Commit | Line | Data |
---|---|---|
af07e104 | 1 | # getaddrinfo.m4 serial 30 |
5e69ceb7 | 2 | dnl Copyright (C) 2004-2014 Free Software Foundation, Inc. |
61cd9dc9 LC |
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 | ||
3d458a81 | 27 | HAVE_GETADDRINFO=1 |
61cd9dc9 LC |
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 | |
3d458a81 | 59 | HAVE_GETADDRINFO=0 |
61cd9dc9 LC |
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. | |
35428fb6 | 66 | AC_CHECK_DECLS([gai_strerror], [], [], [[ |
61cd9dc9 LC |
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> | |
3d458a81 AW |
78 | ]]) |
79 | if test $ac_cv_have_decl_gai_strerror = yes; then | |
35428fb6 LC |
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 | ]]) | |
3d458a81 AW |
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> | |
35428fb6 LC |
108 | extern |
109 | #ifdef __cplusplus | |
110 | "C" | |
111 | #endif | |
112 | const char *gai_strerror(int);]])], | |
3d458a81 AW |
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 | |
61cd9dc9 LC |
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 | |
a927b6c1 | 133 | AC_REQUIRE([gl_FUNC_INET_NTOP]) dnl for INET_NTOP_LIB |
61cd9dc9 LC |
134 | AC_REQUIRE([AC_C_RESTRICT]) |
135 | AC_REQUIRE([gl_SOCKET_FAMILIES]) | |
136 | AC_REQUIRE([gl_HEADER_SYS_SOCKET]) | |
61cd9dc9 LC |
137 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
138 | ||
139 | dnl Including sys/socket.h is wrong for Windows, but Windows does not | |
140 | dnl have sa_len so the result is correct anyway. | |
dd7d0148 LC |
141 | AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [ |
142 | #include <sys/types.h> | |
143 | #include <sys/socket.h> | |
144 | ]) | |
61cd9dc9 LC |
145 | |
146 | AC_CHECK_HEADERS_ONCE([netinet/in.h]) | |
147 | ||
35428fb6 | 148 | AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, getnameinfo],,,[[ |
61cd9dc9 LC |
149 | /* sys/types.h is not needed according to POSIX, but the |
150 | sys/socket.h in i386-unknown-freebsd4.10 and | |
151 | powerpc-apple-darwin5.5 required it. */ | |
152 | #include <sys/types.h> | |
153 | #ifdef HAVE_SYS_SOCKET_H | |
154 | #include <sys/socket.h> | |
155 | #endif | |
156 | #ifdef HAVE_NETDB_H | |
157 | #include <netdb.h> | |
158 | #endif | |
159 | #ifdef HAVE_WS2TCPIP_H | |
160 | #include <ws2tcpip.h> | |
161 | #endif | |
35428fb6 | 162 | ]]) |
61cd9dc9 LC |
163 | if test $ac_cv_have_decl_getaddrinfo = no; then |
164 | HAVE_DECL_GETADDRINFO=0 | |
165 | fi | |
166 | if test $ac_cv_have_decl_freeaddrinfo = no; then | |
167 | HAVE_DECL_FREEADDRINFO=0 | |
168 | fi | |
169 | if test $ac_cv_have_decl_gai_strerror = no; then | |
170 | HAVE_DECL_GAI_STRERROR=0 | |
171 | fi | |
172 | if test $ac_cv_have_decl_getnameinfo = no; then | |
173 | HAVE_DECL_GETNAMEINFO=0 | |
174 | fi | |
175 | ||
176 | AC_CHECK_TYPES([struct addrinfo],,,[ | |
177 | #include <sys/types.h> | |
178 | #ifdef HAVE_SYS_SOCKET_H | |
179 | #include <sys/socket.h> | |
180 | #endif | |
181 | #ifdef HAVE_NETDB_H | |
182 | #include <netdb.h> | |
183 | #endif | |
184 | #ifdef HAVE_WS2TCPIP_H | |
185 | #include <ws2tcpip.h> | |
186 | #endif | |
187 | ]) | |
188 | if test $ac_cv_type_struct_addrinfo = no; then | |
189 | HAVE_STRUCT_ADDRINFO=0 | |
190 | fi | |
191 | ||
192 | dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates. | |
193 | case " $GETADDRINFO_LIB " in | |
194 | *" $HOSTENT_LIB "*) ;; | |
195 | *) GETADDRINFO_LIB="$GETADDRINFO_LIB $HOSTENT_LIB" ;; | |
196 | esac | |
197 | ||
198 | dnl Append $SERVENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates. | |
199 | case " $GETADDRINFO_LIB " in | |
200 | *" $SERVENT_LIB "*) ;; | |
201 | *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;; | |
202 | esac | |
203 | ||
204 | dnl Append $INET_NTOP_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates. | |
205 | case " $GETADDRINFO_LIB " in | |
206 | *" $INET_NTOP_LIB "*) ;; | |
207 | *) GETADDRINFO_LIB="$GETADDRINFO_LIB $INET_NTOP_LIB" ;; | |
208 | esac | |
209 | ]) |