From ab878a7e741073574336c9c4b1d41c6cf80b0d6a Mon Sep 17 00:00:00 2001 From: fanquake Date: Tue, 6 May 2025 09:50:37 +0100 Subject: [PATCH] build: simplify *ifaddr handling We really just want to skip this when building for Windows. So do that, and remove the two header checks (we also already use both of these headers, unguarded, in the !windows part of the codebase). Squash the two *iffaddrs defines into one, as I haven't seen an iffaddrs.h that implements one, but not the other. --- cmake/bitcoin-build-config.h.in | 9 ++------- cmake/introspection.cmake | 5 +---- cmake/module/TestAppendRequiredLibraries.cmake | 3 +-- src/common/netif.cpp | 7 ++++++- src/compat/compat.h | 1 - src/net.cpp | 4 ---- src/randomenv.cpp | 4 ++-- 7 files changed, 12 insertions(+), 21 deletions(-) diff --git a/cmake/bitcoin-build-config.h.in b/cmake/bitcoin-build-config.h.in index ef846fd0b7..4783209ef7 100644 --- a/cmake/bitcoin-build-config.h.in +++ b/cmake/bitcoin-build-config.h.in @@ -55,13 +55,8 @@ */ #cmakedefine01 HAVE_DECL_FORK -/* Define to 1 if you have the declaration of `freeifaddrs', and to 0 if you - don't. */ -#cmakedefine01 HAVE_DECL_FREEIFADDRS - -/* Define to 1 if you have the declaration of `getifaddrs', and to 0 if you - don't. */ -#cmakedefine01 HAVE_DECL_GETIFADDRS +/* Define to 1 if '*ifaddrs' are available. */ +#cmakedefine HAVE_IFADDRS 1 /* Define to 1 if you have the declaration of `pipe2', and to 0 if you don't. */ diff --git a/cmake/introspection.cmake b/cmake/introspection.cmake index 3c95c31bd0..e8538ae73c 100644 --- a/cmake/introspection.cmake +++ b/cmake/introspection.cmake @@ -4,7 +4,6 @@ include(CheckCXXSourceCompiles) include(CheckCXXSymbolExists) -include(CheckIncludeFileCXX) check_cxx_symbol_exists(O_CLOEXEC "fcntl.h" HAVE_O_CLOEXEC) check_cxx_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC) @@ -12,9 +11,7 @@ check_cxx_symbol_exists(fork "unistd.h" HAVE_DECL_FORK) check_cxx_symbol_exists(pipe2 "unistd.h" HAVE_DECL_PIPE2) check_cxx_symbol_exists(setsid "unistd.h" HAVE_DECL_SETSID) -check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H) -check_include_file_cxx(ifaddrs.h HAVE_IFADDRS_H) -if(HAVE_SYS_TYPES_H AND HAVE_IFADDRS_H) +if(NOT WIN32) include(TestAppendRequiredLibraries) test_append_socket_library(core_interface) endif() diff --git a/cmake/module/TestAppendRequiredLibraries.cmake b/cmake/module/TestAppendRequiredLibraries.cmake index e15c2b9934..1fc339a954 100644 --- a/cmake/module/TestAppendRequiredLibraries.cmake +++ b/cmake/module/TestAppendRequiredLibraries.cmake @@ -38,8 +38,7 @@ function(test_append_socket_library target) message(FATAL_ERROR "Cannot figure out how to use getifaddrs/freeifaddrs.") endif() endif() - set(HAVE_DECL_GETIFADDRS TRUE PARENT_SCOPE) - set(HAVE_DECL_FREEIFADDRS TRUE PARENT_SCOPE) + set(HAVE_IFADDRS TRUE PARENT_SCOPE) endfunction() # Clang, when building for 32-bit, diff --git a/src/common/netif.cpp b/src/common/netif.cpp index 7bfec08fdd..51a7522dbf 100644 --- a/src/common/netif.cpp +++ b/src/common/netif.cpp @@ -29,6 +29,11 @@ #include #endif +#ifdef HAVE_IFADDRS +#include +#include +#endif + namespace { //! Return CNetAddr for the specified OS-level network address. @@ -325,7 +330,7 @@ std::vector GetLocalAddresses() } } } -#elif (HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS) +#elif defined(HAVE_IFADDRS) struct ifaddrs* myaddrs; if (getifaddrs(&myaddrs) == 0) { for (struct ifaddrs* ifa = myaddrs; ifa != nullptr; ifa = ifa->ifa_next) diff --git a/src/compat/compat.h b/src/compat/compat.h index 366c648ae7..05210b74ba 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -20,7 +20,6 @@ #else #include // IWYU pragma: export #include // IWYU pragma: export -#include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export diff --git a/src/net.cpp b/src/net.cpp index 66ded1041c..13febcde44 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -41,10 +41,6 @@ #include #endif -#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS -#include -#endif - #include #include #include diff --git a/src/randomenv.cpp b/src/randomenv.cpp index fbab23afe9..84486b38ea 100644 --- a/src/randomenv.cpp +++ b/src/randomenv.cpp @@ -38,7 +38,7 @@ #include #include #endif -#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS +#ifdef HAVE_IFADDRS #include #endif #ifdef HAVE_SYSCTL @@ -330,7 +330,7 @@ void RandAddStaticEnv(CSHA512& hasher) } #endif -#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS +#ifdef HAVE_IFADDRS // Network interfaces struct ifaddrs *ifad = nullptr; getifaddrs(&ifad);