7be1e490ae68f96f83577a745404abce79a1b408
[debian/amanda] / config / gnulib / getaddrinfo.m4
1 # getaddrinfo.m4 serial 13
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_SEARCH_LIBS(getaddrinfo, [nsl socket])
13   AC_CHECK_FUNCS(getaddrinfo,, [
14     AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32,
15                    gl_cv_w32_getaddrinfo, [
16       gl_cv_w32_getaddrinfo=no
17       am_save_LIBS="$LIBS"
18       LIBS="$LIBS -lws2_32"
19       AC_TRY_LINK([
20 #ifdef HAVE_WS2TCPIP_H
21 #include <ws2tcpip.h>
22 #endif
23 ], [getaddrinfo(0, 0, 0, 0);], gl_cv_w32_getaddrinfo=yes)
24     LIBS="$am_save_LIBS"])
25     if test "$gl_cv_w32_getaddrinfo" = "yes"; then
26       LIBS="$LIBS -lws2_32"
27     else
28       AC_LIBOBJ(getaddrinfo)
29     fi
30     ])
31
32   # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
33   # inline function declared in ws2tcpip.h, so we need to get that
34   # header included somehow.
35   AC_CHECK_HEADERS_ONCE(netdb.h)
36   AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)],
37     gl_cv_func_gai_strerror, [
38       AC_TRY_LINK([
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 #include <sys/socket.h>
42 #endif
43 #ifdef HAVE_NETDB_H
44 #include <netdb.h>
45 #endif
46 #ifdef HAVE_WS2TCPIP_H
47 #include <ws2tcpip.h>
48 #endif
49 ], [gai_strerror (0);],
50         [gl_cv_func_gai_strerror=yes],
51         [gl_cv_func_gai_strerror=no])])
52   if test $gl_cv_func_gai_strerror = no; then
53     AC_LIBOBJ(gai_strerror)
54   fi
55
56   gl_PREREQ_GETADDRINFO
57 ])
58
59 # Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
60 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
61   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
62   AC_SEARCH_LIBS(gethostbyname, [inet nsl])
63   AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
64   AC_CHECK_FUNCS(gethostbyname,, [
65     AC_CACHE_CHECK(for gethostbyname in winsock2.h and -lws2_32,
66                    gl_cv_w32_gethostbyname, [
67       gl_cv_w32_gethostbyname=no
68       am_save_LIBS="$LIBS"
69       LIBS="$LIBS -lws2_32"
70       AC_TRY_LINK([
71 #ifdef HAVE_WINSOCK2_H
72 #include <winsock2.h>
73 #endif
74 ], [gethostbyname(0);], gl_cv_w32_gethostbyname=yes)
75     LIBS="$am_save_LIBS"])
76     if test "$gl_cv_w32_gethostbyname" = "yes"; then
77       LIBS="$LIBS -lws2_32"
78     fi
79     ])
80   AC_REQUIRE([AC_C_RESTRICT])
81   AC_REQUIRE([gl_SOCKET_FAMILIES])
82   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
83   AC_REQUIRE([AC_C_INLINE])
84   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
85   AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h)
86   AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
87   /* sys/types.h is not needed according to POSIX, but the
88      sys/socket.h in i386-unknown-freebsd4.10 and
89      powerpc-apple-darwin5.5 required it. */
90 #include <sys/types.h>
91 #ifdef HAVE_SYS_SOCKET_H
92 #include <sys/socket.h>
93 #endif
94 #ifdef HAVE_NETDB_H
95 #include <netdb.h>
96 #endif
97 #ifdef HAVE_WS2TCPIP_H
98 #include <ws2tcpip.h>
99 #endif
100 ])
101   AC_CHECK_TYPES([struct addrinfo],,,[
102 #include <sys/types.h>
103 #ifdef HAVE_SYS_SOCKET_H
104 #include <sys/socket.h>
105 #endif
106 #ifdef HAVE_NETDB_H
107 #include <netdb.h>
108 #endif
109 #ifdef HAVE_WS2TCPIP_H
110 #include <ws2tcpip.h>
111 #endif
112 ])
113 ])