Skip to content

Commit 879215e

Browse files
committed
build: check if -lsocket is required with *ifaddrs
1 parent 87deac6 commit 879215e

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
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
)

0 commit comments

Comments
 (0)