summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-02-17 07:08:11 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-02-17 07:08:11 -0600
commit25392034e99f6ecac1c5987c226e32324dfe6f67 (patch)
tree6cbd0ebe5f81e396cd791bc743f36949c01a41ac
parent10f755ecbaa55265c1459532eed647962e24b39a (diff)
downloadnuttx-25392034e99f6ecac1c5987c226e32324dfe6f67.tar.gz
nuttx-25392034e99f6ecac1c5987c226e32324dfe6f67.tar.bz2
nuttx-25392034e99f6ecac1c5987c226e32324dfe6f67.zip
Move some useful internal macros from udp_send.c and put them in ip.h where they can be used more generally
-rw-r--r--nuttx/include/nuttx/net/ip.h41
-rw-r--r--nuttx/net/udp/udp_send.c20
2 files changed, 45 insertions, 16 deletions
diff --git a/nuttx/include/nuttx/net/ip.h b/nuttx/include/nuttx/net/ip.h
index 2082e590d..3bb221f10 100644
--- a/nuttx/include/nuttx/net/ip.h
+++ b/nuttx/include/nuttx/net/ip.h
@@ -328,6 +328,47 @@ EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link addres
} while (0)
/****************************************************************************
+ * Macro: ip6_get_ipv4addr
+ *
+ * Description:
+ * Decode an encoded IPv4 address.
+ *
+ * Input Parameters:
+ * ipv6addr - The IPv6 address (net_ipv6addr_t) containing the encoded
+ * IPv4 address
+ *
+ * Returned Value:
+ * The decode IPv4 addreses (in_addr_t)
+ *
+ ****************************************************************************/
+
+#define ip6_get_ipv4addr(ipv6addr) \
+ (((in_addr_t)(ipv6addr)->s6_addr[12]) | \
+ ((in_addr_t)(ipv6addr)->s6_addr[13] << 8) | \
+ ((in_addr_t)(ipv6addr)->s6_addr[14] << 16) | \
+ ((in_addr_t)(ipv6addr)->s6_addr[15] << 24))
+
+/****************************************************************************
+ * Macro: ip6_is_ipv4addr
+ *
+ * Description:
+ * Test if an IPv6 is an encoded IPv4 address.
+ *
+ * Input Parameters:
+ * ipv6addr - The IPv6 address to be tested
+ *
+ * Returned Value:
+ * True is returned if ipv6addr holds an encoded IPv4 address.
+ *
+ ****************************************************************************/
+
+#define ip6_is_ipv4addr(ipv6addr) \
+ ((ipv6addr)->s6_addr32[0] == 0 && \
+ (ipv6addr)->s6_addr32[1] == 0 && \
+ (ipv6addr)->s6_addr16[4] == 0 && \
+ (ipv6addr)->s6_addr16[5] == 0xffff)
+
+/****************************************************************************
* Macro: net_ipv4addr_copy, net_ipv4addr_hdrcopy, net_ipv6addr_copy, and
* net_ipv6addr_hdrcopy
*
diff --git a/nuttx/net/udp/udp_send.c b/nuttx/net/udp/udp_send.c
index 7ddff1416..e18be4d24 100644
--- a/nuttx/net/udp/udp_send.c
+++ b/nuttx/net/udp/udp_send.c
@@ -73,18 +73,6 @@
#define UDPIPv6BUF \
((struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
-#define IN6_IS_ADDR_IPV4(a) \
- ((a)->s6_addr32[0] == 0 && \
- (a)->s6_addr32[1] == 0 && \
- (a)->s6_addr16[4] == 0 && \
- (a)->s6_addr16[5] == 0xffff)
-
-#define IN6_GET_ADDR_IPV4(a) \
- (((in_addr_t)(a)->s6_addr[12]) | \
- ((in_addr_t)(a)->s6_addr[13] << 8) | \
- ((in_addr_t)(a)->s6_addr[14] << 16) | \
- ((in_addr_t)(a)->s6_addr[15] << 24))
-
/****************************************************************************
* Public Variables
****************************************************************************/
@@ -133,7 +121,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET ||
(conn->domain == PF_INET6 &&
- IN6_IS_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr)))
+ ip6_is_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr)))
#endif
{
/* Get pointers to the IPv4 header and the offset TCP header */
@@ -159,9 +147,9 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET6 &&
- IN6_IS_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr))
+ ip6_is_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr))
{
- in_addr_t raddr = IN6_GET_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr);
+ in_addr_t raddr = ip6_get_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr);
net_ipv4addr_hdrcopy(ipv4->destipaddr, &raddr);
}
else
@@ -253,7 +241,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET ||
(conn->domain == PF_INET6 &&
- IN6_IS_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr)))
+ ip6_is_ipv4addr((FAR struct in6_addr*)conn->u.ipv6.raddr)))
#endif
{
udp->udpchksum = ~udp_ipv4_chksum(dev);