1 # getaddrinfo.m4 serial 15
2 dnl Copyright (C) 2004, 2005, 2006, 2007 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_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
12 AC_CHECK_HEADERS_ONCE(netdb.h)
14 AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
15 AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
17 #include <sys/types.h>
18 #ifdef HAVE_SYS_SOCKET_H
19 #include <sys/socket.h>
25 ], [getaddrinfo("", "", NULL, NULL);],
26 [gl_cv_func_getaddrinfo=yes],
27 [gl_cv_func_getaddrinfo=no])])
28 if test $gl_cv_func_getaddrinfo = no; then
29 AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32,
30 gl_cv_w32_getaddrinfo, [
31 gl_cv_w32_getaddrinfo=no
35 #ifdef HAVE_WS2TCPIP_H
38 ], [getaddrinfo(NULL, NULL, NULL, NULL);], gl_cv_w32_getaddrinfo=yes)
39 LIBS="$am_save_LIBS"])
40 if test "$gl_cv_w32_getaddrinfo" = "yes"; then
43 AC_LIBOBJ(getaddrinfo)
47 # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an
48 # inline function declared in ws2tcpip.h, so we need to get that
49 # header included somehow.
50 AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)],
51 gl_cv_func_gai_strerror, [
53 #include <sys/types.h>
54 #ifdef HAVE_SYS_SOCKET_H
55 #include <sys/socket.h>
60 #ifdef HAVE_WS2TCPIP_H
63 ], [gai_strerror (NULL);],
64 [gl_cv_func_gai_strerror=yes],
65 [gl_cv_func_gai_strerror=no])])
66 if test $gl_cv_func_gai_strerror = no; then
67 AC_LIBOBJ(gai_strerror)
73 # Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
74 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
75 AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
76 AC_SEARCH_LIBS(gethostbyname, [inet nsl])
77 AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
78 AC_CHECK_FUNCS(gethostbyname,, [
79 AC_CACHE_CHECK(for gethostbyname in winsock2.h and -lws2_32,
80 gl_cv_w32_gethostbyname, [
81 gl_cv_w32_gethostbyname=no
85 #ifdef HAVE_WINSOCK2_H
88 ], [gethostbyname(NULL);], gl_cv_w32_gethostbyname=yes)
89 LIBS="$am_save_LIBS"])
90 if test "$gl_cv_w32_gethostbyname" = "yes"; then
94 AC_REQUIRE([AC_C_RESTRICT])
95 AC_REQUIRE([gl_SOCKET_FAMILIES])
96 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
97 AC_REQUIRE([AC_C_INLINE])
98 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
99 AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h)
100 AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
101 /* sys/types.h is not needed according to POSIX, but the
102 sys/socket.h in i386-unknown-freebsd4.10 and
103 powerpc-apple-darwin5.5 required it. */
104 #include <sys/types.h>
105 #ifdef HAVE_SYS_SOCKET_H
106 #include <sys/socket.h>
111 #ifdef HAVE_WS2TCPIP_H
112 #include <ws2tcpip.h>
115 AC_CHECK_TYPES([struct addrinfo],,,[
116 #include <sys/types.h>
117 #ifdef HAVE_SYS_SOCKET_H
118 #include <sys/socket.h>
123 #ifdef HAVE_WS2TCPIP_H
124 #include <ws2tcpip.h>