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)
12 dnl we need to check that net/if.h really can be used, to cope with hpux
13 dnl where including it always fails
14 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
15 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
18 # include <sys/socket.h>
21 int main(void) {return 0;}])],
22 [libreplace_cv_USABLE_NET_IF_H=yes],
23 [libreplace_cv_USABLE_NET_IF_H=no]
26 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
27 AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
30 AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
31 AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
32 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
33 AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
34 AC_HAVE_TYPE([struct sockaddr_storage], [
35 #include <sys/socket.h>
36 #include <sys/types.h>
37 #include <netinet/in.h>
39 AC_HAVE_TYPE([struct sockaddr_in6], [
40 #include <sys/socket.h>
41 #include <sys/types.h>
42 #include <netinet/in.h>
45 if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
46 AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
47 AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
49 #include <sys/socket.h>
50 #include <sys/types.h>
51 #include <netinet/in.h>
54 if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
55 AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
56 AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
58 #include <sys/socket.h>
59 #include <sys/types.h>
60 #include <netinet/in.h>
65 AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
68 #include <sys/types.h>
69 #include <sys/socket.h>
70 #include <netinet/in.h>
72 struct sockaddr_in sock; sock.sin_len = sizeof(sock);
74 libreplace_cv_HAVE_SOCK_SIN_LEN=yes
76 libreplace_cv_HAVE_SOCK_SIN_LEN=no
79 if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then
80 AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
83 ############################################
84 # check for unix domain sockets
85 AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
87 #include <sys/types.h>
90 #include <sys/socket.h>
93 struct sockaddr_un sunaddr;
94 sunaddr.sun_family = AF_UNIX;
96 libreplace_cv_HAVE_UNIXSOCKET=yes
98 libreplace_cv_HAVE_UNIXSOCKET=no
101 if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
102 AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support])
105 dnl The following test is roughl taken from the cvs sources.
107 dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
108 dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
109 dnl libsocket.so which has a bad implementation of gethostbyname (it
110 dnl only looks in /etc/hosts), so we only look for -lsocket if we need
112 AC_CHECK_FUNCS(connect)
113 if test x"$ac_cv_func_connect" = x"no"; then
114 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect)
115 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect)
116 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect)
117 AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect)
118 dnl We can't just call AC_CHECK_FUNCS(connect) here,
119 dnl because the value has been cached.
120 if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
121 test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
122 test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
123 test x"$ac_cv_lib_ext_inet_connect" = x"yes"
125 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
129 AC_CHECK_FUNCS(gethostbyname)
130 if test x"$ac_cv_func_gethostbyname" = x"no"; then
131 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname)
132 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname)
133 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname)
134 dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
135 dnl because the value has been cached.
136 if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
137 test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
138 test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
140 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
141 [Whether the system has gethostbyname()])
145 dnl HP-UX has if_nametoindex in -lipv6
146 AC_CHECK_FUNCS(if_nametoindex)
147 if test x"$ac_cv_func_if_nametoindex" = x"no"; then
148 AC_CHECK_LIB_EXT(ipv6, LIBREPLACE_NETWORK_LIBS, if_nametoindex)
149 dnl We can't just call AC_CHECK_FUNCS(if_nametoindex) here,
150 dnl because the value has been cached.
151 if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes"
153 AC_DEFINE(HAVE_IF_NAMETOINDEX, 1,
154 [Whether the system has if_nametoindex()])
158 # The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
160 LIBS="${LIBREPLACE_NETWORK_LIBS}"
161 SAVE_CPPFLAGS="$CPPFLAGS"
162 CPPFLAGS="$CPPFLAGS -I$libreplacedir"
164 AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} socketpair.o"])
166 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
170 #include <sys/types.h>
171 #include <netinet/in.h>
172 #ifdef HAVE_ARPA_INET_H
173 #include <arpa/inet.h>
175 main() { struct in_addr ip; ip.s_addr = 0x12345678;
176 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
177 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
179 libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
181 AC_CHECK_FUNCS(inet_ntoa,[],[libreplace_cv_REPLACE_INET_NTOA=yes])
182 if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
183 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
184 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntoa.o"
187 AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_aton.o"])
189 AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntop.o"])
191 AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_pton.o"])
193 dnl test for getaddrinfo/getnameinfo
194 AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
196 #include <sys/types.h>
201 #include <sys/socket.h>
205 struct addrinfo *ai = NULL;
206 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
208 const char *es = gai_strerror(ret);
211 ret = getnameinfo(&sa, sizeof(sa),
216 libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)])
217 if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
218 AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo])
219 AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo])
220 AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
221 AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
223 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getaddrinfo.o"
226 AC_CHECK_HEADERS([ifaddrs.h])
228 dnl Used when getifaddrs is not available
229 AC_CHECK_MEMBERS([struct sockaddr.sa_len],
230 [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
232 [#include <sys/socket.h>])
234 dnl test for getifaddrs and freeifaddrs
235 AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
237 #include <sys/types.h>
242 #include <sys/socket.h>
243 #include <netinet/in.h>
244 #include <arpa/inet.h>
248 struct ifaddrs *ifp = NULL;
249 int ret = getifaddrs (&ifp);
252 libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
253 if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
254 AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
255 AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
256 AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
260 # look for a method of finding the list of network interfaces
262 AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
264 #define HAVE_IFACE_GETIFADDRS 1
265 #define NO_CONFIG_H 1
266 #define AUTOCONF_TEST 1
267 #define SOCKET_WRAPPER_NOT_REPLACE
268 #include "$libreplacedir/replace.c"
269 #include "$libreplacedir/inet_ntop.c"
270 #include "$libreplacedir/snprintf.c"
271 #include "$libreplacedir/getifaddrs.c"
272 #define getifaddrs_test main
273 #include "$libreplacedir/test/getifaddrs.c"],
274 libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
275 if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
276 iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
278 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getifaddrs.o"
282 if test $iface = no; then
283 AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
285 #define HAVE_IFACE_AIX 1
286 #define NO_CONFIG_H 1
287 #define AUTOCONF_TEST 1
288 #undef _XOPEN_SOURCE_EXTENDED
289 #define SOCKET_WRAPPER_NOT_REPLACE
290 #include "$libreplacedir/replace.c"
291 #include "$libreplacedir/inet_ntop.c"
292 #include "$libreplacedir/snprintf.c"
293 #include "$libreplacedir/getifaddrs.c"
294 #define getifaddrs_test main
295 #include "$libreplacedir/test/getifaddrs.c"],
296 libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
297 if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
298 iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
303 if test $iface = no; then
304 AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
306 #define HAVE_IFACE_IFCONF 1
307 #define NO_CONFIG_H 1
308 #define AUTOCONF_TEST 1
309 #define SOCKET_WRAPPER_NOT_REPLACE
310 #include "$libreplacedir/replace.c"
311 #include "$libreplacedir/inet_ntop.c"
312 #include "$libreplacedir/snprintf.c"
313 #include "$libreplacedir/getifaddrs.c"
314 #define getifaddrs_test main
315 #include "$libreplacedir/test/getifaddrs.c"],
316 libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
317 if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
318 iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
322 if test $iface = no; then
323 AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
325 #define HAVE_IFACE_IFREQ 1
326 #define NO_CONFIG_H 1
327 #define AUTOCONF_TEST 1
328 #define SOCKET_WRAPPER_NOT_REPLACE
329 #include "$libreplacedir/replace.c"
330 #include "$libreplacedir/inet_ntop.c"
331 #include "$libreplacedir/snprintf.c"
332 #include "$libreplacedir/getifaddrs.c"
333 #define getifaddrs_test main
334 #include "$libreplacedir/test/getifaddrs.c"],
335 libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
336 if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
337 iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
342 CPPFLAGS="$SAVE_CPPFLAGS"
344 LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
346 echo "LIBREPLACE_NETWORK_CHECKS: END"
347 ]) dnl end AC_LIBREPLACE_NETWORK_CHECKS