1 # getaddrinfo.m4 serial 19
2 dnl Copyright (C) 2004, 2005, 2006, 2007, 2008 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"
27 AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
29 #include <sys/types.h>
30 #ifdef HAVE_SYS_SOCKET_H
31 #include <sys/socket.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
47 #ifdef HAVE_WS2TCPIP_H
51 ], [getaddrinfo(NULL, NULL, NULL, NULL);], gl_cv_w32_getaddrinfo=yes)
54 if test "$gl_cv_w32_getaddrinfo" = "yes"; then
55 GETADDRINFO_LIB="-lws2_32"
56 LIBS="$gai_saved_LIBS $GETADDRINFO_LIB"
58 AC_LIBOBJ(getaddrinfo)
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, [
68 #include <sys/types.h>
69 #ifdef HAVE_SYS_SOCKET_H
70 #include <sys/socket.h>
75 #ifdef HAVE_WS2TCPIP_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)
86 LIBS="$gai_saved_LIBS"
90 AC_SUBST([GETADDRINFO_LIB])
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([AC_C_RESTRICT])
100 AC_REQUIRE([gl_SOCKET_FAMILIES])
101 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
102 AC_REQUIRE([AC_C_INLINE])
103 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
105 dnl Including sys/socket.h is wrong for Windows, but Windows does not
106 dnl have sa_len so the result is correct anyway.
107 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [#include <sys/socket.h>])
109 AC_CHECK_HEADERS_ONCE(netinet/in.h)
111 AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
112 /* sys/types.h is not needed according to POSIX, but the
113 sys/socket.h in i386-unknown-freebsd4.10 and
114 powerpc-apple-darwin5.5 required it. */
115 #include <sys/types.h>
116 #ifdef HAVE_SYS_SOCKET_H
117 #include <sys/socket.h>
122 #ifdef HAVE_WS2TCPIP_H
123 #include <ws2tcpip.h>
126 if test $ac_cv_have_decl_getaddrinfo = no; then
127 HAVE_DECL_GETADDRINFO=0
129 if test $ac_cv_have_decl_freeaddrinfo = no; then
130 HAVE_DECL_FREEADDRINFO=0
132 if test $ac_cv_have_decl_gai_strerror = no; then
133 HAVE_DECL_GAI_STRERROR=0
135 if test $ac_cv_have_decl_getnameinfo = no; then
136 HAVE_DECL_GETNAMEINFO=0
139 AC_CHECK_TYPES([struct addrinfo],,,[
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_type_struct_addrinfo = no; then
152 HAVE_STRUCT_ADDRINFO=0
155 dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
156 case " $GETADDRINFO_LIB " in
157 *" $HOSTENT_LIB "*) ;;
158 *) GETADDRINFO_LIB="$GETADDRINFO_LIB $HOSTENT_LIB" ;;
161 dnl Append $SERVENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
162 case " $GETADDRINFO_LIB " in
163 *" $SERVENT_LIB "*) ;;
164 *) GETADDRINFO_LIB="$GETADDRINFO_LIB $SERVENT_LIB" ;;