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], [], [], [#ifdef HAVE_NETINET_IN_H
12 #include <netinet/in.h>
14 #ifdef HAVE_NETINET_IN_SYSTM_H
15 #include <netinet/in_systm.h>
17 AC_CHECK_HEADERS(netinet/tcp.h netinet/in_ip.h)
18 AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
20 dnl we need to check that net/if.h really can be used, to cope with hpux
21 dnl where including it always fails
22 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
23 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
26 # include <sys/socket.h>
29 int main(void) {return 0;}])],
30 [libreplace_cv_USABLE_NET_IF_H=yes],
31 [libreplace_cv_USABLE_NET_IF_H=no]
34 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
35 AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
38 AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
39 AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
40 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
41 AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
42 AC_HAVE_TYPE([struct sockaddr_storage], [
43 #include <sys/socket.h>
44 #include <sys/types.h>
45 #include <netinet/in.h>
47 AC_HAVE_TYPE([struct sockaddr_in6], [
48 #include <sys/socket.h>
49 #include <sys/types.h>
50 #include <netinet/in.h>
53 if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
54 AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
55 AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
57 #include <sys/socket.h>
58 #include <sys/types.h>
59 #include <netinet/in.h>
62 if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
63 AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
64 AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
66 #include <sys/socket.h>
67 #include <sys/types.h>
68 #include <netinet/in.h>
73 AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
76 #include <sys/types.h>
77 #include <sys/socket.h>
78 #include <netinet/in.h>
80 struct sockaddr_in sock; sock.sin_len = sizeof(sock);
82 libreplace_cv_HAVE_SOCK_SIN_LEN=yes
84 libreplace_cv_HAVE_SOCK_SIN_LEN=no
87 if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then
88 AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
91 ############################################
92 # check for unix domain sockets
93 AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
95 #include <sys/types.h>
98 #include <sys/socket.h>
101 struct sockaddr_un sunaddr;
102 sunaddr.sun_family = AF_UNIX;
104 libreplace_cv_HAVE_UNIXSOCKET=yes
106 libreplace_cv_HAVE_UNIXSOCKET=no
109 if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
110 AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support])
113 dnl The following test is roughl taken from the cvs sources.
115 dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
116 dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
117 dnl libsocket.so which has a bad implementation of gethostbyname (it
118 dnl only looks in /etc/hosts), so we only look for -lsocket if we need
120 AC_CHECK_FUNCS(connect)
121 if test x"$ac_cv_func_connect" = x"no"; then
122 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect)
123 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect)
124 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect)
125 AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect)
126 dnl We can't just call AC_CHECK_FUNCS(connect) here,
127 dnl because the value has been cached.
128 if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
129 test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
130 test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
131 test x"$ac_cv_lib_ext_inet_connect" = x"yes"
133 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
137 AC_CHECK_FUNCS(gethostbyname)
138 if test x"$ac_cv_func_gethostbyname" = x"no"; then
139 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname)
140 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname)
141 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname)
142 dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
143 dnl because the value has been cached.
144 if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
145 test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
146 test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
148 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
149 [Whether the system has gethostbyname()])
153 dnl HP-UX has if_nametoindex in -lipv6
154 AC_CHECK_FUNCS(if_nametoindex)
155 if test x"$ac_cv_func_if_nametoindex" = x"no"; then
156 AC_CHECK_LIB_EXT(ipv6, LIBREPLACE_NETWORK_LIBS, if_nametoindex)
157 dnl We can't just call AC_CHECK_FUNCS(if_nametoindex) here,
158 dnl because the value has been cached.
159 if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes"
161 AC_DEFINE(HAVE_IF_NAMETOINDEX, 1,
162 [Whether the system has if_nametoindex()])
166 # The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
168 LIBS="${LIBREPLACE_NETWORK_LIBS}"
169 SAVE_CPPFLAGS="$CPPFLAGS"
170 CPPFLAGS="$CPPFLAGS -I$libreplacedir"
172 AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} socketpair.o"])
174 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
178 #include <sys/types.h>
179 #include <netinet/in.h>
180 #ifdef HAVE_ARPA_INET_H
181 #include <arpa/inet.h>
183 main() { struct in_addr ip; ip.s_addr = 0x12345678;
184 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
185 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
187 libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
189 AC_CHECK_FUNCS(inet_ntoa,[],[libreplace_cv_REPLACE_INET_NTOA=yes])
190 if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
191 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
192 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntoa.o"
195 AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_aton.o"])
197 AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntop.o"])
199 AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_pton.o"])
201 dnl test for getaddrinfo/getnameinfo
202 AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
204 #include <sys/types.h>
209 #include <sys/socket.h>
213 struct addrinfo *ai = NULL;
214 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
216 const char *es = gai_strerror(ret);
219 ret = getnameinfo(&sa, sizeof(sa),
224 libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)])
225 if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
226 AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo])
227 AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo])
228 AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
229 AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
231 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getaddrinfo.o"
234 AC_CHECK_HEADERS([ifaddrs.h])
236 dnl Used when getifaddrs is not available
237 AC_CHECK_MEMBERS([struct sockaddr.sa_len],
238 [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
240 [#include <sys/socket.h>])
242 dnl test for getifaddrs and freeifaddrs
243 AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
245 #include <sys/types.h>
250 #include <sys/socket.h>
251 #include <netinet/in.h>
252 #include <arpa/inet.h>
256 struct ifaddrs *ifp = NULL;
257 int ret = getifaddrs (&ifp);
260 libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
261 if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
262 AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
263 AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
264 AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
268 # look for a method of finding the list of network interfaces
270 AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
272 #define HAVE_IFACE_GETIFADDRS 1
273 #define NO_CONFIG_H 1
274 #define AUTOCONF_TEST 1
275 #define SOCKET_WRAPPER_NOT_REPLACE
276 #include "$libreplacedir/replace.c"
277 #include "$libreplacedir/inet_ntop.c"
278 #include "$libreplacedir/snprintf.c"
279 #include "$libreplacedir/getifaddrs.c"
280 #define getifaddrs_test main
281 #include "$libreplacedir/test/getifaddrs.c"],
282 libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
283 if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
284 iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
286 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getifaddrs.o"
290 if test $iface = no; then
291 AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
293 #define HAVE_IFACE_AIX 1
294 #define NO_CONFIG_H 1
295 #define AUTOCONF_TEST 1
296 #undef _XOPEN_SOURCE_EXTENDED
297 #define SOCKET_WRAPPER_NOT_REPLACE
298 #include "$libreplacedir/replace.c"
299 #include "$libreplacedir/inet_ntop.c"
300 #include "$libreplacedir/snprintf.c"
301 #include "$libreplacedir/getifaddrs.c"
302 #define getifaddrs_test main
303 #include "$libreplacedir/test/getifaddrs.c"],
304 libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
305 if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
306 iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
311 if test $iface = no; then
312 AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
314 #define HAVE_IFACE_IFCONF 1
315 #define NO_CONFIG_H 1
316 #define AUTOCONF_TEST 1
317 #define SOCKET_WRAPPER_NOT_REPLACE
318 #include "$libreplacedir/replace.c"
319 #include "$libreplacedir/inet_ntop.c"
320 #include "$libreplacedir/snprintf.c"
321 #include "$libreplacedir/getifaddrs.c"
322 #define getifaddrs_test main
323 #include "$libreplacedir/test/getifaddrs.c"],
324 libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
325 if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
326 iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
330 if test $iface = no; then
331 AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
333 #define HAVE_IFACE_IFREQ 1
334 #define NO_CONFIG_H 1
335 #define AUTOCONF_TEST 1
336 #define SOCKET_WRAPPER_NOT_REPLACE
337 #include "$libreplacedir/replace.c"
338 #include "$libreplacedir/inet_ntop.c"
339 #include "$libreplacedir/snprintf.c"
340 #include "$libreplacedir/getifaddrs.c"
341 #define getifaddrs_test main
342 #include "$libreplacedir/test/getifaddrs.c"],
343 libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
344 if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
345 iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
350 AC_CACHE_CHECK([for ipv6 support],libreplace_cv_HAVE_IPV6,[
352 #include <stdlib.h> /* for NULL */
353 #include <sys/socket.h>
354 #include <sys/types.h>
358 struct sockaddr_storage sa_store;
359 struct addrinfo *ai = NULL;
360 struct in6_addr in6addr;
361 int idx = if_nametoindex("iface1");
362 int s = socket(AF_INET6, SOCK_STREAM, 0);
363 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
365 const char *es = gai_strerror(ret);
369 libreplace_cv_HAVE_IPV6=yes
371 libreplace_cv_HAVE_IPV6=no
374 if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then
375 AC_DEFINE(HAVE_IPV6,1,[Whether the system has IPv6 support])
379 CPPFLAGS="$SAVE_CPPFLAGS"
381 LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
383 echo "LIBREPLACE_NETWORK_CHECKS: END"
384 ]) dnl end AC_LIBREPLACE_NETWORK_CHECKS