From 7335fb0d5c8025c9f46f978085cfdabc7da0da99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 22 Oct 2020 16:48:05 +0200 Subject: [PATCH] in6.h: declare in6_addr with a union and extra fields According to https://tools.ietf.org/html/rfc3493: 3.2 IPv6 Address Structure "The structure in6_addr above is usually implemented with an embedded union with extra fields that force the desired alignment level in a manner similar to BSD implementations of "struct in_addr"." Change-Id: Ibe0ee685366398c143cdf9573dcb77566a12888b Reviewed-on: https://review.haiku-os.org/c/haiku/+/3348 Reviewed-by: Rene Gollent --- headers/posix/netinet6/in6.h | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/headers/posix/netinet6/in6.h b/headers/posix/netinet6/in6.h index 8f897c8373..e3af7fa3a3 100644 --- a/headers/posix/netinet6/in6.h +++ b/headers/posix/netinet6/in6.h @@ -11,8 +11,17 @@ struct in6_addr { - uint8_t s6_addr[16]; -}; + union { + uint8_t u6_addr8[16]; + uint16_t u6_addr16[8]; + uint32_t u6_addr32[4]; + } in6_u; + #define s6_addr in6_u.u6_addr8 + #define s6_addr16 in6_u.u6_addr16 + #define s6_addr32 in6_u.u6_addr32 +} _PACKED; + + /* IP Version 6 socket address. */ struct sockaddr_in6 { @@ -25,21 +34,21 @@ struct sockaddr_in6 { }; -#define IN6ADDR_ANY_INIT {{ \ +#define IN6ADDR_ANY_INIT {{{ \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} -#define IN6ADDR_LOOPBACK_INIT {{ \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} +#define IN6ADDR_LOOPBACK_INIT {{{ \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }} -#define IN6ADDR_NODELOCAL_ALLNODES_INIT {{ \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#define IN6ADDR_NODELOCAL_ALLNODES_INIT {{{ \ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }} -#define IN6ADDR_LINKLOCAL_ALLNODES_INIT {{ \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#define IN6ADDR_LINKLOCAL_ALLNODES_INIT {{{ \ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }} -#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT {{ \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT {{{ \ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }} + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} extern const struct in6_addr in6addr_any; extern const struct in6_addr in6addr_loopback;