[libc-commits] [libc] [libc][netdb] Add AI_* family of constants. (PR #221360)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Fri Sep 4 15:23:16 PDT 2026
https://github.com/vonosmas created https://github.com/llvm/llvm-project/pull/221360
* Provide the values for `AI_*` flags that are passed in `ai_flags` field of `addrinfo`
structure to `getaddrinfo` calls.
* Reference some of those constant in a placeholder unittest. Rename it to `getaddrinfo_test`
to clarify its scope (we'll likely be using different test files for other netdb.h functions).
>From d2c95ff526ab337d9c0afa8b2f63e065766a4ea1 Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Fri, 4 Sep 2026 22:21:04 +0000
Subject: [PATCH] [libc][netdb] Add AI_* family of constants.
---
libc/include/llvm-libc-macros/linux/netdb-macros.h | 8 ++++++++
libc/include/netdb.yaml | 14 ++++++++++++++
libc/test/src/netdb/CMakeLists.txt | 5 +++--
.../netdb/{netdb_test.cpp => getaddrinfo_test.cpp} | 11 ++++++++---
4 files changed, 33 insertions(+), 5 deletions(-)
rename libc/test/src/netdb/{netdb_test.cpp => getaddrinfo_test.cpp} (77%)
diff --git a/libc/include/llvm-libc-macros/linux/netdb-macros.h b/libc/include/llvm-libc-macros/linux/netdb-macros.h
index 7bc06982f4553..4965dbd18b3df 100644
--- a/libc/include/llvm-libc-macros/linux/netdb-macros.h
+++ b/libc/include/llvm-libc-macros/linux/netdb-macros.h
@@ -14,6 +14,14 @@
#ifndef LLVM_LIBC_MACROS_LINUX_NETDB_MACROS_H
#define LLVM_LIBC_MACROS_LINUX_NETDB_MACROS_H
+#define AI_PASSIVE 0x0001
+#define AI_CANONNAME 0x0002
+#define AI_NUMERICHOST 0x0004
+#define AI_V4MAPPED 0x0008
+#define AI_ALL 0x0010
+#define AI_ADDRCONFIG 0x0020
+#define AI_NUMERICSERV 0x0400
+
#define EAI_BADFLAGS -1
#define EAI_NONAME -2
#define EAI_AGAIN -3
diff --git a/libc/include/netdb.yaml b/libc/include/netdb.yaml
index 6dc873ae13f11..84e6827abd889 100644
--- a/libc/include/netdb.yaml
+++ b/libc/include/netdb.yaml
@@ -2,6 +2,20 @@ header: netdb.h
standards:
- posix
macros:
+ - macro_name: AI_PASSIVE
+ macro_header: netdb-macros.h
+ - macro_name: AI_CANONNAME
+ macro_header: netdb-macros.h
+ - macro_name: AI_NUMERICHOST
+ macro_header: netdb-macros.h
+ - macro_name: AI_NUMERICSERV
+ macro_header: netdb-macros.h
+ - macro_name: AI_V4MAPPED
+ macro_header: netdb-macros.h
+ - macro_name: AI_ALL
+ macro_header: netdb-macros.h
+ - macro_name: AI_ADDRCONFIG
+ macro_header: netdb-macros.h
- macro_name: EAI_AGAIN
macro_header: netdb-macros.h
- macro_name: EAI_BADFLAGS
diff --git a/libc/test/src/netdb/CMakeLists.txt b/libc/test/src/netdb/CMakeLists.txt
index 608d7f38acabe..9e2e9a15f9d82 100644
--- a/libc/test/src/netdb/CMakeLists.txt
+++ b/libc/test/src/netdb/CMakeLists.txt
@@ -12,14 +12,15 @@ add_libc_test(
)
add_libc_test(
- netdb_test
+ getaddrinfo_test
SUITE
libc-netdb-tests
SRCS
- netdb_test.cpp
+ getaddrinfo_test.cpp
DEPENDS
libc.hdr.errno_macros
libc.hdr.netdb_macros
+ libc.hdr.sys_socket_macros
libc.hdr.types.struct_addrinfo
libc.src.errno.errno
libc.src.netdb.freeaddrinfo
diff --git a/libc/test/src/netdb/netdb_test.cpp b/libc/test/src/netdb/getaddrinfo_test.cpp
similarity index 77%
rename from libc/test/src/netdb/netdb_test.cpp
rename to libc/test/src/netdb/getaddrinfo_test.cpp
index b25a3cdc2a5f0..82be0d3c6dc38 100644
--- a/libc/test/src/netdb/netdb_test.cpp
+++ b/libc/test/src/netdb/getaddrinfo_test.cpp
@@ -13,6 +13,7 @@
#include "hdr/errno_macros.h"
#include "hdr/netdb_macros.h"
+#include "hdr/sys_socket_macros.h"
#include "hdr/types/struct_addrinfo.h"
#include "src/netdb/freeaddrinfo.h"
#include "src/netdb/getaddrinfo.h"
@@ -21,11 +22,15 @@
#include "test/UnitTest/Test.h"
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
-using LlvmLibcNetdbTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+using LlvmLibcGetaddrinfoTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
-TEST_F(LlvmLibcNetdbTest, GetAddrInfoReturnsEaiSystem) {
+TEST_F(LlvmLibcGetaddrinfoTest, GetAddrInfoReturnsEaiSystem) {
+ struct addrinfo hints{};
+ hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
+ hints.ai_family = AF_INET6;
+ hints.ai_socktype = SOCK_DGRAM;
struct addrinfo *res = nullptr;
- ASSERT_THAT(LIBC_NAMESPACE::getaddrinfo("localhost", nullptr, nullptr, &res),
+ ASSERT_THAT(LIBC_NAMESPACE::getaddrinfo("localhost", nullptr, &hints, &res),
Fails(ENOSYS, EAI_SYSTEM));
EXPECT_EQ(res, nullptr);
More information about the libc-commits
mailing list