[libc-commits] [libc] [libc] Add `IN6_IS_ADDR_{LINK, SITE}LOCAL` (PR #168207)

Connector Switch via libc-commits libc-commits at lists.llvm.org
Tue Dec 9 18:59:22 PST 2025


================
@@ -33,4 +33,12 @@
 #define INET_ADDRSTRLEN 16
 #define INET6_ADDRSTRLEN 46
 
+#define IN6_IS_ADDR_LINKLOCAL(a)                                               \
+  ((__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[0]) == 0xfe &&            \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[1] & 0xc0) == 0x80)
----------------
c8ef wrote:

> Are we assuming `a` will be big endian

Yes.

Quote from manpages: Each macro is of type int and takes a single argument of type const struct in6_addr *

`struct in6_addr` is required by the standard to store the address in Network Byte Order (Big Endian). This means the most significant byte is always at memory offset 0, regardless of the host architecture.

https://github.com/llvm/llvm-project/pull/168207


More information about the libc-commits mailing list