diff options
-rw-r--r-- | nuttx/include/nuttx/net/ip.h | 96 | ||||
-rw-r--r-- | nuttx/net/socket/recvfrom.c | 10 | ||||
-rw-r--r-- | nuttx/net/udp/udp_callback.c | 10 | ||||
-rw-r--r-- | nuttx/net/udp/udp_send.c | 42 |
4 files changed, 106 insertions, 52 deletions
diff --git a/nuttx/include/nuttx/net/ip.h b/nuttx/include/nuttx/net/ip.h index f28ff315d..2082e590d 100644 --- a/nuttx/include/nuttx/net/ip.h +++ b/nuttx/include/nuttx/net/ip.h @@ -240,17 +240,23 @@ EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link addres * Public Function Prototypes ****************************************************************************/ -/* Construct an IPv4 address from four bytes. +/**************************************************************************** + * Macro: net_ipaddr + * + * Description: + * Construct an IPv4 address from four bytes. * - * This function constructs an IPv4 address in network byte order. + * This function constructs an IPv4 address in network byte order. * + * Input Parameters: * addr A pointer to a in_addr_t variable that will be * filled in with the IPv4 address. * addr0 The first octet of the IPv4 address. * addr1 The second octet of the IPv4 address. * addr2 The third octet of the IPv4 address. * addr3 The forth octet of the IPv4 address. - */ + * + ****************************************************************************/ #define net_ipaddr(addr, addr0, addr1, addr2, addr3) \ do { \ @@ -258,17 +264,32 @@ EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link addres (uint32_t)(addr2) << 8 | (uint32_t)(addr3)); \ } while (0) -/* Convert an IPv4 address of the form uint16_t[2] to an in_addr_t */ +/**************************************************************************** + * Macro: net_ip4addr_conv32 + * + * Description: + * Convert an IPv4 address of the form uint16_t[2] to an in_addr_t + * + ****************************************************************************/ #ifdef CONFIG_ENDIAN_BIG -# define net_ip4addr_conv32(addr) (((in_addr_t)((uint16_t*)addr)[0] << 16) | (in_addr_t)((uint16_t*)addr)[1]) +# define net_ip4addr_conv32(addr) \ + (((in_addr_t)((uint16_t*)addr)[0] << 16) | \ + (in_addr_t)((uint16_t*)addr)[1]) #else -# define net_ip4addr_conv32(addr) (((in_addr_t)((uint16_t*)addr)[1] << 16) | (in_addr_t)((uint16_t*)addr)[0]) +# define net_ip4addr_conv32(addr) \ + (((in_addr_t)((uint16_t*)addr)[1] << 16) | \ + (in_addr_t)((uint16_t*)addr)[0]) #endif -/* Extract individual bytes from a 32-bit IPv4 IP address that is in network - * byte order. - */ +/**************************************************************************** + * Macro: ip4_addr1, ip4_addr2, ip4_addr3, and ip4_addr4 + * + * Description: + * Extract individual bytes from a 32-bit IPv4 IP address that is in + * network byte order. + * + ****************************************************************************/ #ifdef CONFIG_ENDIAN_BIG /* Big-endian byte order: 11223344 */ @@ -286,10 +307,13 @@ EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link addres # define ip4_addr4(ipaddr) (((ipaddr) >> 24) & 0xff) #endif -/* Construct an IPv6 address from eight 16-bit words. +/**************************************************************************** + * Macro: ip6_addr + * + * Description: + * Construct an IPv6 address from eight 16-bit words. * - * This function constructs an IPv6 address. - */ + ****************************************************************************/ #define ip6_addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) \ do { \ @@ -303,7 +327,12 @@ EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link addres ((uint16_t*)(addr))[7] = HTONS((addr7)); \ } while (0) -/* Copy an IP address from one place to another. +/**************************************************************************** + * Macro: net_ipv4addr_copy, net_ipv4addr_hdrcopy, net_ipv6addr_copy, and + * net_ipv6addr_hdrcopy + * + * Description: + * Copy an IP address from one place to another. * * Example: * @@ -312,9 +341,11 @@ EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link addres * net_ipaddr(&ipaddr1, 192,16,1,2); * net_ipaddr_copy(&ipaddr2, &ipaddr1); * - * dest The destination for the copy. - * src The source from where to copy. - */ + * Input Parameters: + * dest - The destination for the copy. + * src - The source from where to copy. + * + ****************************************************************************/ #ifdef CONFIG_NET_IPv4 # define net_ipv4addr_copy(dest, src) \ @@ -335,21 +366,28 @@ EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link addres net_ipv6addr_copy(dest, src) #endif -/* Compare two IP addresses +/**************************************************************************** + * Macro: net_ipv4addr_cmp, net_ipv4addr_hdrcmp, net_ipv6addr_cmp, and + * net_ipv6addr_hdrcmp * - * Example: + * Description: + * Compare two IP addresses * - * in_addr_t ipaddr1, ipaddr2; + * Example: * - * net_ipaddr(&ipaddr1, 192,16,1,2); - * if (net_ipv4addr_cmp(ipaddr2, ipaddr1)) - * { - * printf("They are the same"); - * } + * in_addr_t ipaddr1, ipaddr2; + * + * net_ipaddr(&ipaddr1, 192,16,1,2); + * if (net_ipv4addr_cmp(ipaddr2, ipaddr1)) + * { + * printf("They are the same"); + * } * - * addr1 The first IP address. - * addr2 The second IP address. - */ + * Input Parameters: + * addr1 - The first IP address. + * addr2 - The second IP address. + * + ****************************************************************************/ #ifdef CONFIG_NET_IPv4 # define net_ipv4addr_cmp(addr1, addr2) \ @@ -387,7 +425,7 @@ EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link addres * printf("They are the same"); * } * - * Parameters: + * Input Parameters: * addr1 - The first IP address. * addr2 - The second IP address. * mask - The netmask. @@ -427,7 +465,7 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1, * In the example above, the variable "ipaddr2" will contain the IP * address 192.168.1.0. * - * Parameters: + * Input Parameters: * dest Where the result is to be placed. * src The IP address. * mask The netmask. diff --git a/nuttx/net/socket/recvfrom.c b/nuttx/net/socket/recvfrom.c index 2f91c238d..3ca7b125e 100644 --- a/nuttx/net/socket/recvfrom.c +++ b/nuttx/net/socket/recvfrom.c @@ -977,12 +977,14 @@ static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_ infrom6->sin6_port = udp->srcport; *fromlen = sizeof(struct sockaddr_in6); - memset(infrom6->sin6_addr.s6_addr, 0, sizeof(infrom6->sin6_addr.s6_addr) - sizeof(in_addr_t)); + memset(infrom6->sin6_addr.s6_addr, 0, + sizeof(infrom6->sin6_addr.s6_addr) - sizeof(in_addr_t)); - infrom6->sin6_addr.s6_addr[10] = 0xFF; - infrom6->sin6_addr.s6_addr[11] = 0xFF; + infrom6->sin6_addr.s6_addr[10] = 0xff; + infrom6->sin6_addr.s6_addr[11] = 0xff; - memcpy(&infrom6->sin6_addr.s6_addr[12], ipv4->srcipaddr, sizeof(in_addr_t)); + memcpy(&infrom6->sin6_addr.s6_addr[12], ipv4->srcipaddr + sizeof(in_addr_t)); } else #endif diff --git a/nuttx/net/udp/udp_callback.c b/nuttx/net/udp/udp_callback.c index 23a27beff..583f348af 100644 --- a/nuttx/net/udp/udp_callback.c +++ b/nuttx/net/udp/udp_callback.c @@ -138,12 +138,14 @@ static uint16_t udp_datahandler(FAR struct net_driver_s *dev, FAR struct udp_con src_addr6.sin6_family = AF_INET6; src_addr6.sin6_port = udp->srcport; - memset(src_addr6.sin6_addr.s6_addr, 0, sizeof(src_addr6.sin6_addr.s6_addr) - sizeof(in_addr_t)); + memset(src_addr6.sin6_addr.s6_addr, 0, + sizeof(src_addr6.sin6_addr.s6_addr) - sizeof(in_addr_t)); - src_addr6.sin6_addr.s6_addr[10] = 0xFF; - src_addr6.sin6_addr.s6_addr[11] = 0xFF; + src_addr6.sin6_addr.s6_addr[10] = 0xff; + src_addr6.sin6_addr.s6_addr[11] = 0xff; - memcpy(&src_addr6.sin6_addr.s6_addr[12], ipv4->srcipaddr, sizeof(in_addr_t)); + memcpy(&src_addr6.sin6_addr.s6_addr[12], ipv4->srcipaddr, + sizeof(in_addr_t)); src_addr_size = sizeof(src_addr6); src_addr = &src_addr6; diff --git a/nuttx/net/udp/udp_send.c b/nuttx/net/udp/udp_send.c index 4994bc535..7ddff1416 100644 --- a/nuttx/net/udp/udp_send.c +++ b/nuttx/net/udp/udp_send.c @@ -63,18 +63,27 @@ * Pre-processor Definitions ****************************************************************************/ -#define IPv4BUF ((struct ipv4_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) -#define IPv6BUF ((struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) - -#define UDPIPv4BUF ((struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv4_HDRLEN]) -#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)) - +#define IPv4BUF \ + ((struct ipv4_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) +#define IPv6BUF \ + ((struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) + +#define UDPIPv4BUF \ + ((struct udp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv4_HDRLEN]) +#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 @@ -123,7 +132,8 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv4 #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))) + (conn->domain == PF_INET6 && + IN6_IS_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr))) #endif { /* Get pointers to the IPv4 header and the offset TCP header */ @@ -148,7 +158,8 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) net_ipv4addr_hdrcopy(ipv4->srcipaddr, &dev->d_ipaddr); #ifdef CONFIG_NET_IPv6 - if (conn->domain == PF_INET6 && IN6_IS_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr)) + if (conn->domain == PF_INET6 && + IN6_IS_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr)) { in_addr_t raddr = IN6_GET_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr); net_ipv4addr_hdrcopy(ipv4->destipaddr, &raddr); @@ -241,7 +252,8 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv4 #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))) + (conn->domain == PF_INET6 && + IN6_IS_ADDR_IPV4((FAR struct in6_addr*)conn->u.ipv6.raddr))) #endif { udp->udpchksum = ~udp_ipv4_chksum(dev); |