IPv6 sockaddr clean ups

This commit address two issues with sockaddr struct implementations for
IPv6:

  1) struct sockaddr_in6 should have 32-bit unsigned field sin6_scope_id
     as specified in Section 3.4 of RFC 3493 (Basic Socket Interface
	 Extensions for IPv6)
  2) struct sockaddr is not extended in IPv6 to contain space for
     struct sockaddr_in6.  Applications should be using struct
	 sockaddr_storage when needing generic storage.  This removes the
	 extra bytes added when LWIP_IPV6 is defined
This commit is contained in:
Joel Cunningham 2015-05-15 08:50:35 -05:00 committed by goldsimon
parent a6bd0944db
commit d850efdd08
2 changed files with 9 additions and 11 deletions

View File

@ -89,7 +89,8 @@
(sin6)->sin6_family = AF_INET6; \
(sin6)->sin6_port = htons((port)); \
(sin6)->sin6_flowinfo = 0; \
inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); }while(0)
inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); \
(sin6)->sin6_scope_id = 0; }while(0)
#define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipaddr, port) do { \
inet6_addr_to_ip6addr(ip_2_ip6(ipaddr), &((sin6)->sin6_addr)); \
(port) = ntohs((sin6)->sin6_port); }while(0)

View File

@ -71,22 +71,19 @@ struct sockaddr_in {
#if LWIP_IPV6
struct sockaddr_in6 {
u8_t sin6_len; /* length of this structure */
sa_family_t sin6_family; /* AF_INET6 */
in_port_t sin6_port; /* Transport layer port # */
u32_t sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
u8_t sin6_len; /* length of this structure */
sa_family_t sin6_family; /* AF_INET6 */
in_port_t sin6_port; /* Transport layer port # */
u32_t sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
u32_t sin6_scope_id; /* Set of interfaces for scope */
};
#endif /* LWIP_IPV6 */
struct sockaddr {
u8_t sa_len;
sa_family_t sa_family;
#if LWIP_IPV6
char sa_data[22];
#else /* LWIP_IPV6 */
char sa_data[14];
#endif /* LWIP_IPV6 */
};
struct sockaddr_storage {
@ -95,7 +92,7 @@ struct sockaddr_storage {
char s2_data1[2];
u32_t s2_data2[3];
#if LWIP_IPV6
u32_t s2_data3[2];
u32_t s2_data3[3];
#endif /* LWIP_IPV6 */
};