Skip to content

Conversation

@c8ef
Copy link
Contributor

@c8ef c8ef commented Dec 15, 2025

No description provided.

@c8ef c8ef marked this pull request as ready for review December 15, 2025 14:48
Copy link
Contributor Author

c8ef commented Dec 15, 2025

@llvmbot llvmbot added the libc label Dec 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 15, 2025

@llvm/pr-subscribers-libc

Author: Connector Switch (c8ef)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/172311.diff

2 Files Affected:

  • (modified) libc/include/llvm-libc-macros/netinet-in-macros.h (+6)
  • (modified) libc/test/include/netinet_in_test.cpp (+6)
diff --git a/libc/include/llvm-libc-macros/netinet-in-macros.h b/libc/include/llvm-libc-macros/netinet-in-macros.h
index b04d6aa4b6781..f97a2dd0c3fda 100644
--- a/libc/include/llvm-libc-macros/netinet-in-macros.h
+++ b/libc/include/llvm-libc-macros/netinet-in-macros.h
@@ -38,6 +38,12 @@
 // int and takes a single argument of type const struct in6_addr *:
 // https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html
 
+#define IN6_IS_ADDR_UNSPECIFIED(a)                                             \
+  ((__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[0]) == 0 &&              \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[1]) == 0 &&              \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[2]) == 0 &&              \
+   (__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[3]) == 0)
+
 #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)
diff --git a/libc/test/include/netinet_in_test.cpp b/libc/test/include/netinet_in_test.cpp
index 6937262f92e90..3b90e5f0bc417 100644
--- a/libc/test/include/netinet_in_test.cpp
+++ b/libc/test/include/netinet_in_test.cpp
@@ -12,6 +12,12 @@
 TEST(LlvmLibcNetinetInTest, IN6Macro) {
   char buff[16] = {};
 
+  EXPECT_TRUE(IN6_IS_ADDR_UNSPECIFIED(buff));
+  for (int i = 0; i < 16; ++i) {
+    buff[i] = 1;
+    EXPECT_FALSE(IN6_IS_ADDR_UNSPECIFIED(buff));
+  }
+
   buff[0] = 0xfe;
   buff[1] = 0x80;
   EXPECT_TRUE(IN6_IS_ADDR_LINKLOCAL(buff));

@c8ef c8ef force-pushed the users/c8ef/12-15-_libc_add_in6_is_addr_unspecified_ branch from 197dea8 to db2ebda Compare December 15, 2025 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants