d29c13196dcce145d112dfbf68be77709020cee5
[ira/wip.git] / source3 / lib / replace / libreplace_network.m4
1 AC_DEFUN_ONCE(AC_LIBREPLACE_NETWORK_CHECKS,
2 [
3 echo "LIBREPLACE_NETWORK_CHECKS: START"
4
5 AC_DEFINE(LIBREPLACE_NETWORK_CHECKS, 1, [LIBREPLACE_NETWORK_CHECKS were used])
6 LIBREPLACE_NETWORK_OBJS=""
7 LIBREPLACE_NETWORK_LIBS=""
8
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)
11
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([
16                 AC_INCLUDES_DEFAULT
17                 #if HAVE_SYS_SOCKET_H
18                 # include <sys/socket.h>
19                 #endif
20                 #include <net/if.h>
21                 int main(void) {return 0;}])],
22                 [libreplace_cv_USABLE_NET_IF_H=yes],
23                 [libreplace_cv_USABLE_NET_IF_H=no]
24         )
25 ])
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)
28 fi
29
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>
38 ])
39 AC_HAVE_TYPE([struct sockaddr_in6], [
40 #include <sys/socket.h>
41 #include <sys/types.h>
42 #include <netinet/in.h>
43 ])
44
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]),,
48                 [
49 #include <sys/socket.h>
50 #include <sys/types.h>
51 #include <netinet/in.h>
52                 ])
53
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]),,
57                 [
58 #include <sys/socket.h>
59 #include <sys/types.h>
60 #include <netinet/in.h>
61                 ])
62 fi
63 fi
64
65 AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
66         AC_TRY_COMPILE(
67                 [
68 #include <sys/types.h>
69 #include <sys/socket.h>
70 #include <netinet/in.h>
71                 ],[
72 struct sockaddr_in sock; sock.sin_len = sizeof(sock);
73                 ],[
74                 libreplace_cv_HAVE_SOCK_SIN_LEN=yes
75                 ],[
76                 libreplace_cv_HAVE_SOCK_SIN_LEN=no
77                 ])
78 ])
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])
81 fi
82
83 ############################################
84 # check for unix domain sockets
85 AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
86         AC_TRY_COMPILE([
87 #include <sys/types.h>
88 #include <stdlib.h>
89 #include <stddef.h>
90 #include <sys/socket.h>
91 #include <sys/un.h>
92                 ],[
93 struct sockaddr_un sunaddr;
94 sunaddr.sun_family = AF_UNIX;
95                 ],[
96                 libreplace_cv_HAVE_UNIXSOCKET=yes
97                 ],[
98                 libreplace_cv_HAVE_UNIXSOCKET=no
99                 ])
100 ])
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])
103 fi
104
105 dnl The following test is roughl taken from the cvs sources.
106 dnl
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
111 dnl it.
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"
124         then
125                 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
126         fi
127 fi
128
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"
139         then
140                 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
141                           [Whether the system has gethostbyname()])
142         fi
143 fi
144
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"
152         then
153                 AC_DEFINE(HAVE_IF_NAMETOINDEX, 1,
154                           [Whether the system has if_nametoindex()])
155         fi
156 fi
157
158 # The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
159 old_LIBS=$LIBS
160 LIBS="${LIBREPLACE_NETWORK_LIBS}"
161 SAVE_CPPFLAGS="$CPPFLAGS"
162 CPPFLAGS="$CPPFLAGS -I$libreplacedir"
163
164 AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} socketpair.o"])
165
166 AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
167 AC_TRY_RUN([
168 #include <stdio.h>
169 #include <unistd.h>
170 #include <sys/types.h>
171 #include <netinet/in.h>
172 #ifdef HAVE_ARPA_INET_H
173 #include <arpa/inet.h>
174 #endif
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); }
178 exit(1);}],
179            libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
180
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"
185 fi
186
187 AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_aton.o"])
188
189 AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_ntop.o"])
190
191 AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} inet_pton.o"])
192
193 dnl test for getaddrinfo/getnameinfo
194 AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
195 AC_TRY_LINK([
196 #include <sys/types.h>
197 #if STDC_HEADERS
198 #include <stdlib.h>
199 #include <stddef.h>
200 #endif
201 #include <sys/socket.h>
202 #include <netdb.h>],
203 [
204 struct sockaddr sa;
205 struct addrinfo *ai = NULL;
206 int ret = getaddrinfo(NULL, NULL, NULL, &ai);
207 if (ret != 0) {
208         const char *es = gai_strerror(ret);
209 }
210 freeaddrinfo(ai);
211 ret = getnameinfo(&sa, sizeof(sa),
212                 NULL, 0,
213                 NULL, 0, 0);
214
215 ],
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])
222 else
223         LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getaddrinfo.o"
224 fi
225
226 AC_CHECK_HEADERS([ifaddrs.h])
227
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])],
231          [],
232          [#include <sys/socket.h>])
233
234 dnl test for getifaddrs and freeifaddrs
235 AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
236 AC_TRY_COMPILE([
237 #include <sys/types.h>
238 #if STDC_HEADERS
239 #include <stdlib.h>
240 #include <stddef.h>
241 #endif
242 #include <sys/socket.h>
243 #include <netinet/in.h>
244 #include <arpa/inet.h>
245 #include <ifaddrs.h>
246 #include <netdb.h>],
247 [
248 struct ifaddrs *ifp = NULL;
249 int ret = getifaddrs (&ifp);
250 freeifaddrs(ifp);
251 ],
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])
257 fi
258
259 ##################
260 # look for a method of finding the list of network interfaces
261 iface=no;
262 AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
263 AC_TRY_RUN([
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])
277 else
278         LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} getifaddrs.o"
279 fi
280
281
282 if test $iface = no; then
283 AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
284 AC_TRY_RUN([
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])
299 fi
300 fi
301
302
303 if test $iface = no; then
304 AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
305 AC_TRY_RUN([
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])
319 fi
320 fi
321
322 if test $iface = no; then
323 AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
324 AC_TRY_RUN([
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])
338 fi
339 fi
340
341 LIBS=$old_LIBS
342 CPPFLAGS="$SAVE_CPPFLAGS"
343
344 LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
345
346 echo "LIBREPLACE_NETWORK_CHECKS: END"
347 ]) dnl end AC_LIBREPLACE_NETWORK_CHECKS