1 AC_DEFUN_ONCE(AC_LIBREPLACE_NETWORK_CHECKS,
3 echo "LIBREPLACE_NETWORK_CHECKS: START"
5 AC_DEFINE(LIBREPLACE_NETWORK_CHECKS, 1, [LIBREPLACE_NETWORK_CHECKS were used])
6 LIBREPLACE_NETWORK_OBJS=""
7 LIBREPLACE_NETWORK_LIBS=""
9 AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
10 AC_CHECK_HEADERS(netinet/in_systm.h)
11 AC_CHECK_HEADERS([netinet/ip.h], [], [],[
12 #include <sys/types.h>
13 #ifdef HAVE_NETINET_IN_H
14 #include <netinet/in.h>
16 #ifdef HAVE_NETINET_IN_SYSTM_H
17 #include <netinet/in_systm.h>
20 AC_CHECK_HEADERS(netinet/tcp.h netinet/in_ip.h)
21 AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
22 AC_CHECK_HEADERS(sys/uio.h)
24 dnl we need to check that net/if.h really can be used, to cope with hpux
25 dnl where including it always fails
26 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
27 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
30 # include <sys/socket.h>
33 int main(void) {return 0;}])],
34 [libreplace_cv_USABLE_NET_IF_H=yes],
35 [libreplace_cv_USABLE_NET_IF_H=no]
38 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
39 AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
42 AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
43 AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
44 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
45 AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
46 AC_HAVE_TYPE([struct sockaddr_storage], [
47 #include <sys/socket.h>
48 #include <sys/types.h>
49 #include <netinet/in.h>
51 AC_HAVE_TYPE([struct sockaddr_in6], [
52 #include <sys/socket.h>
53 #include <sys/types.h>
54 #include <netinet/in.h>
57 if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
58 AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
59 AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
61 #include <sys/socket.h>
62 #include <sys/types.h>
63 #include <netinet/in.h>
66 if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
67 AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
68 AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
70 #include <sys/socket.h>
71 #include <sys/types.h>
72 #include <netinet/in.h>
77 AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
80 #include <sys/types.h>
81 #include <sys/socket.h>
82 #include <netinet/in.h>
84 struct sockaddr_in sock; sock.sin_len = sizeof(sock);
86 libreplace_cv_HAVE_SOCK_SIN_LEN=yes
88 libreplace_cv_HAVE_SOCK_SIN_LEN=no
91 if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then
92 AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
95 ############################################
96 # check for unix domain sockets
97 AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
99 #include <sys/types.h>
102 #include <sys/socket.h>
105 struct sockaddr_un sunaddr;
106 sunaddr.sun_family = AF_UNIX;
108 libreplace_cv_HAVE_UNIXSOCKET=yes
110 libreplace_cv_HAVE_UNIXSOCKET=no
113 if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
114 AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support])
117 dnl The following test is roughl taken from the cvs sources.
119 dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
120 dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
121 dnl libsocket.so which has a bad implementation of gethostbyname (it
122 dnl only looks in /etc/hosts), so we only look for -lsocket if we need
124 AC_CHECK_FUNCS(connect)
125 if test x"$ac_cv_func_connect" = x"no"; then
126 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect)
127 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect)
128 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect)
129 AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect)
130 dnl We can't just call AC_CHECK_FUNCS(connect) here,
131 dnl because the value has been cached.
132 if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
133 test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
134 test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
135 test x"$ac_cv_lib_ext_inet_connect" = x"yes"
137 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
141 AC_CHECK_FUNCS(gethostbyname)
142 if test x"$ac_cv_func_gethostbyname" = x"no"; then
143 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname)
144 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname)
145 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname)
146 dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
147 dnl because the value has been cached.
148 if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
149 test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
150 test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
152 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
153 [Whether the system has gethostbyname()])
157 dnl HP-UX has if_nametoindex in -lipv6
158 AC_CHECK_FUNCS(if_nametoindex)
159 if test x"$ac_cv_func_if_nametoindex" = x"no"; then
160 AC_CHECK_LIB_EXT(ipv6, LIBREPLACE_NETWORK_LIBS, if_nametoindex)
161 dnl We can't just call AC_CHECK_FUNCS(if_nametoindex) here,
162 dnl because the value has been cached.
163 if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes"
165 AC_DEFINE(HAVE_IF_NAMETOINDEX, 1,
166 [Whether the system has if_nametoindex()])
170 # The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
172 LIBS="${LIBREPLACE_NETWORK_LIBS}"
173 libreplace_SAVE_CPPFLAGS="$CPPFLAGS"
174 CPPFLAGS="$CPPFLAGS -I$libreplacedir"
176 AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/socketpair.o"])
178 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
182 #include <sys/types.h>
183 #include <netinet/in.h>
184 #ifdef HAVE_ARPA_INET_H
185 #include <arpa/inet.h>
187 main() { struct in_addr ip; ip.s_addr = 0x12345678;
188 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
189 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
191 libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
193 AC_CHECK_FUNCS(inet_ntoa,[],[libreplace_cv_REPLACE_INET_NTOA=yes])
194 if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
195 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
196 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntoa.o"
199 AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_aton.o"])
201 AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntop.o"])
203 AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_pton.o"])
205 dnl test for getaddrinfo/getnameinfo
206 AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
208 #include <sys/types.h>
213 #include <sys/socket.h>
217 struct addrinfo *ai = NULL;
218 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
220 const char *es = gai_strerror(ret);
223 ret = getnameinfo(&sa, sizeof(sa),
228 libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)])
230 if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
231 # getaddrinfo is broken on some AIX systems
232 # see bug 5910, use our replacements if we detect
236 #include <sys/types.h>
237 #include <sys/socket.h>
239 int main(int argc, const char *argv[])
241 struct addrinfo hints = {0,};
242 struct addrinfo *ppres;
243 const char hostname[] = "0.0.0.0";
244 hints.ai_socktype = SOCK_STREAM;
245 hints.ai_family = AF_INET;
247 AI_NUMERICHOST|AI_PASSIVE|AI_ADDRCONFIG;
248 return getaddrinfo(hostname, NULL, &hints, &ppres) != 0 ? 1 : 0;
250 libreplace_cv_HAVE_GETADDRINFO=yes,
251 libreplace_cv_HAVE_GETADDRINFO=no)
254 if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
255 AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo])
256 AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo])
257 AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
258 AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
260 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getaddrinfo.o"
263 AC_CHECK_HEADERS([ifaddrs.h])
265 dnl Used when getifaddrs is not available
266 AC_CHECK_MEMBERS([struct sockaddr.sa_len],
267 [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
269 [#include <sys/socket.h>])
271 dnl test for getifaddrs and freeifaddrs
272 AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
274 #include <sys/types.h>
279 #include <sys/socket.h>
280 #include <netinet/in.h>
281 #include <arpa/inet.h>
285 struct ifaddrs *ifp = NULL;
286 int ret = getifaddrs (&ifp);
289 libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
290 if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
291 AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
292 AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
293 AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
297 # look for a method of finding the list of network interfaces
299 AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
301 #define HAVE_IFACE_GETIFADDRS 1
302 #define NO_CONFIG_H 1
303 #define AUTOCONF_TEST 1
304 #define SOCKET_WRAPPER_NOT_REPLACE
305 #include "$libreplacedir/replace.c"
306 #include "$libreplacedir/inet_ntop.c"
307 #include "$libreplacedir/snprintf.c"
308 #include "$libreplacedir/getifaddrs.c"
309 #define getifaddrs_test main
310 #include "$libreplacedir/test/getifaddrs.c"],
311 libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
312 if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
313 iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
315 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getifaddrs.o"
319 if test $iface = no; then
320 AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
322 #define HAVE_IFACE_AIX 1
323 #define NO_CONFIG_H 1
324 #define AUTOCONF_TEST 1
325 #undef _XOPEN_SOURCE_EXTENDED
326 #define SOCKET_WRAPPER_NOT_REPLACE
327 #include "$libreplacedir/replace.c"
328 #include "$libreplacedir/inet_ntop.c"
329 #include "$libreplacedir/snprintf.c"
330 #include "$libreplacedir/getifaddrs.c"
331 #define getifaddrs_test main
332 #include "$libreplacedir/test/getifaddrs.c"],
333 libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
334 if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
335 iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
340 if test $iface = no; then
341 AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
343 #define HAVE_IFACE_IFCONF 1
344 #define NO_CONFIG_H 1
345 #define AUTOCONF_TEST 1
346 #define SOCKET_WRAPPER_NOT_REPLACE
347 #include "$libreplacedir/replace.c"
348 #include "$libreplacedir/inet_ntop.c"
349 #include "$libreplacedir/snprintf.c"
350 #include "$libreplacedir/getifaddrs.c"
351 #define getifaddrs_test main
352 #include "$libreplacedir/test/getifaddrs.c"],
353 libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
354 if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
355 iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
359 if test $iface = no; then
360 AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
362 #define HAVE_IFACE_IFREQ 1
363 #define NO_CONFIG_H 1
364 #define AUTOCONF_TEST 1
365 #define SOCKET_WRAPPER_NOT_REPLACE
366 #include "$libreplacedir/replace.c"
367 #include "$libreplacedir/inet_ntop.c"
368 #include "$libreplacedir/snprintf.c"
369 #include "$libreplacedir/getifaddrs.c"
370 #define getifaddrs_test main
371 #include "$libreplacedir/test/getifaddrs.c"],
372 libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
373 if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
374 iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
379 AC_CACHE_CHECK([for ipv6 support],libreplace_cv_HAVE_IPV6,[
381 #include <stdlib.h> /* for NULL */
382 #include <sys/socket.h>
383 #include <sys/types.h>
385 #include <netinet/in.h>
388 struct sockaddr_storage sa_store;
389 struct addrinfo *ai = NULL;
390 struct in6_addr in6addr;
391 int idx = if_nametoindex("iface1");
392 int s = socket(AF_INET6, SOCK_STREAM, 0);
393 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
395 const char *es = gai_strerror(ret);
399 libreplace_cv_HAVE_IPV6=yes
401 libreplace_cv_HAVE_IPV6=no
404 if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then
405 AC_DEFINE(HAVE_IPV6,1,[Whether the system has IPv6 support])
409 CPPFLAGS="$libreplace_SAVE_CPPFLAGS"
411 LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
413 echo "LIBREPLACE_NETWORK_CHECKS: END"
414 ]) dnl end AC_LIBREPLACE_NETWORK_CHECKS