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], [], [],[#ifdef HAVE_NETINET_IN_H
11 #include <netinet/in.h>
13 AC_CHECK_HEADERS(netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
14 AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
16 dnl we need to check that net/if.h really can be used, to cope with hpux
17 dnl where including it always fails
18 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
19 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
22 # include <sys/socket.h>
25 int main(void) {return 0;}])],
26 [libreplace_cv_USABLE_NET_IF_H=yes],
27 [libreplace_cv_USABLE_NET_IF_H=no]
30 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
31 AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
34 AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
35 AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
36 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
37 AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
38 AC_HAVE_TYPE([struct sockaddr_storage], [
39 #include <sys/socket.h>
40 #include <sys/types.h>
41 #include <netinet/in.h>
43 AC_HAVE_TYPE([struct sockaddr_in6], [
44 #include <sys/socket.h>
45 #include <sys/types.h>
46 #include <netinet/in.h>
49 if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
50 AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
51 AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
53 #include <sys/socket.h>
54 #include <sys/types.h>
55 #include <netinet/in.h>
58 if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
59 AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
60 AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
62 #include <sys/socket.h>
63 #include <sys/types.h>
64 #include <netinet/in.h>
69 AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
72 #include <sys/types.h>
73 #include <sys/socket.h>
74 #include <netinet/in.h>
76 struct sockaddr_in sock; sock.sin_len = sizeof(sock);
78 libreplace_cv_HAVE_SOCK_SIN_LEN=yes
80 libreplace_cv_HAVE_SOCK_SIN_LEN=no
83 if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then
84 AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
87 ############################################
88 # check for unix domain sockets
89 AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
91 #include <sys/types.h>
94 #include <sys/socket.h>
97 struct sockaddr_un sunaddr;
98 sunaddr.sun_family = AF_UNIX;
100 libreplace_cv_HAVE_UNIXSOCKET=yes
102 libreplace_cv_HAVE_UNIXSOCKET=no
105 if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
106 AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support])
109 dnl The following test is roughl taken from the cvs sources.
111 dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
112 dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
113 dnl libsocket.so which has a bad implementation of gethostbyname (it
114 dnl only looks in /etc/hosts), so we only look for -lsocket if we need
116 AC_CHECK_FUNCS(connect)
117 if test x"$ac_cv_func_connect" = x"no"; then
118 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect)
119 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect)
120 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect)
121 AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect)
122 dnl We can't just call AC_CHECK_FUNCS(connect) here,
123 dnl because the value has been cached.
124 if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
125 test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
126 test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
127 test x"$ac_cv_lib_ext_inet_connect" = x"yes"
129 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
133 AC_CHECK_FUNCS(gethostbyname)
134 if test x"$ac_cv_func_gethostbyname" = x"no"; then
135 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname)
136 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname)
137 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname)
138 dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
139 dnl because the value has been cached.
140 if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
141 test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
142 test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
144 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
145 [Whether the system has gethostbyname()])
149 dnl HP-UX has if_nametoindex in -lipv6
150 AC_CHECK_FUNCS(if_nametoindex)
151 if test x"$ac_cv_func_if_nametoindex" = x"no"; then
152 AC_CHECK_LIB_EXT(ipv6, LIBREPLACE_NETWORK_LIBS, if_nametoindex)
153 dnl We can't just call AC_CHECK_FUNCS(if_nametoindex) here,
154 dnl because the value has been cached.
155 if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes"
157 AC_DEFINE(HAVE_IF_NAMETOINDEX, 1,
158 [Whether the system has if_nametoindex()])
162 # The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
164 LIBS="${LIBREPLACE_NETWORK_LIBS}"
165 SAVE_CPPFLAGS="$CPPFLAGS"
166 CPPFLAGS="$CPPFLAGS -I$libreplacedir"
168 AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} socketpair.o"])
170 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
174 #include <sys/types.h>
175 #include <netinet/in.h>
176 #ifdef HAVE_ARPA_INET_H
177 #include <arpa/inet.h>
179 main() { struct in_addr ip; ip.s_addr = 0x12345678;
180 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
181 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
183 libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
185 AC_CHECK_FUNCS(inet_ntoa,[],[libreplace_cv_REPLACE_INET_NTOA=yes])
186 if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
187 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
188 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntoa.o"
191 AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_aton.o"])
193 AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntop.o"])
195 AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_pton.o"])
197 dnl test for getaddrinfo/getnameinfo
198 AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
200 #include <sys/types.h>
205 #include <sys/socket.h>
209 struct addrinfo *ai = NULL;
210 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
212 const char *es = gai_strerror(ret);
215 ret = getnameinfo(&sa, sizeof(sa),
220 libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)])
221 if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
222 AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo])
223 AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo])
224 AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
225 AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
227 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getaddrinfo.o"
230 AC_CHECK_HEADERS([ifaddrs.h])
232 dnl Used when getifaddrs is not available
233 AC_CHECK_MEMBERS([struct sockaddr.sa_len],
234 [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
236 [#include <sys/socket.h>])
238 dnl test for getifaddrs and freeifaddrs
239 AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
241 #include <sys/types.h>
246 #include <sys/socket.h>
247 #include <netinet/in.h>
248 #include <arpa/inet.h>
252 struct ifaddrs *ifp = NULL;
253 int ret = getifaddrs (&ifp);
256 libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
257 if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
258 AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
259 AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
260 AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
264 # look for a method of finding the list of network interfaces
266 AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
268 #define HAVE_IFACE_GETIFADDRS 1
269 #define NO_CONFIG_H 1
270 #define AUTOCONF_TEST 1
271 #define SOCKET_WRAPPER_NOT_REPLACE
272 #include "$libreplacedir/replace.c"
273 #include "$libreplacedir/inet_ntop.c"
274 #include "$libreplacedir/snprintf.c"
275 #include "$libreplacedir/getifaddrs.c"
276 #define getifaddrs_test main
277 #include "$libreplacedir/test/getifaddrs.c"],
278 libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
279 if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
280 iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
282 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getifaddrs.o"
286 if test $iface = no; then
287 AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
289 #define HAVE_IFACE_AIX 1
290 #define NO_CONFIG_H 1
291 #define AUTOCONF_TEST 1
292 #undef _XOPEN_SOURCE_EXTENDED
293 #define SOCKET_WRAPPER_NOT_REPLACE
294 #include "$libreplacedir/replace.c"
295 #include "$libreplacedir/inet_ntop.c"
296 #include "$libreplacedir/snprintf.c"
297 #include "$libreplacedir/getifaddrs.c"
298 #define getifaddrs_test main
299 #include "$libreplacedir/test/getifaddrs.c"],
300 libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
301 if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
302 iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
307 if test $iface = no; then
308 AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
310 #define HAVE_IFACE_IFCONF 1
311 #define NO_CONFIG_H 1
312 #define AUTOCONF_TEST 1
313 #define SOCKET_WRAPPER_NOT_REPLACE
314 #include "$libreplacedir/replace.c"
315 #include "$libreplacedir/inet_ntop.c"
316 #include "$libreplacedir/snprintf.c"
317 #include "$libreplacedir/getifaddrs.c"
318 #define getifaddrs_test main
319 #include "$libreplacedir/test/getifaddrs.c"],
320 libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
321 if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
322 iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
326 if test $iface = no; then
327 AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
329 #define HAVE_IFACE_IFREQ 1
330 #define NO_CONFIG_H 1
331 #define AUTOCONF_TEST 1
332 #define SOCKET_WRAPPER_NOT_REPLACE
333 #include "$libreplacedir/replace.c"
334 #include "$libreplacedir/inet_ntop.c"
335 #include "$libreplacedir/snprintf.c"
336 #include "$libreplacedir/getifaddrs.c"
337 #define getifaddrs_test main
338 #include "$libreplacedir/test/getifaddrs.c"],
339 libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
340 if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
341 iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
346 AC_CACHE_CHECK([for ipv6 support],libreplace_cv_HAVE_IPV6,[
348 #include <stdlib.h> /* for NULL */
349 #include <sys/socket.h>
350 #include <sys/types.h>
354 struct sockaddr_storage sa_store;
355 struct addrinfo *ai = NULL;
356 struct in6_addr in6addr;
357 int idx = if_nametoindex("iface1");
358 int s = socket(AF_INET6, SOCK_STREAM, 0);
359 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
361 const char *es = gai_strerror(ret);
365 libreplace_cv_HAVE_IPV6=yes
367 libreplace_cv_HAVE_IPV6=no
370 if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then
371 AC_DEFINE(HAVE_IPV6,1,[Whether the system has IPv6 support])
375 CPPFLAGS="$SAVE_CPPFLAGS"
377 LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
379 echo "LIBREPLACE_NETWORK_CHECKS: END"
380 ]) dnl end AC_LIBREPLACE_NETWORK_CHECKS