1 AC_DEFUN_ONCE(AC_LIBREPLACE_NETWORK_CHECKS,
3 echo "LIBREPLACE_NETWORK_CHECKS: START"
5 AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
6 AC_CHECK_HEADERS(netinet/ip.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
8 dnl we need to check that net/if.h really can be used, to cope with hpux
9 dnl where including it always fails
10 AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
11 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
14 # include <sys/socket.h>
17 int main(void) {return 0;}])],
18 [libreplace_cv_USABLE_NET_IF_H=yes],
19 [libreplace_cv_USABLE_NET_IF_H=no]
22 if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
23 AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
26 AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
27 AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
28 AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
29 AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
30 AC_HAVE_TYPE([struct sockaddr_storage], [
31 #include <sys/socket.h>
32 #include <sys/types.h>
33 #include <netinet/in.h>
35 AC_HAVE_TYPE([struct sockaddr_in6], [
36 #include <sys/socket.h>
37 #include <sys/types.h>
38 #include <netinet/in.h>
41 if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
42 AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
43 AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
45 #include <sys/socket.h>
46 #include <sys/types.h>
47 #include <netinet/in.h>
50 if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
51 AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
52 AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
54 #include <sys/socket.h>
55 #include <sys/types.h>
56 #include <netinet/in.h>
61 dnl The following test is roughl taken from the cvs sources.
63 dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
64 dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
65 dnl libsocket.so which has a bad implementation of gethostbyname (it
66 dnl only looks in /etc/hosts), so we only look for -lsocket if we need
68 AC_CHECK_FUNCS(connect)
69 if test x"$ac_cv_func_connect" = x"no"; then
70 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect)
71 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect)
72 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect)
73 AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect)
74 dnl We can't just call AC_CHECK_FUNCS(connect) here,
75 dnl because the value has been cached.
76 if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
77 test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
78 test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
79 test x"$ac_cv_lib_ext_inet_connect" = x"yes"
81 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
85 AC_CHECK_FUNCS(gethostbyname)
86 if test x"$ac_cv_func_gethostbyname" = x"no"; then
87 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname)
88 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname)
89 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname)
90 dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
91 dnl because the value has been cached.
92 if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
93 test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
94 test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
96 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
97 [Whether the system has gethostbyname()])
101 AC_CHECK_FUNCS(socketpair,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} socketpair.o"])
103 AC_CHECK_FUNCS(inet_ntoa,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} inet_ntoa.o"])
105 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
109 #include <sys/types.h>
110 #include <netinet/in.h>
111 #ifdef HAVE_ARPA_INET_H
112 #include <arpa/inet.h>
114 main() { struct in_addr ip; ip.s_addr = 0x12345678;
115 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
116 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
118 libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
119 if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
120 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
123 AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} inet_aton.o"])
125 AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} inet_ntop.o"])
127 AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} inet_pton.o"])
129 dnl test for getaddrinfo/getnameinfo
130 AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
132 #include <sys/types.h>
137 #include <sys/socket.h>
141 struct addrinfo *ai = NULL;
142 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
144 const char *es = gai_strerror(ret);
147 ret = getnameinfo(&sa, sizeof(sa),
152 libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)])
153 if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
154 AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo])
155 AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo])
156 AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
157 AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
159 LIBREPLACEOBJ="${LIBREPLACEOBJ} getaddrinfo.o"
162 AC_CHECK_HEADERS([ifaddrs.h])
164 dnl Used when getifaddrs is not available
165 AC_CHECK_MEMBERS([struct sockaddr.sa_len],
166 [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
168 [#include <sys/socket.h>])
170 dnl test for getifaddrs and freeifaddrs
171 AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
173 #include <sys/types.h>
178 #include <sys/socket.h>
179 #include <netinet/in.h>
180 #include <arpa/inet.h>
184 struct ifaddrs *ifp = NULL;
185 int ret = getifaddrs (&ifp);
188 libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
189 if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
190 AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
191 AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
192 AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
196 # look for a method of finding the list of network interfaces
198 # This tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
201 LIBS="${LIBREPLACE_NETWORK_LIBS}"
202 SAVE_CPPFLAGS="$CPPFLAGS"
203 CPPFLAGS="$CPPFLAGS -I$libreplacedir"
206 # look for a method of finding the list of network interfaces
208 AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
210 #define HAVE_IFACE_GETIFADDRS 1
211 #define NO_CONFIG_H 1
212 #define AUTOCONF_TEST 1
213 #define SOCKET_WRAPPER_NOT_REPLACE
214 #include "$libreplacedir/replace.c"
215 #include "$libreplacedir/inet_ntop.c"
216 #include "$libreplacedir/snprintf.c"
217 #include "$libreplacedir/getifaddrs.c"
218 #define getifaddrs_test main
219 #include "$libreplacedir/test/getifaddrs.c"],
220 libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
221 if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
222 iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
224 LIBREPLACEOBJ="${LIBREPLACEOBJ} getifaddrs.o"
228 if test $iface = no; then
229 AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
231 #define HAVE_IFACE_AIX 1
232 #define NO_CONFIG_H 1
233 #define AUTOCONF_TEST 1
234 #undef _XOPEN_SOURCE_EXTENDED
235 #define SOCKET_WRAPPER_NOT_REPLACE
236 #include "$libreplacedir/replace.c"
237 #include "$libreplacedir/inet_ntop.c"
238 #include "$libreplacedir/snprintf.c"
239 #include "$libreplacedir/getifaddrs.c"
240 #define getifaddrs_test main
241 #include "$libreplacedir/test/getifaddrs.c"],
242 libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
243 if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
244 iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
249 if test $iface = no; then
250 AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
252 #define HAVE_IFACE_IFCONF 1
253 #define NO_CONFIG_H 1
254 #define AUTOCONF_TEST 1
255 #define SOCKET_WRAPPER_NOT_REPLACE
256 #include "$libreplacedir/replace.c"
257 #include "$libreplacedir/inet_ntop.c"
258 #include "$libreplacedir/snprintf.c"
259 #include "$libreplacedir/getifaddrs.c"
260 #define getifaddrs_test main
261 #include "$libreplacedir/test/getifaddrs.c"],
262 libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
263 if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
264 iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
268 if test $iface = no; then
269 AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
271 #define HAVE_IFACE_IFREQ 1
272 #define NO_CONFIG_H 1
273 #define AUTOCONF_TEST 1
274 #define SOCKET_WRAPPER_NOT_REPLACE
275 #include "$libreplacedir/replace.c"
276 #include "$libreplacedir/inet_ntop.c"
277 #include "$libreplacedir/snprintf.c"
278 #include "$libreplacedir/getifaddrs.c"
279 #define getifaddrs_test main
280 #include "$libreplacedir/test/getifaddrs.c"],
281 libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
282 if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
283 iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
288 CPPFLAGS="$SAVE_CPPFLAGS"
290 echo "LIBREPLACE_NETWORK_CHECKS: END"
291 ]) dnl end AC_LIBREPLACE_NETWORK_CHECKS