Skip to content

Commit 746ab19

Browse files
committed
Merge bitcoin/bitcoin#32446: build: simplify *ifaddr handling
ab878a7 build: simplify *ifaddr handling (fanquake) Pull request description: 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. ACKs for top commit: hebasto: ACK ab878a7. Only addressed my [comment](bitcoin/bitcoin#32446 (comment)) and rebased since my recent [review](bitcoin/bitcoin#32446 (review)). TheCharlatan: ACK ab878a7 Tree-SHA512: 7667305df9fef4728526c7217f85b51e739ec63b38e808da51d6ae65cb6f2696afa5ba82e5a72ed4a7a9b79ffa2402640448af4392587253027122eab7618e30
2 parents 19b1e17 + ab878a7 commit 746ab19

File tree

7 files changed

+12
-21
lines changed

7 files changed

+12
-21
lines changed

cmake/bitcoin-build-config.h.in

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,8 @@
5555
*/
5656
#cmakedefine01 HAVE_DECL_FORK
5757

58-
/* Define to 1 if you have the declaration of `freeifaddrs', and to 0 if you
59-
don't. */
60-
#cmakedefine01 HAVE_DECL_FREEIFADDRS
61-
62-
/* Define to 1 if you have the declaration of `getifaddrs', and to 0 if you
63-
don't. */
64-
#cmakedefine01 HAVE_DECL_GETIFADDRS
58+
/* Define to 1 if '*ifaddrs' are available. */
59+
#cmakedefine HAVE_IFADDRS 1
6560

6661
/* Define to 1 if you have the declaration of `pipe2', and to 0 if you don't.
6762
*/

cmake/introspection.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44

55
include(CheckCXXSourceCompiles)
66
include(CheckCXXSymbolExists)
7-
include(CheckIncludeFileCXX)
87

98
check_cxx_symbol_exists(O_CLOEXEC "fcntl.h" HAVE_O_CLOEXEC)
109
check_cxx_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
1110
check_cxx_symbol_exists(fork "unistd.h" HAVE_DECL_FORK)
1211
check_cxx_symbol_exists(pipe2 "unistd.h" HAVE_DECL_PIPE2)
1312
check_cxx_symbol_exists(setsid "unistd.h" HAVE_DECL_SETSID)
1413

15-
check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H)
16-
check_include_file_cxx(ifaddrs.h HAVE_IFADDRS_H)
17-
if(HAVE_SYS_TYPES_H AND HAVE_IFADDRS_H)
14+
if(NOT WIN32)
1815
include(TestAppendRequiredLibraries)
1916
test_append_socket_library(core_interface)
2017
endif()

cmake/module/TestAppendRequiredLibraries.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ function(test_append_socket_library target)
3838
message(FATAL_ERROR "Cannot figure out how to use getifaddrs/freeifaddrs.")
3939
endif()
4040
endif()
41-
set(HAVE_DECL_GETIFADDRS TRUE PARENT_SCOPE)
42-
set(HAVE_DECL_FREEIFADDRS TRUE PARENT_SCOPE)
41+
set(HAVE_IFADDRS TRUE PARENT_SCOPE)
4342
endfunction()
4443

4544
# Clang, when building for 32-bit,

src/common/netif.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
#include <sys/sysctl.h>
3030
#endif
3131

32+
#ifdef HAVE_IFADDRS
33+
#include <sys/types.h>
34+
#include <ifaddrs.h>
35+
#endif
36+
3237
namespace {
3338

3439
//! Return CNetAddr for the specified OS-level network address.
@@ -325,7 +330,7 @@ std::vector<CNetAddr> GetLocalAddresses()
325330
}
326331
}
327332
}
328-
#elif (HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS)
333+
#elif defined(HAVE_IFADDRS)
329334
struct ifaddrs* myaddrs;
330335
if (getifaddrs(&myaddrs) == 0) {
331336
for (struct ifaddrs* ifa = myaddrs; ifa != nullptr; ifa = ifa->ifa_next)

src/compat/compat.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#else
2121
#include <arpa/inet.h> // IWYU pragma: export
2222
#include <fcntl.h> // IWYU pragma: export
23-
#include <ifaddrs.h> // IWYU pragma: export
2423
#include <net/if.h> // IWYU pragma: export
2524
#include <netdb.h> // IWYU pragma: export
2625
#include <netinet/in.h> // IWYU pragma: export

src/net.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
#include <string.h>
4242
#endif
4343

44-
#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
45-
#include <ifaddrs.h>
46-
#endif
47-
4844
#include <algorithm>
4945
#include <array>
5046
#include <cmath>

src/randomenv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <sys/utsname.h>
3939
#include <unistd.h>
4040
#endif
41-
#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
41+
#ifdef HAVE_IFADDRS
4242
#include <ifaddrs.h>
4343
#endif
4444
#ifdef HAVE_SYSCTL
@@ -330,7 +330,7 @@ void RandAddStaticEnv(CSHA512& hasher)
330330
}
331331
#endif
332332

333-
#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
333+
#ifdef HAVE_IFADDRS
334334
// Network interfaces
335335
struct ifaddrs *ifad = nullptr;
336336
getifaddrs(&ifad);

0 commit comments

Comments
 (0)