libreplace: merge inet_ntoa.m4 into libreplace_network.m4
[Samba.git] / source / lib / replace / libreplace_network.m4
blob35aa3ede7ca3f947593e2804c543cd1ba495758c
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([
12                 AC_INCLUDES_DEFAULT
13                 #if HAVE_SYS_SOCKET_H
14                 # include <sys/socket.h>
15                 #endif
16                 #include <net/if.h>
17                 int main(void) {return 0;}])],
18                 [libreplace_cv_USABLE_NET_IF_H=yes],
19                 [libreplace_cv_USABLE_NET_IF_H=no]
20         )
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]),,
44                 [
45 #include <sys/socket.h>
46 #include <sys/types.h>
47 #include <netinet/in.h>
48                 ])
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]),,
53                 [
54 #include <sys/socket.h>
55 #include <sys/types.h>
56 #include <netinet/in.h>
57                 ])
61 dnl The following test is roughl taken from the cvs sources.
62 dnl
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
67 dnl it.
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"
80         then
81                 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
82         fi
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"
95         then
96                 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
97                           [Whether the system has gethostbyname()])
98         fi
101 AC_CHECK_FUNCS(inet_ntoa,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} inet_ntoa.o"])
103 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
104 AC_TRY_RUN([
105 #include <stdio.h>
106 #include <unistd.h>
107 #include <sys/types.h>
108 #include <netinet/in.h>
109 #ifdef HAVE_ARPA_INET_H
110 #include <arpa/inet.h>
111 #endif
112 main() { struct in_addr ip; ip.s_addr = 0x12345678;
113 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
114     strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
115 exit(1);}],
116            libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
117 if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
118     AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
121 m4_include(inet_ntop.m4)
122 m4_include(inet_pton.m4)
123 m4_include(inet_aton.m4)
124 m4_include(getaddrinfo.m4)
125 m4_include(getifaddrs.m4)
126 m4_include(socketpair.m4)
128 echo "LIBREPLACE_NETWORK_CHECKS: END"
129 ]) dnl end AC_LIBREPLACE_NETWORK_CHECKS