Skip to content

Commit b144620

Browse files
committed
Merge bitcoin#21486: build: link against -lsocket if required for *ifaddrs
4783115 net: add ifaddrs.h include (fanquake) 879215e build: check if -lsocket is required with *ifaddrs (fanquake) 87deac6 rand: only try and use freeifaddrs if available (fanquake) Pull request description: Fixes bitcoin#21485 by linking against `-lsocket` when it's required for using `*ifaddrs` functions. ACKs for top commit: laanwj: Code review ACK 4783115 hebasto: ACK 4783115, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 4542e036e9b029de970eff8a9230fe45d9204bb22313d075f474295d49bdaf1f1cbb36c0c6e2fa8dbbcdba518d8d3a68a6116ce304b82414315f333baf9af0e4
2 parents e4a2918 + 4783115 commit b144620

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

build-aux/m4/l_socket.m4

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Illumos/SmartOS requires linking with -lsocket if
2+
# using getifaddrs & freeifaddrs
3+
4+
m4_define([_CHECK_SOCKET_testbody], [[
5+
#include <sys/types.h>
6+
#include <ifaddrs.h>
7+
8+
int main() {
9+
struct ifaddrs *ifaddr;
10+
getifaddrs(&ifaddr);
11+
freeifaddrs(ifaddr);
12+
}
13+
]])
14+
15+
AC_DEFUN([CHECK_SOCKET], [
16+
17+
AC_LANG_PUSH(C++)
18+
19+
AC_MSG_CHECKING([whether ifaddrs funcs can be used without link library])
20+
21+
AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_SOCKET_testbody])],[
22+
AC_MSG_RESULT([yes])
23+
],[
24+
AC_MSG_RESULT([no])
25+
LIBS="$LIBS -lsocket"
26+
AC_MSG_CHECKING([whether getifaddrs needs -lsocket])
27+
AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_SOCKET_testbody])],[
28+
AC_MSG_RESULT([yes])
29+
],[
30+
AC_MSG_RESULT([no])
31+
AC_MSG_FAILURE([cannot figure out how to use getifaddrs])
32+
])
33+
])
34+
35+
AC_LANG_POP
36+
])

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ fi
936936

937937
AC_CHECK_HEADERS([endian.h sys/endian.h byteswap.h stdio.h stdlib.h unistd.h strings.h sys/types.h sys/stat.h sys/select.h sys/prctl.h sys/sysctl.h vm/vm_param.h sys/vmmeter.h sys/resources.h])
938938

939-
AC_CHECK_DECLS([getifaddrs, freeifaddrs],,,
939+
AC_CHECK_DECLS([getifaddrs, freeifaddrs],[CHECK_SOCKET],,
940940
[#include <sys/types.h>
941941
#include <ifaddrs.h>]
942942
)

src/net.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include <fcntl.h>
3232
#endif
3333

34+
#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
35+
#include <ifaddrs.h>
36+
#endif
37+
3438
#ifdef USE_POLL
3539
#include <poll.h>
3640
#endif

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
41+
#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
4242
#include <ifaddrs.h>
4343
#endif
4444
#if HAVE_SYSCTL
@@ -361,7 +361,7 @@ void RandAddStaticEnv(CSHA512& hasher)
361361
hasher.Write((const unsigned char*)hname, strnlen(hname, 256));
362362
}
363363

364-
#if HAVE_DECL_GETIFADDRS
364+
#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
365365
// Network interfaces
366366
struct ifaddrs *ifad = NULL;
367367
getifaddrs(&ifad);

0 commit comments

Comments
 (0)