From 955a407e3c7dd91d6322a65747fb61403978c6a8 Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Fri, 27 Jan 2006 12:50:41 +0000 Subject: [PATCH] Mingw32 fixes for getaddrinfo. --- lib/ChangeLog | 11 +++++++++++ lib/gai_strerror.c | 6 ++++-- lib/getaddrinfo.h | 16 +++++++++++++--- lib/socket_.h | 16 ++++++++++++++++ m4/ChangeLog | 6 ++++++ m4/getaddrinfo.m4 | 46 +++++++++++++++++++++++++++++++++++++++++----- 6 files changed, 91 insertions(+), 10 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index e21d1cbec..4e3aed77a 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,14 @@ +2006-01-25 Simon Josefsson + + * 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 * fts.c (diropen): Open with O_NOCTTY | O_NONBLOCK too. Don't diff --git a/lib/gai_strerror.c b/lib/gai_strerror.c index f2898706e..d97b858be 100644 --- 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 , 1997. @@ -25,7 +25,9 @@ #endif #include -#include +#ifdef HAVE_NETDB_H +# include +#endif #ifdef _LIBC # include diff --git a/lib/getaddrinfo.h b/lib/getaddrinfo.h index 65f52cda6..7722c14ba 100644 --- 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 . This program is free software; you can redistribute it and/or modify @@ -26,7 +26,9 @@ # include /* Get all getaddrinfo related declarations, if available. */ # include +#ifdef HAVE_NETDB_H # include +#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 diff --git a/lib/socket_.h b/lib/socket_.h index 07b1d30d1..3d94ada81 100644 --- 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 #endif #if HAVE_WS2TCPIP_H diff --git a/m4/ChangeLog b/m4/ChangeLog index e4d22b47c..50da584ff 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,9 @@ +2006-01-25 Simon Josefsson + + * 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 * stdbool.m4 (AC_HEADER_STDBOOL): Check for xlc bug if __GCC__ too, diff --git a/m4/getaddrinfo.m4 b/m4/getaddrinfo.m4 index b3b7b0736..006cdab2a 100644 --- 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 +], [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 +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_NETDB_H #include +#endif +#ifdef HAVE_WS2TCPIP_H +#define WINVER 0x0501 +#include +#endif ]) AC_CHECK_TYPES([struct addrinfo],,,[ #include +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_NETDB_H #include +#endif +#ifdef HAVE_WS2TCPIP_H +#define WINVER 0x0501 +#include +#endif ]) ]) -- 2.11.0