source: branches/samba-3.5.x/lib/replace/libreplace_network.m4

Last change on this file was 480, checked in by Silvan Scherrer, 15 years ago

Samba Server 3.5: trunk update to 3.5.4

File size: 14.2 KB
Line 
1AC_DEFUN_ONCE(AC_LIBREPLACE_NETWORK_CHECKS,
2[
3echo "LIBREPLACE_NETWORK_CHECKS: START"
4
5AC_DEFINE(LIBREPLACE_NETWORK_CHECKS, 1, [LIBREPLACE_NETWORK_CHECKS were used])
6LIBREPLACE_NETWORK_OBJS=""
7LIBREPLACE_NETWORK_LIBS=""
8
9AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
10AC_CHECK_HEADERS(netinet/in_systm.h)
11AC_CHECK_HEADERS([netinet/ip.h], [], [],[
12 #include <sys/types.h>
13 #ifdef HAVE_NETINET_IN_H
14 #include <netinet/in.h>
15 #endif
16 #ifdef HAVE_NETINET_IN_SYSTM_H
17 #include <netinet/in_systm.h>
18 #endif
19])
20AC_CHECK_HEADERS(netinet/tcp.h netinet/in_ip.h)
21AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
22AC_CHECK_HEADERS(sys/uio.h)
23
24dnl we need to check that net/if.h really can be used, to cope with hpux
25dnl where including it always fails
26AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
27 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
28 AC_INCLUDES_DEFAULT
29 #if HAVE_SYS_SOCKET_H
30 # include <sys/socket.h>
31 #endif
32 #include <net/if.h>
33 int main(void) {return 0;}])],
34 [libreplace_cv_USABLE_NET_IF_H=yes],
35 [libreplace_cv_USABLE_NET_IF_H=no]
36 )
37])
38if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
39 AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
40fi
41
42AC_HAVE_TYPE([socklen_t],[#include <sys/socket.h>])
43AC_HAVE_TYPE([sa_family_t],[#include <sys/socket.h>])
44AC_HAVE_TYPE([struct addrinfo], [#include <netdb.h>])
45AC_HAVE_TYPE([struct sockaddr], [#include <sys/socket.h>])
46AC_HAVE_TYPE([struct sockaddr_storage], [
47#include <sys/socket.h>
48#include <sys/types.h>
49#include <netinet/in.h>
50])
51AC_HAVE_TYPE([struct sockaddr_in6], [
52#include <sys/socket.h>
53#include <sys/types.h>
54#include <netinet/in.h>
55])
56
57if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then
58AC_CHECK_MEMBER(struct sockaddr_storage.ss_family,
59 AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),,
60 [
61#include <sys/socket.h>
62#include <sys/types.h>
63#include <netinet/in.h>
64 ])
65
66if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then
67AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family,
68 AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),,
69 [
70#include <sys/socket.h>
71#include <sys/types.h>
72#include <netinet/in.h>
73 ])
74fi
75fi
76
77AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[
78 AC_TRY_COMPILE(
79 [
80#include <sys/types.h>
81#include <sys/socket.h>
82#include <netinet/in.h>
83 ],[
84struct sockaddr_in sock; sock.sin_len = sizeof(sock);
85 ],[
86 libreplace_cv_HAVE_SOCK_SIN_LEN=yes
87 ],[
88 libreplace_cv_HAVE_SOCK_SIN_LEN=no
89 ])
90])
91if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then
92 AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property])
93fi
94
95############################################
96# check for unix domain sockets
97AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[
98 AC_TRY_COMPILE([
99#include <sys/types.h>
100#include <stdlib.h>
101#include <stddef.h>
102#include <sys/socket.h>
103#include <sys/un.h>
104 ],[
105struct sockaddr_un sunaddr;
106sunaddr.sun_family = AF_UNIX;
107 ],[
108 libreplace_cv_HAVE_UNIXSOCKET=yes
109 ],[
110 libreplace_cv_HAVE_UNIXSOCKET=no
111 ])
112])
113if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
114 AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support])
115fi
116
117dnl The following test is roughl taken from the cvs sources.
118dnl
119dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
120dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
121dnl libsocket.so which has a bad implementation of gethostbyname (it
122dnl only looks in /etc/hosts), so we only look for -lsocket if we need
123dnl it.
124AC_CHECK_FUNCS(connect)
125if test x"$ac_cv_func_connect" = x"no"; then
126 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect)
127 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect)
128 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect)
129 AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect)
130 dnl We can't just call AC_CHECK_FUNCS(connect) here,
131 dnl because the value has been cached.
132 if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
133 test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
134 test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
135 test x"$ac_cv_lib_ext_inet_connect" = x"yes"
136 then
137 AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
138 fi
139fi
140
141AC_CHECK_FUNCS(gethostbyname)
142if test x"$ac_cv_func_gethostbyname" = x"no"; then
143 AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname)
144 AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname)
145 AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname)
146 dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
147 dnl because the value has been cached.
148 if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
149 test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
150 test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
151 then
152 AC_DEFINE(HAVE_GETHOSTBYNAME,1,
153 [Whether the system has gethostbyname()])
154 fi
155fi
156
157dnl HP-UX has if_nametoindex in -lipv6
158AC_CHECK_FUNCS(if_nametoindex)
159if test x"$ac_cv_func_if_nametoindex" = x"no"; then
160 AC_CHECK_LIB_EXT(ipv6, LIBREPLACE_NETWORK_LIBS, if_nametoindex)
161 dnl We can't just call AC_CHECK_FUNCS(if_nametoindex) here,
162 dnl because the value has been cached.
163 if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes"
164 then
165 AC_DEFINE(HAVE_IF_NAMETOINDEX, 1,
166 [Whether the system has if_nametoindex()])
167 fi
168fi
169
170# The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
171old_LIBS=$LIBS
172LIBS="${LIBREPLACE_NETWORK_LIBS}"
173libreplace_SAVE_CPPFLAGS="$CPPFLAGS"
174CPPFLAGS="$CPPFLAGS -I$libreplacedir"
175
176AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/socketpair.o"])
177
178AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
179AC_TRY_RUN([
180#include <stdio.h>
181#include <unistd.h>
182#include <sys/types.h>
183#include <netinet/in.h>
184#ifdef HAVE_ARPA_INET_H
185#include <arpa/inet.h>
186#endif
187main() { struct in_addr ip; ip.s_addr = 0x12345678;
188if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
189 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
190exit(1);}],
191 libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
192
193AC_CHECK_FUNCS(inet_ntoa,[],[libreplace_cv_REPLACE_INET_NTOA=yes])
194if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
195 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
196 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntoa.o"
197fi
198
199AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_aton.o"])
200
201AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntop.o"])
202
203AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_pton.o"])
204
205dnl test for getaddrinfo/getnameinfo
206AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[
207AC_TRY_LINK([
208#include <sys/types.h>
209#if STDC_HEADERS
210#include <stdlib.h>
211#include <stddef.h>
212#endif
213#include <sys/socket.h>
214#include <netdb.h>],
215[
216struct sockaddr sa;
217struct addrinfo *ai = NULL;
218int ret = getaddrinfo(NULL, NULL, NULL, &ai);
219if (ret != 0) {
220 const char *es = gai_strerror(ret);
221}
222freeaddrinfo(ai);
223ret = getnameinfo(&sa, sizeof(sa),
224 NULL, 0,
225 NULL, 0, 0);
226
227],
228libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)])
229if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then
230 AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo])
231 AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo])
232 AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo])
233 AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror])
234else
235 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getaddrinfo.o"
236fi
237
238AC_CHECK_HEADERS([ifaddrs.h])
239
240dnl Used when getifaddrs is not available
241AC_CHECK_MEMBERS([struct sockaddr.sa_len],
242 [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
243 [],
244 [#include <sys/socket.h>])
245
246dnl test for getifaddrs and freeifaddrs
247AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
248AC_TRY_LINK([
249#include <sys/types.h>
250#if STDC_HEADERS
251#include <stdlib.h>
252#include <stddef.h>
253#endif
254#include <sys/socket.h>
255#include <netinet/in.h>
256#include <arpa/inet.h>
257#include <ifaddrs.h>
258#include <netdb.h>],
259[
260struct ifaddrs *ifp = NULL;
261int ret = getifaddrs (&ifp);
262freeifaddrs(ifp);
263],
264libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
265if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
266 AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
267 AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
268 AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
269fi
270
271##################
272# look for a method of finding the list of network interfaces
273iface=no;
274AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
275AC_TRY_RUN([
276#define HAVE_IFACE_GETIFADDRS 1
277#define NO_CONFIG_H 1
278#define AUTOCONF_TEST 1
279#define SOCKET_WRAPPER_NOT_REPLACE
280#include "$libreplacedir/replace.c"
281#include "$libreplacedir/inet_ntop.c"
282#include "$libreplacedir/snprintf.c"
283#include "$libreplacedir/getifaddrs.c"
284#define getifaddrs_test main
285#include "$libreplacedir/test/getifaddrs.c"],
286 libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
287if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
288 iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
289else
290 LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getifaddrs.o"
291fi
292
293
294if test $iface = no; then
295AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
296AC_TRY_RUN([
297#define HAVE_IFACE_AIX 1
298#define NO_CONFIG_H 1
299#define AUTOCONF_TEST 1
300#undef _XOPEN_SOURCE_EXTENDED
301#define SOCKET_WRAPPER_NOT_REPLACE
302#include "$libreplacedir/replace.c"
303#include "$libreplacedir/inet_ntop.c"
304#include "$libreplacedir/snprintf.c"
305#include "$libreplacedir/getifaddrs.c"
306#define getifaddrs_test main
307#include "$libreplacedir/test/getifaddrs.c"],
308 libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
309if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
310 iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
311fi
312fi
313
314
315if test $iface = no; then
316AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
317AC_TRY_RUN([
318#define HAVE_IFACE_IFCONF 1
319#define NO_CONFIG_H 1
320#define AUTOCONF_TEST 1
321#define SOCKET_WRAPPER_NOT_REPLACE
322#include "$libreplacedir/replace.c"
323#include "$libreplacedir/inet_ntop.c"
324#include "$libreplacedir/snprintf.c"
325#include "$libreplacedir/getifaddrs.c"
326#define getifaddrs_test main
327#include "$libreplacedir/test/getifaddrs.c"],
328 libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
329if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
330 iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
331fi
332fi
333
334if test $iface = no; then
335AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
336AC_TRY_RUN([
337#define HAVE_IFACE_IFREQ 1
338#define NO_CONFIG_H 1
339#define AUTOCONF_TEST 1
340#define SOCKET_WRAPPER_NOT_REPLACE
341#include "$libreplacedir/replace.c"
342#include "$libreplacedir/inet_ntop.c"
343#include "$libreplacedir/snprintf.c"
344#include "$libreplacedir/getifaddrs.c"
345#define getifaddrs_test main
346#include "$libreplacedir/test/getifaddrs.c"],
347 libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
348if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
349 iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
350fi
351fi
352
353dnl Some old Linux systems have broken header files and
354dnl miss the IPV6_V6ONLY define in netinet/in.h,
355dnl but have it in linux/in6.h.
356dnl We can't include both files so we just check if the value
357dnl if defined and do the replacement in system/network.h
358AC_CACHE_CHECK([for IPV6_V6ONLY support],libreplace_cv_HAVE_IPV6_V6ONLY,[
359 AC_TRY_COMPILE([
360#include <stdlib.h> /* for NULL */
361#include <sys/socket.h>
362#include <sys/types.h>
363#include <netdb.h>
364#include <netinet/in.h>
365 ],
366 [
367#ifndef IPV6_V6ONLY
368#error no IPV6_V6ONLY
369#endif
370 ],[
371 libreplace_cv_HAVE_IPV6_V6ONLY=yes
372 ],[
373 libreplace_cv_HAVE_IPV6_V6ONLY=no
374 ])
375])
376if test x"$libreplace_cv_HAVE_IPV6_V6ONLY" != x"yes"; then
377 dnl test for IPV6_V6ONLY
378 AC_CACHE_CHECK([for IPV6_V6ONLY in linux/in6.h],libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26,[
379 AC_TRY_COMPILE([
380 #include <linux/in6.h>
381 ],
382 [
383 #if (IPV6_V6ONLY != 26)
384 #error no linux IPV6_V6ONLY
385 #endif
386 ],[
387 libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26=yes
388 ],[
389 libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26=no
390 ])
391 ])
392 if test x"$libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26" = x"yes"; then
393 AC_DEFINE(HAVE_LINUX_IPV6_V6ONLY_26,1,[Whether the system has IPV6_V6ONLY in linux/in6.h])
394 fi
395fi
396
397dnl test for ipv6
398AC_CACHE_CHECK([for ipv6 support],libreplace_cv_HAVE_IPV6,[
399 AC_TRY_LINK([
400#include <stdlib.h> /* for NULL */
401#include <sys/socket.h>
402#include <sys/types.h>
403#include <netdb.h>
404#include <netinet/in.h>
405 ],
406 [
407struct sockaddr_storage sa_store;
408struct addrinfo *ai = NULL;
409struct in6_addr in6addr;
410int idx = if_nametoindex("iface1");
411int s = socket(AF_INET6, SOCK_STREAM, 0);
412int ret = getaddrinfo(NULL, NULL, NULL, &ai);
413if (ret != 0) {
414 const char *es = gai_strerror(ret);
415}
416freeaddrinfo(ai);
417{
418 int val = 1;
419 #ifdef HAVE_LINUX_IPV6_V6ONLY_26
420 #define IPV6_V6ONLY 26
421 #endif
422 ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
423 (const void *)&val, sizeof(val));
424}
425 ],[
426 libreplace_cv_HAVE_IPV6=yes
427 ],[
428 libreplace_cv_HAVE_IPV6=no
429 ])
430])
431if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then
432 AC_DEFINE(HAVE_IPV6,1,[Whether the system has IPv6 support])
433fi
434
435LIBS=$old_LIBS
436CPPFLAGS="$libreplace_SAVE_CPPFLAGS"
437
438LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
439
440echo "LIBREPLACE_NETWORK_CHECKS: END"
441]) dnl end AC_LIBREPLACE_NETWORK_CHECKS
Note: See TracBrowser for help on using the repository browser.