1 # getaddrinfo.m4 serial 18
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 AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
14 AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
16 #include <sys/types.h>
17 #ifdef HAVE_SYS_SOCKET_H
18 #include <sys/socket.h>
24 ], [getaddrinfo("", "", NULL, NULL);],
25 [gl_cv_func_getaddrinfo=yes],
26 [gl_cv_func_getaddrinfo=no])])
27 if test $gl_cv_func_getaddrinfo = no; then
28 AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32,
29 gl_cv_w32_getaddrinfo, [
30 gl_cv_w32_getaddrinfo=no
34 #ifdef HAVE_WS2TCPIP_H
38 ], [getaddrinfo(NULL, NULL, NULL, NULL);], gl_cv_w32_getaddrinfo=yes)
41 if test "$gl_cv_w32_getaddrinfo" = "yes"; then
44 AC_LIBOBJ(getaddrinfo)
48 # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
49 # inline function declared in ws2tcpip.h, so we need to get that
50 # header included somehow.
51 AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)],
52 gl_cv_func_gai_strerror, [
54 #include <sys/types.h>
55 #ifdef HAVE_SYS_SOCKET_H
56 #include <sys/socket.h>
61 #ifdef HAVE_WS2TCPIP_H
65 ], [gai_strerror (NULL);],
66 [gl_cv_func_gai_strerror=yes],
67 [gl_cv_func_gai_strerror=no])])
68 if test $gl_cv_func_gai_strerror = no; then
69 AC_LIBOBJ(gai_strerror)
75 # Prerequisites of lib/netdb.in.h and lib/getaddrinfo.c.
76 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
77 AC_REQUIRE([gl_NETDB_H_DEFAULTS])
78 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
79 AC_REQUIRE([gl_HOSTENT]) dnl for HOSTENT_LIB
80 AC_REQUIRE([gl_SERVENT]) dnl for SERVENT_LIB
81 LIBS="$LIBS $HOSTENT_LIB $SERVENT_LIB"
82 AC_REQUIRE([AC_C_RESTRICT])
83 AC_REQUIRE([gl_SOCKET_FAMILIES])
84 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
85 AC_REQUIRE([AC_C_INLINE])
86 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
88 dnl Including sys/socket.h is wrong for Windows, but Windows does not
89 dnl have sa_len so the result is correct anyway.
90 AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [#include <sys/socket.h>])
92 AC_CHECK_HEADERS_ONCE(netinet/in.h)
94 AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
95 /* sys/types.h is not needed according to POSIX, but the
96 sys/socket.h in i386-unknown-freebsd4.10 and
97 powerpc-apple-darwin5.5 required it. */
98 #include <sys/types.h>
99 #ifdef HAVE_SYS_SOCKET_H
100 #include <sys/socket.h>
105 #ifdef HAVE_WS2TCPIP_H
106 #include <ws2tcpip.h>
109 if test $ac_cv_have_decl_getaddrinfo = no; then
110 HAVE_DECL_GETADDRINFO=0
112 if test $ac_cv_have_decl_freeaddrinfo = no; then
113 HAVE_DECL_FREEADDRINFO=0
115 if test $ac_cv_have_decl_gai_strerror = no; then
116 HAVE_DECL_GAI_STRERROR=0
118 if test $ac_cv_have_decl_getnameinfo = no; then
119 HAVE_DECL_GETNAMEINFO=0
122 AC_CHECK_TYPES([struct addrinfo],,,[
123 #include <sys/types.h>
124 #ifdef HAVE_SYS_SOCKET_H
125 #include <sys/socket.h>
130 #ifdef HAVE_WS2TCPIP_H
131 #include <ws2tcpip.h>
134 if test $ac_cv_type_struct_addrinfo = no; then
135 HAVE_STRUCT_ADDRINFO=0