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)
23 dnl we need to check that net/if.h really can be used, to cope with hpux
24 dnl where including it always fails
25 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
26 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
29 # include <sys/socket.h>
32 int main(void) {return 0;}])],
33 [libreplace_cv_USABLE_NET_IF_H=yes],
34 [libreplace_cv_USABLE_NET_IF_H=no]
37 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
38 AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
41 AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
42 AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
43 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
44 AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
45 AC_HAVE_TYPE([struct sockaddr_storage], [
46 #include <sys/socket.h>
47 #include <sys/types.h>
48 #include <netinet/in.h>
50 AC_HAVE_TYPE([struct sockaddr_in6], [
51 #include <sys/socket.h>
52 #include <sys/types.h>
53 #include <netinet/in.h>
56 if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
57 AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
58 AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
60 #include <sys/socket.h>
61 #include <sys/types.h>
62 #include <netinet/in.h>
65 if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
66 AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
67 AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
69 #include <sys/socket.h>
70 #include <sys/types.h>
71 #include <netinet/in.h>
76 AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
79 #include <sys/types.h>
80 #include <sys/socket.h>
81 #include <netinet/in.h>
83 struct sockaddr_in sock; sock.sin_len = sizeof(sock);
85 libreplace_cv_HAVE_SOCK_SIN_LEN=yes
87 libreplace_cv_HAVE_SOCK_SIN_LEN=no
90 if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then
91 AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
94 ############################################
95 # check for unix domain sockets
96 AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
98 #include <sys/types.h>
101 #include <sys/socket.h>
104 struct sockaddr_un sunaddr;
105 sunaddr.sun_family = AF_UNIX;
107 libreplace_cv_HAVE_UNIXSOCKET=yes
109 libreplace_cv_HAVE_UNIXSOCKET=no
112 if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
113 AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support])
116 dnl The following test is roughl taken from the cvs sources.
118 dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
119 dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
120 dnl libsocket.so which has a bad implementation of gethostbyname (it
121 dnl only looks in /etc/hosts), so we only look for -lsocket if we need
123 AC_CHECK_FUNCS(connect)
124 if test x"$ac_cv_func_connect" = x"no"; then
125 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect)
126 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect)
127 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect)
128 AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect)
129 dnl We can't just call AC_CHECK_FUNCS(connect) here,
130 dnl because the value has been cached.
131 if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
132 test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
133 test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
134 test x"$ac_cv_lib_ext_inet_connect" = x"yes"
136 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
140 AC_CHECK_FUNCS(gethostbyname)
141 if test x"$ac_cv_func_gethostbyname" = x"no"; then
142 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname)
143 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname)
144 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname)
145 dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
146 dnl because the value has been cached.
147 if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
148 test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
149 test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
151 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
152 [Whether the system has gethostbyname()])
156 dnl HP-UX has if_nametoindex in -lipv6
157 AC_CHECK_FUNCS(if_nametoindex)
158 if test x"$ac_cv_func_if_nametoindex" = x"no"; then
159 AC_CHECK_LIB_EXT(ipv6, LIBREPLACE_NETWORK_LIBS, if_nametoindex)
160 dnl We can't just call AC_CHECK_FUNCS(if_nametoindex) here,
161 dnl because the value has been cached.
162 if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes"
164 AC_DEFINE(HAVE_IF_NAMETOINDEX, 1,
165 [Whether the system has if_nametoindex()])
169 # The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
171 LIBS="${LIBREPLACE_NETWORK_LIBS}"
172 SAVE_CPPFLAGS="$CPPFLAGS"
173 CPPFLAGS="$CPPFLAGS -I$libreplacedir"
175 AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} socketpair.o"])
177 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
181 #include <sys/types.h>
182 #include <netinet/in.h>
183 #ifdef HAVE_ARPA_INET_H
184 #include <arpa/inet.h>
186 main() { struct in_addr ip; ip.s_addr = 0x12345678;
187 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
188 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
190 libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
192 AC_CHECK_FUNCS(inet_ntoa,[],[libreplace_cv_REPLACE_INET_NTOA=yes])
193 if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
194 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
195 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntoa.o"
198 AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_aton.o"])
200 AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntop.o"])
202 AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_pton.o"])
204 dnl test for getaddrinfo/getnameinfo
205 AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
207 #include <sys/types.h>
212 #include <sys/socket.h>
216 struct addrinfo *ai = NULL;
217 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
219 const char *es = gai_strerror(ret);
222 ret = getnameinfo(&sa, sizeof(sa),
227 libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)])
228 if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
229 AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo])
230 AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo])
231 AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
232 AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
234 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getaddrinfo.o"
237 AC_CHECK_HEADERS([ifaddrs.h])
239 dnl Used when getifaddrs is not available
240 AC_CHECK_MEMBERS([struct sockaddr.sa_len],
241 [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
243 [#include <sys/socket.h>])
245 dnl test for getifaddrs and freeifaddrs
246 AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
248 #include <sys/types.h>
253 #include <sys/socket.h>
254 #include <netinet/in.h>
255 #include <arpa/inet.h>
259 struct ifaddrs *ifp = NULL;
260 int ret = getifaddrs (&ifp);
263 libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
264 if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
265 AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
266 AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
267 AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
271 # look for a method of finding the list of network interfaces
273 AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
275 #define HAVE_IFACE_GETIFADDRS 1
276 #define NO_CONFIG_H 1
277 #define AUTOCONF_TEST 1
278 #define SOCKET_WRAPPER_NOT_REPLACE
279 #include "$libreplacedir/replace.c"
280 #include "$libreplacedir/inet_ntop.c"
281 #include "$libreplacedir/snprintf.c"
282 #include "$libreplacedir/getifaddrs.c"
283 #define getifaddrs_test main
284 #include "$libreplacedir/test/getifaddrs.c"],
285 libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
286 if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
287 iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
289 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getifaddrs.o"
293 if test $iface = no; then
294 AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
296 #define HAVE_IFACE_AIX 1
297 #define NO_CONFIG_H 1
298 #define AUTOCONF_TEST 1
299 #undef _XOPEN_SOURCE_EXTENDED
300 #define SOCKET_WRAPPER_NOT_REPLACE
301 #include "$libreplacedir/replace.c"
302 #include "$libreplacedir/inet_ntop.c"
303 #include "$libreplacedir/snprintf.c"
304 #include "$libreplacedir/getifaddrs.c"
305 #define getifaddrs_test main
306 #include "$libreplacedir/test/getifaddrs.c"],
307 libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
308 if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
309 iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
314 if test $iface = no; then
315 AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
317 #define HAVE_IFACE_IFCONF 1
318 #define NO_CONFIG_H 1
319 #define AUTOCONF_TEST 1
320 #define SOCKET_WRAPPER_NOT_REPLACE
321 #include "$libreplacedir/replace.c"
322 #include "$libreplacedir/inet_ntop.c"
323 #include "$libreplacedir/snprintf.c"
324 #include "$libreplacedir/getifaddrs.c"
325 #define getifaddrs_test main
326 #include "$libreplacedir/test/getifaddrs.c"],
327 libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
328 if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
329 iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
333 if test $iface = no; then
334 AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
336 #define HAVE_IFACE_IFREQ 1
337 #define NO_CONFIG_H 1
338 #define AUTOCONF_TEST 1
339 #define SOCKET_WRAPPER_NOT_REPLACE
340 #include "$libreplacedir/replace.c"
341 #include "$libreplacedir/inet_ntop.c"
342 #include "$libreplacedir/snprintf.c"
343 #include "$libreplacedir/getifaddrs.c"
344 #define getifaddrs_test main
345 #include "$libreplacedir/test/getifaddrs.c"],
346 libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
347 if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
348 iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
353 AC_CACHE_CHECK([for ipv6 support],libreplace_cv_HAVE_IPV6,[
355 #include <stdlib.h> /* for NULL */
356 #include <sys/socket.h>
357 #include <sys/types.h>
359 #include <netinet/in.h>
362 struct sockaddr_storage sa_store;
363 struct addrinfo *ai = NULL;
364 struct in6_addr in6addr;
365 int idx = if_nametoindex("iface1");
366 int s = socket(AF_INET6, SOCK_STREAM, 0);
367 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
369 const char *es = gai_strerror(ret);
373 libreplace_cv_HAVE_IPV6=yes
375 libreplace_cv_HAVE_IPV6=no
378 if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then
379 AC_DEFINE(HAVE_IPV6,1,[Whether the system has IPv6 support])
383 CPPFLAGS="$SAVE_CPPFLAGS"
385 LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
387 echo "LIBREPLACE_NETWORK_CHECKS: END"
388 ]) dnl end AC_LIBREPLACE_NETWORK_CHECKS