From d850efdd08a80c1b83fff31965cf119cf314ce87 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Fri, 15 May 2015 08:50:35 -0500 Subject: [PATCH] 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 --- src/api/sockets.c | 3 ++- src/include/lwip/sockets.h | 17 +++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/api/sockets.c b/src/api/sockets.c index e74ceea1..c1539b91 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -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) diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h index 47f89e13..0e795e1f 100644 --- a/src/include/lwip/sockets.h +++ b/src/include/lwip/sockets.h @@ -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 */ };