1 # getaddrinfo.m4 serial 27
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.
7 AC_DEFUN([gl_GETADDRINFO],
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])
13 gai_saved_LIBS="$LIBS"
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"
25 LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
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>
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
47 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
48 #ifdef HAVE_WS2TCPIP_H
52 ]], [[getaddrinfo(NULL, NULL, NULL, NULL);]])], [gl_cv_w32_getaddrinfo=yes])
55 if test "$gl_cv_w32_getaddrinfo" = "yes"; then
56 GETADDRINFO_LIB="-lws2_32"
57 LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
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, gai_strerrorA], [], [break], [[
67 #include <sys/types.h>
68 #ifdef HAVE_SYS_SOCKET_H
69 #include <sys/socket.h>
74 #ifdef HAVE_WS2TCPIP_H
79 if test $ac_cv_have_decl_gai_strerror = yes; then
80 dnl check for correct signature
81 AC_CACHE_CHECK([for gai_strerror with POSIX signature],
82 [gl_cv_func_gai_strerror_posix_signature], [
83 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
84 #include <sys/types.h>
85 #ifdef HAVE_SYS_SOCKET_H
86 #include <sys/socket.h>
91 #ifdef HAVE_WS2TCPIP_H
99 const char *gai_strerror(int);]])],
100 [gl_cv_func_gai_strerror_posix_signature=yes],
101 [gl_cv_func_gai_strerror_posix_signature=no])])
102 if test $gl_cv_func_gai_strerror_posix_signature = no; then
103 REPLACE_GAI_STRERROR=1
107 LIBS="$gai_saved_LIBS"
109 gl_PREREQ_GETADDRINFO
111 AC_SUBST([GETADDRINFO_LIB])
114 # Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c.
115 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
116 AC_REQUIRE([gl_NETDB_H_DEFAULTS])
117 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
118 AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB
119 AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB
120 AC_REQUIRE([gl_FUNC_INET_NTOP]) dnl for INET_NTOP_LIB
121 AC_REQUIRE([AC_C_RESTRICT])
122 AC_REQUIRE([gl_SOCKET_FAMILIES])
123 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
124 AC_REQUIRE([AC_C_INLINE])
125 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
127 dnl Including sys/socket.h is wrong for Windows, but Windows does not
128 dnl have sa_len so the result is correct anyway.
129 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [
130 #include <sys/types.h>
131 #include <sys/socket.h>
134 AC_CHECK_HEADERS_ONCE([netinet/in.h])
136 AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, getnameinfo],,,[
137 /* sys/types.h is not needed according to POSIX, but the
138 sys/socket.h in i386-unknown-freebsd4.10 and
139 powerpc-apple-darwin5.5 required it. */
140 #include <sys/types.h>
141 #ifdef HAVE_SYS_SOCKET_H
142 #include <sys/socket.h>
147 #ifdef HAVE_WS2TCPIP_H
148 #include <ws2tcpip.h>
151 if test $ac_cv_have_decl_getaddrinfo = no; then
152 HAVE_DECL_GETADDRINFO=0
154 if test $ac_cv_have_decl_freeaddrinfo = no; then
155 HAVE_DECL_FREEADDRINFO=0
157 if test $ac_cv_have_decl_gai_strerror = no; then
158 HAVE_DECL_GAI_STRERROR=0
160 if test $ac_cv_have_decl_getnameinfo = no; then
161 HAVE_DECL_GETNAMEINFO=0
164 AC_CHECK_TYPES([struct addrinfo],,,[
165 #include <sys/types.h>
166 #ifdef HAVE_SYS_SOCKET_H
167 #include <sys/socket.h>
172 #ifdef HAVE_WS2TCPIP_H
173 #include <ws2tcpip.h>
176 if test $ac_cv_type_struct_addrinfo = no; then
177 HAVE_STRUCT_ADDRINFO=0
180 dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
181 case " $GETADDRINFO_LIB " in
182 *" $HOSTENT_LIB "*) ;;
183 *) GETADDRINFO_LIB="$GETADDRINFO_LIB $HOSTENT_LIB" ;;
186 dnl Append $SERVENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
187 case " $GETADDRINFO_LIB " in
188 *" $SERVENT_LIB "*) ;;
189 *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;;
192 dnl Append $INET_NTOP_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
193 case " $GETADDRINFO_LIB " in
194 *" $INET_NTOP_LIB "*) ;;
195 *) GETADDRINFO_LIB="$GETADDRINFO_LIB $INET_NTOP_LIB" ;;