Bruno Haible <[EMAIL PROTECTED]> writes: > Simon Josefsson wrote: >> Unless there is a simple concrete solution to this, I'm inclined to >> install the patch below and document that people using this module >> will have to call WSAStartup manually, > > I don't know the simple concrete solution either :-), so I would do like > you say.
I installed the patch below. I have tested this on Windows XP, and getaddrinfo do seem to look up names. >> +#define WINVER 0x0501 > > Can you explain the purpose of this line in a comment, please? For > maintainability. I wrote what I know in a comment below. I'm pretty sure I don't know all the details and implications of that. +/* 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> Thanks! 2006-01-25 Simon Josefsson <[EMAIL PROTECTED]> * 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 Simon Josefsson <[EMAIL PROTECTED]> * 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). Index: m4/getaddrinfo.m4 =================================================================== RCS file: /sources/gnulib/gnulib/m4/getaddrinfo.m4,v retrieving revision 1.12 diff -u -p -r1.12 getaddrinfo.m4 --- m4/getaddrinfo.m4 5 Oct 2005 21:41:31 -0000 1.12 +++ m4/getaddrinfo.m4 27 Jan 2006 12:48:06 -0000 @@ -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 ]) ]) Index: lib/socket_.h =================================================================== RCS file: /sources/gnulib/gnulib/lib/socket_.h,v retrieving revision 1.4 diff -u -p -r1.4 socket_.h --- lib/socket_.h 24 Jan 2006 12:53:13 -0000 1.4 +++ lib/socket_.h 27 Jan 2006 12:48:06 -0000 @@ -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 Index: lib/getaddrinfo.h =================================================================== RCS file: /sources/gnulib/gnulib/lib/getaddrinfo.h,v retrieving revision 1.11 diff -u -p -r1.11 getaddrinfo.h --- lib/getaddrinfo.h 8 Nov 2005 19:20:59 -0000 1.11 +++ lib/getaddrinfo.h 27 Jan 2006 12:48:06 -0000 @@ -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 <[EMAIL PROTECTED]>. 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 @@ struct addrinfo # 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_ADDRFAMILY -9 /* Address family for NAME not supported. */ # define EAI_MEMORY -10 /* Memory allocation failure. */ -# define EAI_SYSTEM -11 /* System error returned in `errno'. */ # 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. */ +# 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'. */ # endif # ifdef __USE_GNU Index: lib/gai_strerror.c =================================================================== RCS file: /sources/gnulib/gnulib/lib/gai_strerror.c,v retrieving revision 1.4 diff -u -p -r1.4 gai_strerror.c --- lib/gai_strerror.c 12 Sep 2005 14:25:04 -0000 1.4 +++ lib/gai_strerror.c 27 Jan 2006 12:48:06 -0000 @@ -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 <[EMAIL PROTECTED]>, 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> _______________________________________________ bug-gnulib mailing list bug-gnulib@gnu.org http://lists.gnu.org/mailman/listinfo/bug-gnulib