[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getaddrinfo: finding gethostbyname in mingw32
From: |
Simon Josefsson |
Subject: |
Re: getaddrinfo: finding gethostbyname in mingw32 |
Date: |
Thu, 19 Jan 2006 16:30:03 +0100 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) |
The follow patch make getaddrinfo work (it seems Windows has a
getaddrinfo implementation, although it doesn't have gai_strerror)
_except_ that applications need to initialize Windows' socket code
manually, by calling WSAStartup. I'm not sure how to handle that.
One solution is to create gl_getaddrinfo which make sure WSAStartup is
called, and then invoke getaddrinfo. But that forces all applications
to call gl_getaddrinfo rather than getaddrinfo. That seem rather
ugly. Ideas?
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, if that function exists in
-lws2_32.
PS. mingw32 doesn't have netdb.h either. Perhaps something similar as
the sys_socket module should be done for it, to avoid the HAVE_NETDB_H
stuff. I think ws2tcpip.h contain most of the useful definitions.
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 19 Jan 2006 15:25:33 -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.2
diff -u -p -r1.2 socket_.h
--- lib/socket_.h 19 Jan 2006 13:45:37 -0000 1.2
+++ lib/socket_.h 19 Jan 2006 15:25:33 -0000
@@ -27,6 +27,7 @@
winsock2.h and ws2tcpip.h that declare the sys/socket.h definitions
we need. */
+#define WINVER 0x0501
#if HAVE_WINSOCK2_H
# include <winsock2.h>
#endif
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 19 Jan 2006 15:25:33 -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 <address@hidden>.
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,16 @@ 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 define on mingw32. */
+# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
+# endif
+# ifndef EAI_SYSTEM
+/* Not define on mingw32. */
+# 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 19 Jan 2006 15:25:33 -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 <address@hidden>, 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>