changeset 6619:29248383a0c7

Mingw32 fixes for getaddrinfo.
author Simon Josefsson <simon@josefsson.org>
date Fri, 27 Jan 2006 12:50:41 +0000
parents 6f335711be5e
children d01ba6cdaf9e
files lib/ChangeLog lib/gai_strerror.c lib/getaddrinfo.h lib/socket_.h m4/ChangeLog m4/getaddrinfo.m4
diffstat 6 files changed, 91 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,14 @@
+2006-01-25  Simon Josefsson  <jas@extundo.com>
+
+	* socket_.h: Set WINVER to 0x0501, to make sure getaddrinfo
+	prototype is visible on mingw32.
+
+	* getaddrinfo.h: Define EAI_ADDRFAMILY and EAI_SYSTEM if not set,
+	for mingw32.
+
+	* gai_strerror.c, getaddrinfo.h: Protect netdb.h #include (for
+	mingw32).
+
 2006-01-26  Paul Eggert  <eggert@cs.ucla.edu>
 
 	* fts.c (diropen): Open with O_NOCTTY | O_NONBLOCK too.  Don't
--- a/lib/gai_strerror.c
+++ b/lib/gai_strerror.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997.
 
@@ -25,7 +25,9 @@
 #endif
 
 #include <stdio.h>
-#include <netdb.h>
+#ifdef HAVE_NETDB_H
+# include <netdb.h>
+#endif
 
 #ifdef _LIBC
 # include <libintl.h>
--- a/lib/getaddrinfo.h
+++ b/lib/getaddrinfo.h
@@ -1,5 +1,5 @@
 /* Get address information.
-   Copyright (C) 1996-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1996-2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
    Contributed by Simon Josefsson <simon@josefsson.org>.
 
    This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,9 @@
 # include <sys/types.h>
 /* Get all getaddrinfo related declarations, if available.  */
 # include <sys/socket.h>
+#ifdef HAVE_NETDB_H
 # include <netdb.h>
+#endif
 
 # ifndef HAVE_STRUCT_ADDRINFO
 
@@ -65,10 +67,18 @@
 #  define EAI_FAMILY	  -6	/* `ai_family' not supported.  */
 #  define EAI_SOCKTYPE	  -7	/* `ai_socktype' not supported.  */
 #  define EAI_SERVICE	  -8	/* SERVICE not supported for `ai_socktype'.  */
+#  define EAI_MEMORY	  -10	/* Memory allocation failure.  */
+#  define EAI_OVERFLOW	  -12	/* Argument buffer overflow.  */
+#endif
+# ifndef EAI_ADDRFAMILY
+/* Not defined on mingw32.  XXX May be incorrect? Perhaps it is never
+   returned? */
 #  define EAI_ADDRFAMILY  -9	/* Address family for NAME not supported.  */
-#  define EAI_MEMORY	  -10	/* Memory allocation failure.  */
+# endif
+# ifndef EAI_SYSTEM
+/* Not defined on mingw32.  XXX May be incorrect? Perhaps it is never
+   returned? */
 #  define EAI_SYSTEM	  -11	/* System error returned in `errno'.  */
-#  define EAI_OVERFLOW	  -12	/* Argument buffer overflow.  */
 # endif
 
 # ifdef __USE_GNU
--- a/lib/socket_.h
+++ b/lib/socket_.h
@@ -28,6 +28,22 @@
    we need. */
 
 #if HAVE_WINSOCK2_H
+/* The following define makes sure we get all the prototypes from the
+   header files.  getaddrinfo is only available if _WIN32_WINNT >=
+   0x0501 (that symbol is set indiriectly through WINVER).  This has
+   the following two (potential) problems:
+
+     1) winsock2.h must not have been included before this symbol
+        is set (I think).
+
+     2) There may be some _reason_ for all prototypes not being
+        available with the default settings.  Such as if some APIs are
+        not available on older Windows hosts.  However, getaddrinfo
+        (which need >= 0x0501) should be available on Windows 95 and
+        later, according to:
+        http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp
+*/
+#define WINVER 0x0501
 # include <winsock2.h>
 #endif
 #if HAVE_WS2TCPIP_H
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-25  Simon Josefsson  <jas@extundo.com>
+
+	* getaddrinfo.m4: Look for getaddrinfo inside ws2tcip.h and
+	-lws2_32.  Protect sys/socket.h and netdb.h #include's.  Include
+	ws2tcpip.h with WINVER=0x0501.  All for mingw32.
+
 2006-01-25  Paul Eggert  <eggert@cs.ucla.edu>
 
 	* stdbool.m4 (AC_HEADER_STDBOOL): Check for xlc bug if __GCC__ too,
--- a/m4/getaddrinfo.m4
+++ b/m4/getaddrinfo.m4
@@ -1,36 +1,72 @@
 # getaddrinfo.m4 serial 7
-dnl Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+dnl Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_GETADDRINFO],
 [
+  AC_MSG_NOTICE([checking how to do getaddrinfo])
+
   AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
-  AC_SEARCH_LIBS(gethostbyname, [inet nsl])
-  AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
-  AC_REPLACE_FUNCS(getaddrinfo gai_strerror)
+  AC_CHECK_FUNCS(getaddrinfo,, [
+    AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32,
+                   gl_cv_w32_getaddrinfo, [
+      gl_cv_w32_getaddrinfo=no
+      am_save_LIBS="$LIBS"
+      LIBS="$LIBS -lws2_32"
+      AC_TRY_LINK([
+#define WINVER 0x0501
+#include <ws2tcpip.h>
+], [getaddrinfo(0, 0, 0, 0);], gl_cv_w32_getaddrinfo=yes)
+      LIBS="$am_save_LIBS"
+      if test "$gl_cv_w32_getaddrinfo" = "yes"; then
+        LIBS="$LIBS -lws2_32"
+      else
+        AC_LIBOBJ(getaddrinfo)
+      fi
+    ])])
+
+  AC_REPLACE_FUNCS(gai_strerror)
   gl_PREREQ_GETADDRINFO
 ])
 
 # Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
+  AC_SEARCH_LIBS(gethostbyname, [inet nsl])
+  AC_SEARCH_LIBS(getservbyname, [inet nsl socket xnet])
   AC_REQUIRE([gl_C_RESTRICT])
   AC_REQUIRE([gl_SOCKET_FAMILIES])
   AC_REQUIRE([AC_C_INLINE])
   AC_REQUIRE([AC_GNU_SOURCE])
-  AC_CHECK_HEADERS_ONCE(netinet/in.h)
+  AC_CHECK_HEADERS_ONCE(netinet/in.h sys/socket.h netdb.h ws2tcpip.h)
   AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror],,,[
   /* sys/types.h is not needed according to POSIX, but the
      sys/socket.h in i386-unknown-freebsd4.10 and
      powerpc-apple-darwin5.5 required it. */
 #include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
+#ifdef HAVE_NETDB_H
 #include <netdb.h>
+#endif
+#ifdef HAVE_WS2TCPIP_H
+#define WINVER 0x0501
+#include <ws2tcpip.h>
+#endif
 ])
   AC_CHECK_TYPES([struct addrinfo],,,[
 #include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
+#ifdef HAVE_NETDB_H
 #include <netdb.h>
+#endif
+#ifdef HAVE_WS2TCPIP_H
+#define WINVER 0x0501
+#include <ws2tcpip.h>
+#endif
 ])
 ])