5d36c195053839d83b298f8220b5210289ed5f68
[debian/amanda] / config / gnulib / getaddrinfo.m4
1 # getaddrinfo.m4 serial 15
2 dnl Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_GETADDRINFO],
8 [
9   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
10   AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
11
12   AC_CHECK_HEADERS_ONCE(netdb.h)
13
14   AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
15   AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
16     AC_TRY_LINK([
17 #include <sys/types.h>
18 #ifdef HAVE_SYS_SOCKET_H
19 #include <sys/socket.h>
20 #endif
21 #ifdef HAVE_NETDB_H
22 #include <netdb.h>
23 #endif
24 #include <stddef.h>
25 ], [getaddrinfo("", "", NULL, NULL);],
26       [gl_cv_func_getaddrinfo=yes],
27       [gl_cv_func_getaddrinfo=no])])
28   if test $gl_cv_func_getaddrinfo = no; then
29     AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32,
30                    gl_cv_w32_getaddrinfo, [
31       gl_cv_w32_getaddrinfo=no
32       am_save_LIBS="$LIBS"
33       LIBS="$LIBS -lws2_32"
34       AC_TRY_LINK([
35 #ifdef HAVE_WS2TCPIP_H
36 #include <ws2tcpip.h>
37 #endif
38 #include <stddef.h>
39 ], [getaddrinfo(NULL, NULL, NULL, NULL);], gl_cv_w32_getaddrinfo=yes)
40     LIBS="$am_save_LIBS"])
41     if test "$gl_cv_w32_getaddrinfo" = "yes"; then
42       LIBS="$LIBS -lws2_32"
43     else
44       AC_LIBOBJ(getaddrinfo)
45     fi
46   fi
47
48   # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
49   # inline function declared in ws2tcpip.h, so we need to get that
50   # header included somehow.
51   AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)],
52     gl_cv_func_gai_strerror, [
53       AC_TRY_LINK([
54 #include <sys/types.h>
55 #ifdef HAVE_SYS_SOCKET_H
56 #include <sys/socket.h>
57 #endif
58 #ifdef HAVE_NETDB_H
59 #include <netdb.h>
60 #endif
61 #ifdef HAVE_WS2TCPIP_H
62 #include <ws2tcpip.h>
63 #endif
64 #include <stddef.h>
65 ], [gai_strerror (NULL);],
66         [gl_cv_func_gai_strerror=yes],
67         [gl_cv_func_gai_strerror=no])])
68   if test $gl_cv_func_gai_strerror = no; then
69     AC_LIBOBJ(gai_strerror)
70   fi
71
72   gl_PREREQ_GETADDRINFO
73 ])
74
75 # Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
76 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
77   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
78   AC_SEARCH_LIBS(gethostbyname, [inet nsl])
79   AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
80   AC_CHECK_FUNCS(gethostbyname,, [
81     AC_CACHE_CHECK(for gethostbyname in winsock2.h and -lws2_32,
82                    gl_cv_w32_gethostbyname, [
83       gl_cv_w32_gethostbyname=no
84       am_save_LIBS="$LIBS"
85       LIBS="$LIBS -lws2_32"
86       AC_TRY_LINK([
87 #ifdef HAVE_WINSOCK2_H
88 #include <winsock2.h>
89 #endif
90 #include <stddef.h>
91 ], [gethostbyname(NULL);], gl_cv_w32_gethostbyname=yes)
92     LIBS="$am_save_LIBS"])
93     if test "$gl_cv_w32_gethostbyname" = "yes"; then
94       LIBS="$LIBS -lws2_32"
95     fi
96     ])
97   AC_REQUIRE([AC_C_RESTRICT])
98   AC_REQUIRE([gl_SOCKET_FAMILIES])
99   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
100   AC_REQUIRE([AC_C_INLINE])
101   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
102   AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h)
103   AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
104   /* sys/types.h is not needed according to POSIX, but the
105      sys/socket.h in i386-unknown-freebsd4.10 and
106      powerpc-apple-darwin5.5 required it. */
107 #include <sys/types.h>
108 #ifdef HAVE_SYS_SOCKET_H
109 #include <sys/socket.h>
110 #endif
111 #ifdef HAVE_NETDB_H
112 #include <netdb.h>
113 #endif
114 #ifdef HAVE_WS2TCPIP_H
115 #include <ws2tcpip.h>
116 #endif
117 ])
118   AC_CHECK_TYPES([struct addrinfo],,,[
119 #include <sys/types.h>
120 #ifdef HAVE_SYS_SOCKET_H
121 #include <sys/socket.h>
122 #endif
123 #ifdef HAVE_NETDB_H
124 #include <netdb.h>
125 #endif
126 #ifdef HAVE_WS2TCPIP_H
127 #include <ws2tcpip.h>
128 #endif
129 ])
130 ])