Commit | Line | Data |
---|---|---|
61cd9dc9 LC |
1 | # getaddrinfo.m4 serial 22 |
2 | dnl Copyright (C) 2004-2010 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 | AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [ | |
28 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ | |
29 | #include <sys/types.h> | |
30 | #ifdef HAVE_SYS_SOCKET_H | |
31 | #include <sys/socket.h> | |
32 | #endif | |
33 | #ifdef HAVE_NETDB_H | |
34 | #include <netdb.h> | |
35 | #endif | |
36 | #include <stddef.h> | |
37 | ]], [[getaddrinfo("", "", NULL, NULL);]])], | |
38 | [gl_cv_func_getaddrinfo=yes], | |
39 | [gl_cv_func_getaddrinfo=no])]) | |
40 | if test $gl_cv_func_getaddrinfo = no; then | |
41 | AC_CACHE_CHECK([for getaddrinfo in ws2tcpip.h and -lws2_32], | |
42 | gl_cv_w32_getaddrinfo, [ | |
43 | gl_cv_w32_getaddrinfo=no | |
44 | am_save_LIBS="$LIBS" | |
45 | LIBS="$LIBS -lws2_32" | |
46 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ | |
47 | #ifdef HAVE_WS2TCPIP_H | |
48 | #include <ws2tcpip.h> | |
49 | #endif | |
50 | #include <stddef.h> | |
51 | ]], [[getaddrinfo(NULL, NULL, NULL, NULL);]])], [gl_cv_w32_getaddrinfo=yes]) | |
52 | LIBS="$am_save_LIBS" | |
53 | ]) | |
54 | if test "$gl_cv_w32_getaddrinfo" = "yes"; then | |
55 | GETADDRINFO_LIB="-lws2_32" | |
56 | LIBS="$gai_saved_LIBS $GETADDRINFO_LIB" | |
57 | else | |
58 | AC_LIBOBJ([getaddrinfo]) | |
59 | fi | |
60 | fi | |
61 | ||
62 | # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an | |
63 | # inline function declared in ws2tcpip.h, so we need to get that | |
64 | # header included somehow. | |
65 | AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)], | |
66 | gl_cv_func_gai_strerror, [ | |
67 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ | |
68 | #include <sys/types.h> | |
69 | #ifdef HAVE_SYS_SOCKET_H | |
70 | #include <sys/socket.h> | |
71 | #endif | |
72 | #ifdef HAVE_NETDB_H | |
73 | #include <netdb.h> | |
74 | #endif | |
75 | #ifdef HAVE_WS2TCPIP_H | |
76 | #include <ws2tcpip.h> | |
77 | #endif | |
78 | #include <stddef.h> | |
79 | ]], [[gai_strerror (NULL);]])], | |
80 | [gl_cv_func_gai_strerror=yes], | |
81 | [gl_cv_func_gai_strerror=no])]) | |
82 | if test $gl_cv_func_gai_strerror = no; then | |
83 | AC_LIBOBJ([gai_strerror]) | |
84 | fi | |
85 | ||
86 | LIBS="$gai_saved_LIBS" | |
87 | ||
88 | gl_PREREQ_GETADDRINFO | |
89 | ||
90 | AC_SUBST([GETADDRINFO_LIB]) | |
91 | ]) | |
92 | ||
93 | # Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c. | |
94 | AC_DEFUN([gl_PREREQ_GETADDRINFO], [ | |
95 | AC_REQUIRE([gl_NETDB_H_DEFAULTS]) | |
96 | AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H | |
97 | AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB | |
98 | AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB | |
99 | AC_REQUIRE([gl_INET_NTOP]) dnl for INET_NTOP_LIB | |
100 | AC_REQUIRE([AC_C_RESTRICT]) | |
101 | AC_REQUIRE([gl_SOCKET_FAMILIES]) | |
102 | AC_REQUIRE([gl_HEADER_SYS_SOCKET]) | |
103 | AC_REQUIRE([AC_C_INLINE]) | |
104 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) | |
105 | ||
106 | dnl Including sys/socket.h is wrong for Windows, but Windows does not | |
107 | dnl have sa_len so the result is correct anyway. | |
108 | AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [#include <sys/socket.h>]) | |
109 | ||
110 | AC_CHECK_HEADERS_ONCE([netinet/in.h]) | |
111 | ||
112 | AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[ | |
113 | /* sys/types.h is not needed according to POSIX, but the | |
114 | sys/socket.h in i386-unknown-freebsd4.10 and | |
115 | powerpc-apple-darwin5.5 required it. */ | |
116 | #include <sys/types.h> | |
117 | #ifdef HAVE_SYS_SOCKET_H | |
118 | #include <sys/socket.h> | |
119 | #endif | |
120 | #ifdef HAVE_NETDB_H | |
121 | #include <netdb.h> | |
122 | #endif | |
123 | #ifdef HAVE_WS2TCPIP_H | |
124 | #include <ws2tcpip.h> | |
125 | #endif | |
126 | ]) | |
127 | if test $ac_cv_have_decl_getaddrinfo = no; then | |
128 | HAVE_DECL_GETADDRINFO=0 | |
129 | fi | |
130 | if test $ac_cv_have_decl_freeaddrinfo = no; then | |
131 | HAVE_DECL_FREEADDRINFO=0 | |
132 | fi | |
133 | if test $ac_cv_have_decl_gai_strerror = no; then | |
134 | HAVE_DECL_GAI_STRERROR=0 | |
135 | fi | |
136 | if test $ac_cv_have_decl_getnameinfo = no; then | |
137 | HAVE_DECL_GETNAMEINFO=0 | |
138 | fi | |
139 | ||
140 | AC_CHECK_TYPES([struct addrinfo],,,[ | |
141 | #include <sys/types.h> | |
142 | #ifdef HAVE_SYS_SOCKET_H | |
143 | #include <sys/socket.h> | |
144 | #endif | |
145 | #ifdef HAVE_NETDB_H | |
146 | #include <netdb.h> | |
147 | #endif | |
148 | #ifdef HAVE_WS2TCPIP_H | |
149 | #include <ws2tcpip.h> | |
150 | #endif | |
151 | ]) | |
152 | if test $ac_cv_type_struct_addrinfo = no; then | |
153 | HAVE_STRUCT_ADDRINFO=0 | |
154 | fi | |
155 | ||
156 | dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates. | |
157 | case " $GETADDRINFO_LIB " in | |
158 | *" $HOSTENT_LIB "*) ;; | |
159 | *) GETADDRINFO_LIB="$GETADDRINFO_LIB $HOSTENT_LIB" ;; | |
160 | esac | |
161 | ||
162 | dnl Append $SERVENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates. | |
163 | case " $GETADDRINFO_LIB " in | |
164 | *" $SERVENT_LIB "*) ;; | |
165 | *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;; | |
166 | esac | |
167 | ||
168 | dnl Append $INET_NTOP_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates. | |
169 | case " $GETADDRINFO_LIB " in | |
170 | *" $INET_NTOP_LIB "*) ;; | |
171 | *) GETADDRINFO_LIB="$GETADDRINFO_LIB $INET_NTOP_LIB" ;; | |
172 | esac | |
173 | ]) |