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