getaddrinfo: fix sh typo in gai_strerrorA decl checking
[gnulib.git] / m4 / getaddrinfo.m4
1 # getaddrinfo.m4 serial 28
2 dnl Copyright (C) 2004-2011 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_REQUIRE([gl_HEADER_NETDB])dnl for HAVE_NETDB_H
11   AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
12   GETADDRINFO_LIB=
13   gai_saved_LIBS="$LIBS"
14
15   dnl Where is getaddrinfo()?
16   dnl - On Solaris, it is in libsocket.
17   dnl - On Haiku, it is in libnetwork.
18   dnl - On BeOS, it is in libnet.
19   dnl - On native Windows, it is in ws2_32.dll.
20   dnl - Otherwise it is in libc.
21   AC_SEARCH_LIBS([getaddrinfo], [socket network net],
22     [if test "$ac_cv_search_getaddrinfo" != "none required"; then
23        GETADDRINFO_LIB="$ac_cv_search_getaddrinfo"
24      fi])
25   LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
26
27   HAVE_GETADDRINFO=1
28   AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
29     AC_LINK_IFELSE([AC_LANG_PROGRAM([[
30 #include <sys/types.h>
31 #ifdef HAVE_SYS_SOCKET_H
32 #include <sys/socket.h>
33 #endif
34 #ifdef HAVE_NETDB_H
35 #include <netdb.h>
36 #endif
37 #include <stddef.h>
38 ]], [[getaddrinfo("", "", NULL, NULL);]])],
39       [gl_cv_func_getaddrinfo=yes],
40       [gl_cv_func_getaddrinfo=no])])
41   if test $gl_cv_func_getaddrinfo = no; then
42     AC_CACHE_CHECK([for getaddrinfo in ws2tcpip.h and -lws2_32],
43                    gl_cv_w32_getaddrinfo, [
44       gl_cv_w32_getaddrinfo=no
45       am_save_LIBS="$LIBS"
46       LIBS="$LIBS -lws2_32"
47       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
48 #ifdef HAVE_WS2TCPIP_H
49 #include <ws2tcpip.h>
50 #endif
51 #include <stddef.h>
52 ]], [[getaddrinfo(NULL, NULL, NULL, NULL);]])], [gl_cv_w32_getaddrinfo=yes])
53       LIBS="$am_save_LIBS"
54     ])
55     if test "$gl_cv_w32_getaddrinfo" = "yes"; then
56       GETADDRINFO_LIB="-lws2_32"
57       LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
58     else
59       HAVE_GETADDRINFO=0
60     fi
61   fi
62
63   # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
64   # inline function declared in ws2tcpip.h, so we need to get that
65   # header included somehow.
66   AC_CHECK_DECLS([gai_strerror], [], [], [[
67 #include <sys/types.h>
68 #ifdef HAVE_SYS_SOCKET_H
69 #include <sys/socket.h>
70 #endif
71 #ifdef HAVE_NETDB_H
72 #include <netdb.h>
73 #endif
74 #ifdef HAVE_WS2TCPIP_H
75 #include <ws2tcpip.h>
76 #endif
77 #include <stddef.h>
78 ]])
79   if test $ac_cv_have_decl_gai_strerror = yes; then
80     AC_CHECK_DECLS([gai_strerrorA], [], [], [[
81 #include <sys/types.h>
82 #ifdef HAVE_SYS_SOCKET_H
83 #include <sys/socket.h>
84 #endif
85 #ifdef HAVE_NETDB_H
86 #include <netdb.h>
87 #endif
88 #ifdef HAVE_WS2TCPIP_H
89 #include <ws2tcpip.h>
90 #endif
91 #include <stddef.h>
92 ]])
93     dnl check for correct signature
94     AC_CACHE_CHECK([for gai_strerror with POSIX signature],
95      [gl_cv_func_gai_strerror_posix_signature], [
96       AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
97 #include <sys/types.h>
98 #ifdef HAVE_SYS_SOCKET_H
99 #include <sys/socket.h>
100 #endif
101 #ifdef HAVE_NETDB_H
102 #include <netdb.h>
103 #endif
104 #ifdef HAVE_WS2TCPIP_H
105 #include <ws2tcpip.h>
106 #endif
107 #include <stddef.h>
108 extern
109 #ifdef __cplusplus
110 "C"
111 #endif
112 const char *gai_strerror(int);]])],
113         [gl_cv_func_gai_strerror_posix_signature=yes],
114         [gl_cv_func_gai_strerror_posix_signature=no])])
115     if test $gl_cv_func_gai_strerror_posix_signature = no; then
116       REPLACE_GAI_STRERROR=1
117     fi
118   fi
119
120   LIBS="$gai_saved_LIBS"
121
122   gl_PREREQ_GETADDRINFO
123
124   AC_SUBST([GETADDRINFO_LIB])
125 ])
126
127 # Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c.
128 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
129   AC_REQUIRE([gl_NETDB_H_DEFAULTS])
130   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
131   AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB
132   AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB
133   AC_REQUIRE([gl_FUNC_INET_NTOP]) dnl for INET_NTOP_LIB
134   AC_REQUIRE([AC_C_RESTRICT])
135   AC_REQUIRE([gl_SOCKET_FAMILIES])
136   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
137   AC_REQUIRE([AC_C_INLINE])
138   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
139
140   dnl Including sys/socket.h is wrong for Windows, but Windows does not
141   dnl have sa_len so the result is correct anyway.
142   AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [
143 #include <sys/types.h>
144 #include <sys/socket.h>
145 ])
146
147   AC_CHECK_HEADERS_ONCE([netinet/in.h])
148
149   AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, getnameinfo],,,[
150   /* sys/types.h is not needed according to POSIX, but the
151      sys/socket.h in i386-unknown-freebsd4.10 and
152      powerpc-apple-darwin5.5 required it. */
153 #include <sys/types.h>
154 #ifdef HAVE_SYS_SOCKET_H
155 #include <sys/socket.h>
156 #endif
157 #ifdef HAVE_NETDB_H
158 #include <netdb.h>
159 #endif
160 #ifdef HAVE_WS2TCPIP_H
161 #include <ws2tcpip.h>
162 #endif
163 ])
164   if test $ac_cv_have_decl_getaddrinfo = no; then
165     HAVE_DECL_GETADDRINFO=0
166   fi
167   if test $ac_cv_have_decl_freeaddrinfo = no; then
168     HAVE_DECL_FREEADDRINFO=0
169   fi
170   if test $ac_cv_have_decl_gai_strerror = no; then
171     HAVE_DECL_GAI_STRERROR=0
172   fi
173   if test $ac_cv_have_decl_getnameinfo = no; then
174     HAVE_DECL_GETNAMEINFO=0
175   fi
176
177   AC_CHECK_TYPES([struct addrinfo],,,[
178 #include <sys/types.h>
179 #ifdef HAVE_SYS_SOCKET_H
180 #include <sys/socket.h>
181 #endif
182 #ifdef HAVE_NETDB_H
183 #include <netdb.h>
184 #endif
185 #ifdef HAVE_WS2TCPIP_H
186 #include <ws2tcpip.h>
187 #endif
188 ])
189   if test $ac_cv_type_struct_addrinfo = no; then
190     HAVE_STRUCT_ADDRINFO=0
191   fi
192
193   dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
194   case " $GETADDRINFO_LIB " in
195     *" $HOSTENT_LIB "*) ;;
196     *) GETADDRINFO_LIB="$GETADDRINFO_LIB $HOSTENT_LIB" ;;
197   esac
198
199   dnl Append $SERVENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
200   case " $GETADDRINFO_LIB " in
201     *" $SERVENT_LIB "*) ;;
202     *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;;
203   esac
204
205   dnl Append $INET_NTOP_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
206   case " $GETADDRINFO_LIB " in
207     *" $INET_NTOP_LIB "*) ;;
208     *) GETADDRINFO_LIB="$GETADDRINFO_LIB $INET_NTOP_LIB" ;;
209   esac
210 ])