[libc-commits] [libc] [libc] Add the in6addr_{any, loopback} variables (PR #203579)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Fri Jun 12 09:48:09 PDT 2026
https://github.com/labath created https://github.com/llvm/llvm-project/pull/203579
None
>From 4b4ae5bcb204c380291429cc7ebbdf7a41f7af76 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Fri, 12 Jun 2026 16:40:08 +0000
Subject: [PATCH] [libc] Add the in6addr_{any,loopback} variables
---
libc/config/linux/aarch64/entrypoints.txt | 4 ++++
libc/config/linux/riscv/entrypoints.txt | 4 ++++
libc/config/linux/x86_64/entrypoints.txt | 4 ++++
libc/include/netinet/in.yaml | 6 +++++-
libc/src/CMakeLists.txt | 1 +
libc/src/netinet/CMakeLists.txt | 25 ++++++++++++++++++++++
libc/src/netinet/in6addr_any.cpp | 24 +++++++++++++++++++++
libc/src/netinet/in6addr_any.h | 26 +++++++++++++++++++++++
libc/src/netinet/in6addr_loopback.cpp | 25 ++++++++++++++++++++++
libc/src/netinet/in6addr_loopback.h | 26 +++++++++++++++++++++++
libc/test/src/netinet/CMakeLists.txt | 2 ++
libc/test/src/netinet/in_test.cpp | 14 ++++++++++++
12 files changed, 160 insertions(+), 1 deletion(-)
create mode 100644 libc/src/netinet/CMakeLists.txt
create mode 100644 libc/src/netinet/in6addr_any.cpp
create mode 100644 libc/src/netinet/in6addr_any.h
create mode 100644 libc/src/netinet/in6addr_loopback.cpp
create mode 100644 libc/src/netinet/in6addr_loopback.h
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 88ae0e8389517..af40c1026967e 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1018,6 +1018,10 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.arpa.inet.ntohl
libc.src.arpa.inet.ntohs
+ # netinet/in.h entrypoints
+ libc.src.netinet.in6addr_any
+ libc.src.netinet.in6addr_loopback
+
# pthread.h entrypoints
libc.src.pthread.pthread_atfork
libc.src.pthread.pthread_attr_destroy
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 4eec6c8679fad..8069877db72f4 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1151,6 +1151,10 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.arpa.inet.ntohl
libc.src.arpa.inet.ntohs
+ # netinet/in.h entrypoints
+ libc.src.netinet.in6addr_any
+ libc.src.netinet.in6addr_loopback
+
# pthread.h entrypoints
libc.src.pthread.pthread_atfork
libc.src.pthread.pthread_attr_destroy
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 42603ec89d4c8..09dfe3f02e642 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -41,6 +41,10 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.fcntl.open
libc.src.fcntl.openat
+ # netinet/in.h entrypoints
+ libc.src.netinet.in6addr_any
+ libc.src.netinet.in6addr_loopback
+
# poll.h entrypoints
libc.src.poll.poll
diff --git a/libc/include/netinet/in.yaml b/libc/include/netinet/in.yaml
index ad62e0955e9e6..e4eb7d65bb42d 100644
--- a/libc/include/netinet/in.yaml
+++ b/libc/include/netinet/in.yaml
@@ -33,5 +33,9 @@ types:
- type_name: struct_in_addr
- type_name: struct_in6_addr
enums: []
-objects: []
+objects:
+ - object_name: in6addr_any
+ object_type: const struct in6_addr
+ - object_name: in6addr_loopback
+ object_type: const struct in6_addr
functions: []
diff --git a/libc/src/CMakeLists.txt b/libc/src/CMakeLists.txt
index 56fb121ecda75..9db314f54723b 100644
--- a/libc/src/CMakeLists.txt
+++ b/libc/src/CMakeLists.txt
@@ -9,6 +9,7 @@ add_subdirectory(fenv)
add_subdirectory(inttypes)
add_subdirectory(link)
add_subdirectory(math)
+add_subdirectory(netinet)
add_subdirectory(stdbit)
add_subdirectory(stdfix)
add_subdirectory(stdio)
diff --git a/libc/src/netinet/CMakeLists.txt b/libc/src/netinet/CMakeLists.txt
new file mode 100644
index 0000000000000..868e09f7a3431
--- /dev/null
+++ b/libc/src/netinet/CMakeLists.txt
@@ -0,0 +1,25 @@
+add_entrypoint_object(
+ in6addr_any
+ SRCS
+ in6addr_any.cpp
+ HDRS
+ in6addr_any.h
+ DEPENDS
+ libc.hdr.netinet_in_macros
+ libc.hdr.types.struct_in6_addr
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
+add_entrypoint_object(
+ in6addr_loopback
+ SRCS
+ in6addr_loopback.cpp
+ HDRS
+ in6addr_loopback.h
+ DEPENDS
+ libc.hdr.netinet_in_macros
+ libc.hdr.types.struct_in6_addr
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
diff --git a/libc/src/netinet/in6addr_any.cpp b/libc/src/netinet/in6addr_any.cpp
new file mode 100644
index 0000000000000..c20c21b43a936
--- /dev/null
+++ b/libc/src/netinet/in6addr_any.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of the in6addr_any constant.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/netinet/in6addr_any.h"
+#include "hdr/netinet_in_macros.h"
+#include "hdr/types/struct_in6_addr.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_VARIABLE(const struct in6_addr, in6addr_any) = IN6ADDR_ANY_INIT;
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/netinet/in6addr_any.h b/libc/src/netinet/in6addr_any.h
new file mode 100644
index 0000000000000..e6ff709363fed
--- /dev/null
+++ b/libc/src/netinet/in6addr_any.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Declaration of the in6addr_any constant.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_NETINET_IN6ADDR_ANY_H
+#define LLVM_LIBC_SRC_NETINET_IN6ADDR_ANY_H
+
+#include "hdr/types/struct_in6_addr.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+extern const struct in6_addr in6addr_any;
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_NETINET_IN6ADDR_ANY_H
diff --git a/libc/src/netinet/in6addr_loopback.cpp b/libc/src/netinet/in6addr_loopback.cpp
new file mode 100644
index 0000000000000..8d647cff1e3de
--- /dev/null
+++ b/libc/src/netinet/in6addr_loopback.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of the in6addr_loopback constant.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/netinet/in6addr_loopback.h"
+#include "hdr/netinet_in_macros.h"
+#include "hdr/types/struct_in6_addr.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_VARIABLE(const struct in6_addr,
+ in6addr_loopback) = IN6ADDR_LOOPBACK_INIT;
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/netinet/in6addr_loopback.h b/libc/src/netinet/in6addr_loopback.h
new file mode 100644
index 0000000000000..4564114f8b130
--- /dev/null
+++ b/libc/src/netinet/in6addr_loopback.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Declaration of the in6addr_loopback constant.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_NETINET_IN6ADDR_LOOPBACK_H
+#define LLVM_LIBC_SRC_NETINET_IN6ADDR_LOOPBACK_H
+
+#include "hdr/types/struct_in6_addr.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+extern const struct in6_addr in6addr_loopback;
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_NETINET_IN6ADDR_LOOPBACK_H
diff --git a/libc/test/src/netinet/CMakeLists.txt b/libc/test/src/netinet/CMakeLists.txt
index c168186b60eeb..605f70ff193cd 100644
--- a/libc/test/src/netinet/CMakeLists.txt
+++ b/libc/test/src/netinet/CMakeLists.txt
@@ -12,6 +12,8 @@ add_libc_unittest(
libc.hdr.types.struct_sockaddr_in6
libc.src.arpa.inet.htons
libc.src.arpa.inet.htonl
+ libc.src.netinet.in6addr_any
+ libc.src.netinet.in6addr_loopback
libc.src.string.memcmp
)
diff --git a/libc/test/src/netinet/in_test.cpp b/libc/test/src/netinet/in_test.cpp
index 7ca408ac21ead..fb4c3be335605 100644
--- a/libc/test/src/netinet/in_test.cpp
+++ b/libc/test/src/netinet/in_test.cpp
@@ -19,6 +19,8 @@
#include "hdr/netinet_in_macros.h"
#include "hdr/types/struct_in6_addr.h"
#include "hdr/types/struct_sockaddr_in6.h"
+#include "src/netinet/in6addr_any.h"
+#include "src/netinet/in6addr_loopback.h"
TEST(LlvmLibcNetinetInTest, In6AddrLayout) {
EXPECT_EQ(sizeof(struct in6_addr), static_cast<size_t>(16));
@@ -68,6 +70,18 @@ TEST(LlvmLibcNetinetInTest, IN6AddrInitMacros) {
EXPECT_TRUE(IN6_IS_ADDR_LOOPBACK(&loopback));
}
+TEST(LlvmLibcNetinetInTest, IN6AddrConstants) {
+ const uint8_t ANY_CONTENT[16] = {0};
+ EXPECT_EQ(
+ LIBC_NAMESPACE::memcmp(&LIBC_NAMESPACE::in6addr_any, ANY_CONTENT, 16), 0);
+
+ const uint8_t LOOPBACK_CONTENT[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1};
+ EXPECT_EQ(LIBC_NAMESPACE::memcmp(&LIBC_NAMESPACE::in6addr_loopback,
+ LOOPBACK_CONTENT, 16),
+ 0);
+}
+
TEST(LlvmLibcNetinetInTest, SockaddrIn6Layout) {
EXPECT_EQ(offsetof(struct sockaddr_in6, sin6_family), static_cast<size_t>(0));
EXPECT_EQ(offsetof(struct sockaddr_in6, sin6_port), static_cast<size_t>(2));
More information about the libc-commits
mailing list