[libc-commits] [libc] [libc] Implement IPv6 (AF_INET6) support in inet_pton (PR #226550)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Mon Sep 28 02:13:46 PDT 2026


================
@@ -90,6 +91,151 @@ TEST_F(LlvmLibcInetPtonTest, StrictPosixLeadingZeros) {
   ASSERT_ERRNO_SUCCESS();
 }
 
+static bool check_ipv6(const struct in6_addr &addr, uint16_t a, uint16_t b,
+                       uint16_t c, uint16_t d, uint16_t e, uint16_t f,
+                       uint16_t g, uint16_t h) {
+  uint16_t expected[8] = {a, b, c, d, e, f, g, h};
+  for (size_t i = 0; i < 8; ++i) {
+    uint16_t actual = static_cast<uint16_t>(
+        (static_cast<uint16_t>(addr.s6_addr[2 * i]) << 8) |
+        static_cast<uint16_t>(addr.s6_addr[2 * i + 1]));
+    if (actual != expected[i])
+      return false;
+  }
----------------
labath wrote:

I'd probably just construct another in6_addr, and to an `inline_memcmp`.

Also, you can use the s6_addr16 field to avoid bit twiddling.

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


More information about the libc-commits mailing list