[libc-commits] [libc] [libc] Add <ifaddrs.h> and getifaddrs/freeifaddrs stubs (PR #241896)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Thu Nov 12 05:59:10 PST 2026
https://github.com/labath created https://github.com/llvm/llvm-project/pull/241896
Add the <ifaddrs.h> header, struct ifaddrs definition, and stub implementations for getifaddrs() and freeifaddrs() (returning ENOSYS and doing nothing, respectively).
The stubs live under src/ifaddrs/linux/ (matching net/if) so the real netlink-based implementation can be filled in later. Since they don't do anything useful yet, the header and entrypoints are gated on LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS (on linux aarch64, riscv, and x86_64, where the rest of our networking headers are enabled).
Assisted-by: Gemini
>From 9981731ad9914b0658891a39f1b8c1076dea0e71 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Thu, 12 Nov 2026 13:37:20 +0000
Subject: [PATCH] [libc] Add <ifaddrs.h> and getifaddrs/freeifaddrs stubs
Add the <ifaddrs.h> header, struct ifaddrs definition, and stub
implementations for getifaddrs() and freeifaddrs() (returning ENOSYS and
doing nothing, respectively).
The stubs live under src/ifaddrs/linux/ (matching net/if) so the real
netlink-based implementation can be filled in later. Since they don't do
anything useful yet, the header and entrypoints are gated on
LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS (on linux aarch64, riscv, and
x86_64, where the rest of our networking headers are enabled).
Assisted-by: Gemini
---
libc/config/linux/aarch64/entrypoints.txt | 4 +++
libc/config/linux/aarch64/headers.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 4 +++
libc/config/linux/riscv/headers.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 4 +++
libc/config/linux/x86_64/headers.txt | 1 +
libc/hdr/types/CMakeLists.txt | 8 +++++
libc/hdr/types/struct_ifaddrs.h | 27 ++++++++++++++
libc/include/CMakeLists.txt | 9 +++++
libc/include/ifaddrs.yaml | 21 +++++++++++
libc/include/llvm-libc-types/CMakeLists.txt | 1 +
libc/include/llvm-libc-types/struct_ifaddrs.h | 35 +++++++++++++++++++
libc/src/CMakeLists.txt | 1 +
libc/src/ifaddrs/CMakeLists.txt | 17 +++++++++
libc/src/ifaddrs/freeifaddrs.h | 26 ++++++++++++++
libc/src/ifaddrs/getifaddrs.h | 26 ++++++++++++++
libc/src/ifaddrs/linux/CMakeLists.txt | 26 ++++++++++++++
libc/src/ifaddrs/linux/freeifaddrs.cpp | 26 ++++++++++++++
libc/src/ifaddrs/linux/getifaddrs.cpp | 29 +++++++++++++++
libc/test/src/CMakeLists.txt | 1 +
libc/test/src/ifaddrs/CMakeLists.txt | 5 +++
libc/test/src/ifaddrs/linux/CMakeLists.txt | 15 ++++++++
.../src/ifaddrs/linux/getifaddrs_test.cpp | 33 +++++++++++++++++
23 files changed, 321 insertions(+)
create mode 100644 libc/hdr/types/struct_ifaddrs.h
create mode 100644 libc/include/ifaddrs.yaml
create mode 100644 libc/include/llvm-libc-types/struct_ifaddrs.h
create mode 100644 libc/src/ifaddrs/CMakeLists.txt
create mode 100644 libc/src/ifaddrs/freeifaddrs.h
create mode 100644 libc/src/ifaddrs/getifaddrs.h
create mode 100644 libc/src/ifaddrs/linux/CMakeLists.txt
create mode 100644 libc/src/ifaddrs/linux/freeifaddrs.cpp
create mode 100644 libc/src/ifaddrs/linux/getifaddrs.cpp
create mode 100644 libc/test/src/ifaddrs/CMakeLists.txt
create mode 100644 libc/test/src/ifaddrs/linux/CMakeLists.txt
create mode 100644 libc/test/src/ifaddrs/linux/getifaddrs_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index a9941aab496cf..e8fbcb63116f5 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1564,6 +1564,10 @@ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
libc.src.grp.initgroups
libc.src.grp.setgroups
+ # ifaddrs.h entrypoints
+ libc.src.ifaddrs.freeifaddrs
+ libc.src.ifaddrs.getifaddrs
+
# libintl.h entrypoints
libc.src.libintl.bind_textdomain_codeset
libc.src.libintl.bindtextdomain
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 086ea4d39540f..2136903109b51 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -102,6 +102,7 @@ set(TARGET_PUBLIC_HEADERS
if(LLVM_LIBC_FULL_BUILD AND LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
list(APPEND TARGET_PUBLIC_HEADERS
libc.include.glob
+ libc.include.ifaddrs
libc.include.libintl
libc.include.netdb
libc.include.regex
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 1f52d96704a42..6d26b71fec924 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1808,6 +1808,10 @@ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
libc.src.grp.initgroups
libc.src.grp.setgroups
+ # ifaddrs.h entrypoints
+ libc.src.ifaddrs.freeifaddrs
+ libc.src.ifaddrs.getifaddrs
+
# libintl.h entrypoints
libc.src.libintl.bind_textdomain_codeset
libc.src.libintl.bindtextdomain
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index 4cbdb13738ceb..b6a28c6226303 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -107,6 +107,7 @@ set(TARGET_PUBLIC_HEADERS
if(LLVM_LIBC_FULL_BUILD AND LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
list(APPEND TARGET_PUBLIC_HEADERS
libc.include.glob
+ libc.include.ifaddrs
libc.include.libintl
libc.include.netdb
libc.include.regex
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index f30f73548e326..49e5d0ad34139 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1812,6 +1812,10 @@ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
libc.src.grp.initgroups
libc.src.grp.setgroups
+ # ifaddrs.h entrypoints
+ libc.src.ifaddrs.freeifaddrs
+ libc.src.ifaddrs.getifaddrs
+
# libintl.h entrypoints
libc.src.libintl.bind_textdomain_codeset
libc.src.libintl.bindtextdomain
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index 411adb411e312..f7e5dd3bd6b80 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -108,6 +108,7 @@ set(TARGET_PUBLIC_HEADERS
if(LLVM_LIBC_FULL_BUILD AND LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
list(APPEND TARGET_PUBLIC_HEADERS
libc.include.glob
+ libc.include.ifaddrs
libc.include.libintl
libc.include.netdb
libc.include.regex
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index f038bcfb38000..f67c97de84d4c 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -678,6 +678,14 @@ add_proxy_header_library(
libc.include.llvm-libc-types.struct_if_nameindex
)
+add_proxy_header_library(
+ struct_ifaddrs
+ HDRS
+ struct_ifaddrs.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-types.struct_ifaddrs
+)
+
add_proxy_header_library(
struct_sockaddr
HDRS
diff --git a/libc/hdr/types/struct_ifaddrs.h b/libc/hdr/types/struct_ifaddrs.h
new file mode 100644
index 0000000000000..6a1ae5b132fdd
--- /dev/null
+++ b/libc/hdr/types/struct_ifaddrs.h
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Proxy header for struct ifaddrs.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_IFADDRS_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_IFADDRS_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_ifaddrs.h"
+
+#else
+
+#include <ifaddrs.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_IFADDRS_H
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 7010d6998b5fe..ddca7cd3749df 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -186,6 +186,15 @@ add_header_macro(
.llvm_libc_common_h
)
+add_header_macro(
+ ifaddrs
+ ../libc/include/ifaddrs.yaml
+ ifaddrs.h
+ DEPENDS
+ .llvm_libc_common_h
+ .llvm-libc-types.struct_ifaddrs
+)
+
add_header_macro(
libgen
../libc/include/libgen.yaml
diff --git a/libc/include/ifaddrs.yaml b/libc/include/ifaddrs.yaml
new file mode 100644
index 0000000000000..ad70dfcc6522c
--- /dev/null
+++ b/libc/include/ifaddrs.yaml
@@ -0,0 +1,21 @@
+header: ifaddrs.h
+standards:
+ - bsd
+macros: []
+types:
+ - type_name: struct_ifaddrs
+enums: []
+objects: []
+functions:
+ - name: freeifaddrs
+ standards:
+ - bsd
+ return_type: void
+ arguments:
+ - type: struct ifaddrs *
+ - name: getifaddrs
+ standards:
+ - bsd
+ return_type: int
+ arguments:
+ - type: struct ifaddrs **
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index cbd4594d46305..2973e5758b4e1 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -317,6 +317,7 @@ add_type_header(
struct_ifreq.h
)
add_header(struct_if_nameindex HDR struct_if_nameindex.h)
+add_header(struct_ifaddrs HDR struct_ifaddrs.h DEPENDS .struct_sockaddr)
add_header(struct_iovec HDR struct_iovec.h DEPENDS .size_t)
add_header(struct_linger HDR struct_linger.h)
add_header(struct_ucred HDR struct_ucred.h DEPENDS .pid_t .uid_t .gid_t)
diff --git a/libc/include/llvm-libc-types/struct_ifaddrs.h b/libc/include/llvm-libc-types/struct_ifaddrs.h
new file mode 100644
index 0000000000000..d97dd8cd1872b
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_ifaddrs.h
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 struct ifaddrs.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_IFADDRS_H
+#define LLVM_LIBC_TYPES_STRUCT_IFADDRS_H
+
+#include "struct_sockaddr.h"
+
+struct ifaddrs {
+ struct ifaddrs *ifa_next;
+ char *ifa_name;
+ unsigned int ifa_flags;
+ struct sockaddr *ifa_addr;
+ struct sockaddr *ifa_netmask;
+ union {
+ struct sockaddr *ifu_broadaddr;
+ struct sockaddr *ifu_dstaddr;
+ } ifa_ifu;
+ void *ifa_data;
+};
+
+#define ifa_broadaddr ifa_ifu.ifu_broadaddr
+#define ifa_dstaddr ifa_ifu.ifu_dstaddr
+
+#endif // LLVM_LIBC_TYPES_STRUCT_IFADDRS_H
diff --git a/libc/src/CMakeLists.txt b/libc/src/CMakeLists.txt
index 485259980f764..e05bb014d20d7 100644
--- a/libc/src/CMakeLists.txt
+++ b/libc/src/CMakeLists.txt
@@ -51,6 +51,7 @@ endif()
add_subdirectory(assert)
add_subdirectory(compiler)
+add_subdirectory(ifaddrs)
add_subdirectory(libintl)
add_subdirectory(locale)
add_subdirectory(netdb)
diff --git a/libc/src/ifaddrs/CMakeLists.txt b/libc/src/ifaddrs/CMakeLists.txt
new file mode 100644
index 0000000000000..5289dce4deb2c
--- /dev/null
+++ b/libc/src/ifaddrs/CMakeLists.txt
@@ -0,0 +1,17 @@
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+endif()
+
+add_entrypoint_object(
+ freeifaddrs
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.freeifaddrs
+)
+
+add_entrypoint_object(
+ getifaddrs
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.getifaddrs
+)
diff --git a/libc/src/ifaddrs/freeifaddrs.h b/libc/src/ifaddrs/freeifaddrs.h
new file mode 100644
index 0000000000000..29173829a9a53
--- /dev/null
+++ b/libc/src/ifaddrs/freeifaddrs.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
+/// Implementation header for freeifaddrs.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_IFADDRS_FREEIFADDRS_H
+#define LLVM_LIBC_SRC_IFADDRS_FREEIFADDRS_H
+
+#include "hdr/types/struct_ifaddrs.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+void freeifaddrs(struct ifaddrs *ifa);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_IFADDRS_FREEIFADDRS_H
diff --git a/libc/src/ifaddrs/getifaddrs.h b/libc/src/ifaddrs/getifaddrs.h
new file mode 100644
index 0000000000000..77103296d0cfd
--- /dev/null
+++ b/libc/src/ifaddrs/getifaddrs.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
+/// Implementation header for getifaddrs.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_IFADDRS_GETIFADDRS_H
+#define LLVM_LIBC_SRC_IFADDRS_GETIFADDRS_H
+
+#include "hdr/types/struct_ifaddrs.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int getifaddrs(struct ifaddrs **ifap);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_IFADDRS_GETIFADDRS_H
diff --git a/libc/src/ifaddrs/linux/CMakeLists.txt b/libc/src/ifaddrs/linux/CMakeLists.txt
new file mode 100644
index 0000000000000..c370308e459ea
--- /dev/null
+++ b/libc/src/ifaddrs/linux/CMakeLists.txt
@@ -0,0 +1,26 @@
+add_entrypoint_object(
+ freeifaddrs
+ SRCS
+ freeifaddrs.cpp
+ HDRS
+ ../freeifaddrs.h
+ DEPENDS
+ libc.hdr.types.struct_ifaddrs
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
+add_entrypoint_object(
+ getifaddrs
+ SRCS
+ getifaddrs.cpp
+ HDRS
+ ../getifaddrs.h
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.types.struct_ifaddrs
+ libc.src.__support.common
+ libc.src.__support.libc_errno
+ libc.src.__support.macros.config
+ libc.src.errno.errno
+)
diff --git a/libc/src/ifaddrs/linux/freeifaddrs.cpp b/libc/src/ifaddrs/linux/freeifaddrs.cpp
new file mode 100644
index 0000000000000..81ebf2f26f63d
--- /dev/null
+++ b/libc/src/ifaddrs/linux/freeifaddrs.cpp
@@ -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
+/// Linux implementation of freeifaddrs.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/ifaddrs/freeifaddrs.h"
+#include "hdr/types/struct_ifaddrs.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(void, freeifaddrs, ([[maybe_unused]] struct ifaddrs * ifa)) {
+ // TODO: Implement freeifaddrs.
+ return;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/ifaddrs/linux/getifaddrs.cpp b/libc/src/ifaddrs/linux/getifaddrs.cpp
new file mode 100644
index 0000000000000..e1f2ccb804e3a
--- /dev/null
+++ b/libc/src/ifaddrs/linux/getifaddrs.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Linux implementation of getifaddrs.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/ifaddrs/getifaddrs.h"
+#include "hdr/errno_macros.h"
+#include "hdr/types/struct_ifaddrs.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, getifaddrs, ([[maybe_unused]] struct ifaddrs * *ifap)) {
+ // TODO: Implement getifaddrs.
+ libc_errno = ENOSYS;
+ return -1;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index b3ca7a0d36637..33f94b961188c 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -49,6 +49,7 @@ endif()
add_subdirectory(assert)
add_subdirectory(compiler)
add_subdirectory(dirent)
+add_subdirectory(ifaddrs)
add_subdirectory(libintl)
add_subdirectory(locale)
add_subdirectory(netdb)
diff --git a/libc/test/src/ifaddrs/CMakeLists.txt b/libc/test/src/ifaddrs/CMakeLists.txt
new file mode 100644
index 0000000000000..b4e90385e258b
--- /dev/null
+++ b/libc/test/src/ifaddrs/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_libc_testsuite(libc-ifaddrs-tests)
+
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+ add_subdirectory(${LIBC_TARGET_OS})
+endif()
diff --git a/libc/test/src/ifaddrs/linux/CMakeLists.txt b/libc/test/src/ifaddrs/linux/CMakeLists.txt
new file mode 100644
index 0000000000000..c5dfc051d4c27
--- /dev/null
+++ b/libc/test/src/ifaddrs/linux/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_libc_test(
+ getifaddrs_test
+ SUITE
+ libc-ifaddrs-tests
+ SRCS
+ getifaddrs_test.cpp
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.hdr.types.struct_ifaddrs
+ libc.hdr.types.struct_sockaddr
+ libc.src.ifaddrs.freeifaddrs
+ libc.src.ifaddrs.getifaddrs
+ libc.test.UnitTest.ErrnoCheckingTest
+ libc.test.UnitTest.ErrnoSetterMatcher
+)
diff --git a/libc/test/src/ifaddrs/linux/getifaddrs_test.cpp b/libc/test/src/ifaddrs/linux/getifaddrs_test.cpp
new file mode 100644
index 0000000000000..b65b3aef8d012
--- /dev/null
+++ b/libc/test/src/ifaddrs/linux/getifaddrs_test.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Unittests for getifaddrs and freeifaddrs.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/types/struct_ifaddrs.h"
+#include "hdr/types/struct_sockaddr.h"
+#include "src/ifaddrs/freeifaddrs.h"
+#include "src/ifaddrs/getifaddrs.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+using LlvmLibcGetifaddrsTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcGetifaddrsTest, GetIfAddrsReturnsEnosys) {
+ struct ifaddrs *ifap = nullptr;
+ ASSERT_THAT(LIBC_NAMESPACE::getifaddrs(&ifap), Fails(ENOSYS));
+ EXPECT_EQ(ifap, nullptr);
+
+ // freeifaddrs should do nothing and not crash.
+ LIBC_NAMESPACE::freeifaddrs(ifap);
+}
More information about the libc-commits
mailing list