2006-02-17 Eric Blake <address@hidden>
[gnulib.git] / m4 / getaddrinfo.m4
1 # getaddrinfo.m4 serial 9
2 dnl Copyright (C) 2004, 2005, 2006 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_MSG_NOTICE([checking how to do getaddrinfo])
10
11   AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
12   AC_CHECK_FUNCS(getaddrinfo,, [
13     AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32,
14                    gl_cv_w32_getaddrinfo, [
15       gl_cv_w32_getaddrinfo=no
16       am_save_LIBS="$LIBS"
17       LIBS="$LIBS -lws2_32"
18       AC_TRY_LINK([
19 #ifdef HAVE_WS2TCPIP_H
20 #define WINVER 0x0501
21 #include <ws2tcpip.h>
22 #endif
23 ], [getaddrinfo(0, 0, 0, 0);], gl_cv_w32_getaddrinfo=yes)
24     LIBS="$am_save_LIBS"])
25     if test "$gl_cv_w32_getaddrinfo" = "yes"; then
26       LIBS="$LIBS -lws2_32"
27     else
28       AC_LIBOBJ(getaddrinfo)
29     fi
30     ])
31
32   AC_REPLACE_FUNCS(gai_strerror)
33   gl_PREREQ_GETADDRINFO
34 ])
35
36 # Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
37 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
38   AC_SEARCH_LIBS(gethostbyname, [inet nsl])
39   AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
40   AC_REQUIRE([gl_C_RESTRICT])
41   AC_REQUIRE([gl_SOCKET_FAMILIES])
42   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
43   AC_REQUIRE([AC_C_INLINE])
44   AC_REQUIRE([AC_GNU_SOURCE])
45   AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h)
46   AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror],,,[
47   /* sys/types.h is not needed according to POSIX, but the
48      sys/socket.h in i386-unknown-freebsd4.10 and
49      powerpc-apple-darwin5.5 required it. */
50 #include <sys/types.h>
51 #ifdef HAVE_SYS_SOCKET_H
52 #include <sys/socket.h>
53 #endif
54 #ifdef HAVE_NETDB_H
55 #include <netdb.h>
56 #endif
57 #ifdef HAVE_WS2TCPIP_H
58 #define WINVER 0x0501
59 #include <ws2tcpip.h>
60 #endif
61 ])
62   AC_CHECK_TYPES([struct addrinfo],,,[
63 #include <sys/types.h>
64 #ifdef HAVE_SYS_SOCKET_H
65 #include <sys/socket.h>
66 #endif
67 #ifdef HAVE_NETDB_H
68 #include <netdb.h>
69 #endif
70 #ifdef HAVE_WS2TCPIP_H
71 #define WINVER 0x0501
72 #include <ws2tcpip.h>
73 #endif
74 ])
75 ])