From 87deac66aa747481e6f34fc80599e1e490de3ea0 Mon Sep 17 00:00:00 2001 From: fanquake Date: Sat, 20 Mar 2021 17:57:43 +0800 Subject: [PATCH 1/3] rand: only try and use freeifaddrs if available --- src/randomenv.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/randomenv.cpp b/src/randomenv.cpp index 9248db1539..fa2a3a0607 100644 --- a/src/randomenv.cpp +++ b/src/randomenv.cpp @@ -38,7 +38,7 @@ #include #include #endif -#if HAVE_DECL_GETIFADDRS +#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS #include #endif #if HAVE_SYSCTL @@ -361,7 +361,7 @@ void RandAddStaticEnv(CSHA512& hasher) hasher.Write((const unsigned char*)hname, strnlen(hname, 256)); } -#if HAVE_DECL_GETIFADDRS +#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS // Network interfaces struct ifaddrs *ifad = NULL; getifaddrs(&ifad); From 879215e665a9f348c8d3fa92701c34065bc86a69 Mon Sep 17 00:00:00 2001 From: fanquake Date: Sun, 21 Mar 2021 08:41:26 +0800 Subject: [PATCH 2/3] build: check if -lsocket is required with *ifaddrs --- build-aux/m4/l_socket.m4 | 36 ++++++++++++++++++++++++++++++++++++ configure.ac | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 build-aux/m4/l_socket.m4 diff --git a/build-aux/m4/l_socket.m4 b/build-aux/m4/l_socket.m4 new file mode 100644 index 0000000000..38923a98fc --- /dev/null +++ b/build-aux/m4/l_socket.m4 @@ -0,0 +1,36 @@ +# Illumos/SmartOS requires linking with -lsocket if +# using getifaddrs & freeifaddrs + +m4_define([_CHECK_SOCKET_testbody], [[ + #include + #include + + int main() { + struct ifaddrs *ifaddr; + getifaddrs(&ifaddr); + freeifaddrs(ifaddr); + } +]]) + +AC_DEFUN([CHECK_SOCKET], [ + + AC_LANG_PUSH(C++) + + AC_MSG_CHECKING([whether ifaddrs funcs can be used without link library]) + + AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_SOCKET_testbody])],[ + AC_MSG_RESULT([yes]) + ],[ + AC_MSG_RESULT([no]) + LIBS="$LIBS -lsocket" + AC_MSG_CHECKING([whether getifaddrs needs -lsocket]) + AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_SOCKET_testbody])],[ + AC_MSG_RESULT([yes]) + ],[ + AC_MSG_RESULT([no]) + AC_MSG_FAILURE([cannot figure out how to use getifaddrs]) + ]) + ]) + + AC_LANG_POP +]) diff --git a/configure.ac b/configure.ac index 9ac2643374..c3eabad131 100644 --- a/configure.ac +++ b/configure.ac @@ -936,7 +936,7 @@ fi 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]) -AC_CHECK_DECLS([getifaddrs, freeifaddrs],,, +AC_CHECK_DECLS([getifaddrs, freeifaddrs],[CHECK_SOCKET],, [#include #include ] ) From 4783115fd4cccb46a7f8c592b34fa7c094c29410 Mon Sep 17 00:00:00 2001 From: fanquake Date: Fri, 26 Mar 2021 12:53:05 +0800 Subject: [PATCH 3/3] net: add ifaddrs.h include --- src/net.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index 3b1ebede98..c4d87c6f6a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -31,6 +31,10 @@ #include #endif +#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS +#include +#endif + #ifdef USE_POLL #include #endif