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/ip.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
11 AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
13 dnl we need to check that net/if.h really can be used, to cope with hpux
14 dnl where including it always fails
15 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
16 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
19 # include <sys/socket.h>
22 int main(void) {return 0;}])],
23 [libreplace_cv_USABLE_NET_IF_H=yes],
24 [libreplace_cv_USABLE_NET_IF_H=no]
27 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
28 AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
31 AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
32 AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
33 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
34 AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
35 AC_HAVE_TYPE([struct sockaddr_storage], [
36 #include <sys/socket.h>
37 #include <sys/types.h>
38 #include <netinet/in.h>
40 AC_HAVE_TYPE([struct sockaddr_in6], [
41 #include <sys/socket.h>
42 #include <sys/types.h>
43 #include <netinet/in.h>
46 if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
47 AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
48 AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
50 #include <sys/socket.h>
51 #include <sys/types.h>
52 #include <netinet/in.h>
55 if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
56 AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
57 AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
59 #include <sys/socket.h>
60 #include <sys/types.h>
61 #include <netinet/in.h>
66 AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
69 #include <sys/types.h>
70 #include <sys/socket.h>
71 #include <netinet/in.h>
73 struct sockaddr_in sock; sock.sin_len = sizeof(sock);
75 libreplace_cv_HAVE_SOCK_SIN_LEN=yes
77 libreplace_cv_HAVE_SOCK_SIN_LEN=no
80 if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then
81 AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
84 ############################################
85 # check for unix domain sockets
86 AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
88 #include <sys/types.h>
91 #include <sys/socket.h>
94 struct sockaddr_un sunaddr;
95 sunaddr.sun_family = AF_UNIX;
97 libreplace_cv_HAVE_UNIXSOCKET=yes
99 libreplace_cv_HAVE_UNIXSOCKET=no
102 if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
103 AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support])
106 dnl The following test is roughl taken from the cvs sources.
108 dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
109 dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
110 dnl libsocket.so which has a bad implementation of gethostbyname (it
111 dnl only looks in /etc/hosts), so we only look for -lsocket if we need
113 AC_CHECK_FUNCS(connect)
114 if test x"$ac_cv_func_connect" = x"no"; then
115 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect)
116 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect)
117 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect)
118 AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect)
119 dnl We can't just call AC_CHECK_FUNCS(connect) here,
120 dnl because the value has been cached.
121 if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
122 test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
123 test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
124 test x"$ac_cv_lib_ext_inet_connect" = x"yes"
126 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
130 AC_CHECK_FUNCS(gethostbyname)
131 if test x"$ac_cv_func_gethostbyname" = x"no"; then
132 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname)
133 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname)
134 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname)
135 dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
136 dnl because the value has been cached.
137 if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
138 test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
139 test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
141 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
142 [Whether the system has gethostbyname()])
146 dnl HP-UX has if_nametoindex in -lipv6
147 AC_CHECK_FUNCS(if_nametoindex)
148 if test x"$ac_cv_func_if_nametoindex" = x"no"; then
149 AC_CHECK_LIB_EXT(ipv6, LIBREPLACE_NETWORK_LIBS, if_nametoindex)
150 dnl We can't just call AC_CHECK_FUNCS(if_nametoindex) here,
151 dnl because the value has been cached.
152 if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes"
154 AC_DEFINE(HAVE_IF_NAMETOINDEX, 1,
155 [Whether the system has if_nametoindex()])
159 # The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
161 LIBS="${LIBREPLACE_NETWORK_LIBS}"
162 SAVE_CPPFLAGS="$CPPFLAGS"
163 CPPFLAGS="$CPPFLAGS -I$libreplacedir"
165 AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} socketpair.o"])
167 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
171 #include <sys/types.h>
172 #include <netinet/in.h>
173 #ifdef HAVE_ARPA_INET_H
174 #include <arpa/inet.h>
176 main() { struct in_addr ip; ip.s_addr = 0x12345678;
177 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
178 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
180 libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
182 AC_CHECK_FUNCS(inet_ntoa,[],[libreplace_cv_REPLACE_INET_NTOA=yes])
183 if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
184 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
185 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntoa.o"
188 AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_aton.o"])
190 AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntop.o"])
192 AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_pton.o"])
194 dnl test for getaddrinfo/getnameinfo
195 AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
197 #include <sys/types.h>
202 #include <sys/socket.h>
206 struct addrinfo *ai = NULL;
207 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
209 const char *es = gai_strerror(ret);
212 ret = getnameinfo(&sa, sizeof(sa),
217 libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)])
218 if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
219 AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo])
220 AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo])
221 AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
222 AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
224 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getaddrinfo.o"
227 AC_CHECK_HEADERS([ifaddrs.h])
229 dnl Used when getifaddrs is not available
230 AC_CHECK_MEMBERS([struct sockaddr.sa_len],
231 [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
233 [#include <sys/socket.h>])
235 dnl test for getifaddrs and freeifaddrs
236 AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
238 #include <sys/types.h>
243 #include <sys/socket.h>
244 #include <netinet/in.h>
245 #include <arpa/inet.h>
249 struct ifaddrs *ifp = NULL;
250 int ret = getifaddrs (&ifp);
253 libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
254 if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
255 AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
256 AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
257 AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
261 # look for a method of finding the list of network interfaces
263 AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
265 #define HAVE_IFACE_GETIFADDRS 1
266 #define NO_CONFIG_H 1
267 #define AUTOCONF_TEST 1
268 #define SOCKET_WRAPPER_NOT_REPLACE
269 #include "$libreplacedir/replace.c"
270 #include "$libreplacedir/inet_ntop.c"
271 #include "$libreplacedir/snprintf.c"
272 #include "$libreplacedir/getifaddrs.c"
273 #define getifaddrs_test main
274 #include "$libreplacedir/test/getifaddrs.c"],
275 libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
276 if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
277 iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
279 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getifaddrs.o"
283 if test $iface = no; then
284 AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
286 #define HAVE_IFACE_AIX 1
287 #define NO_CONFIG_H 1
288 #define AUTOCONF_TEST 1
289 #undef _XOPEN_SOURCE_EXTENDED
290 #define SOCKET_WRAPPER_NOT_REPLACE
291 #include "$libreplacedir/replace.c"
292 #include "$libreplacedir/inet_ntop.c"
293 #include "$libreplacedir/snprintf.c"
294 #include "$libreplacedir/getifaddrs.c"
295 #define getifaddrs_test main
296 #include "$libreplacedir/test/getifaddrs.c"],
297 libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
298 if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
299 iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
304 if test $iface = no; then
305 AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
307 #define HAVE_IFACE_IFCONF 1
308 #define NO_CONFIG_H 1
309 #define AUTOCONF_TEST 1
310 #define SOCKET_WRAPPER_NOT_REPLACE
311 #include "$libreplacedir/replace.c"
312 #include "$libreplacedir/inet_ntop.c"
313 #include "$libreplacedir/snprintf.c"
314 #include "$libreplacedir/getifaddrs.c"
315 #define getifaddrs_test main
316 #include "$libreplacedir/test/getifaddrs.c"],
317 libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
318 if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
319 iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
323 if test $iface = no; then
324 AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
326 #define HAVE_IFACE_IFREQ 1
327 #define NO_CONFIG_H 1
328 #define AUTOCONF_TEST 1
329 #define SOCKET_WRAPPER_NOT_REPLACE
330 #include "$libreplacedir/replace.c"
331 #include "$libreplacedir/inet_ntop.c"
332 #include "$libreplacedir/snprintf.c"
333 #include "$libreplacedir/getifaddrs.c"
334 #define getifaddrs_test main
335 #include "$libreplacedir/test/getifaddrs.c"],
336 libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
337 if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
338 iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
343 AC_CACHE_CHECK([for ipv6 support],libreplace_cv_HAVE_IPV6,[
345 #include <stdlib.h> /* for NULL */
346 #include <sys/socket.h>
347 #include <sys/types.h>
351 struct sockaddr_storage sa_store;
352 struct addrinfo *ai = NULL;
353 struct in6_addr in6addr;
354 int idx = if_nametoindex("iface1");
355 int s = socket(AF_INET6, SOCK_STREAM, 0);
356 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
358 const char *es = gai_strerror(ret);
362 libreplace_cv_HAVE_IPV6=yes
364 libreplace_cv_HAVE_IPV6=no
367 if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then
368 AC_DEFINE(HAVE_IPV6,1,[Whether the system has IPv6 support])
372 CPPFLAGS="$SAVE_CPPFLAGS"
374 LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
376 echo "LIBREPLACE_NETWORK_CHECKS: END"
377 ]) dnl end AC_LIBREPLACE_NETWORK_CHECKS