bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] getaddrinfo: Initialize sockets, to make it work under Windows.


From: Simon Josefsson
Subject: [PATCH] getaddrinfo: Initialize sockets, to make it work under Windows.
Date: Sat, 25 Sep 2010 18:52:01 +0200
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (gnu/linux)

The getaddrinfo replacement didn't work on Windows if the application
hadn't already initialized sockets.  I believe replacement socket
functions should call WSAStartup on Windows -- POSIX doesn't require any
socket initialization code, and other gnulib replacement functions
(e.g., socket) already calls WSAStartup before calling the Windows
function.  The test-getaddrinfo self test worked around the bug, for
some reason that I hope was not intentional.

/Simon

---
 ChangeLog                |    8 ++++++++
 doc/gnulib.texi          |    2 +-
 lib/getaddrinfo.c        |    5 +++++
 modules/getaddrinfo      |    1 +
 tests/test-getaddrinfo.c |   19 -------------------
 5 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e4692b7..cfcf9a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-09-25  Simon Josefsson  <address@hidden>
+
+       * modules/getaddrinfo (Depends-on): Depend on the sockets module.
+       * lib/getaddrinfo.c (use_win32_p): Call gl_sockets_startup to make
+       sure Windows sockets are working before calling getaddrinfo.
+       * tests/test-getaddrinfo.c (main): Don't call WSAStartup here.
+       * doc/gnulib.texi (Windows sockets): Fix typo.
+
 2010-09-25  Bruno Haible  <address@hidden>
 
        Tests for module 'regex-quote'.
diff --git a/doc/gnulib.texi b/doc/gnulib.texi
index fd5485e..3e1599c 100644
--- a/doc/gnulib.texi
+++ b/doc/gnulib.texi
@@ -989,7 +989,7 @@ XP.  The function declaration is present if @code{WINVER >= 
0x0501}.
 Windows 2000 does not have getaddrinfo in its @file{WS2_32.DLL}.
 
 Thus, if you want to assume Windows XP or later, you can add
-AC_DEFINE(WINVER, 0x0501) to avoid compiling to (partial) getaddrinfo
+AC_DEFINE(WINVER, 0x0501) to avoid compiling the (partial) getaddrinfo
 implementation.
 
 If you want to support Windows 2000, don't do anything.  The
diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c
index 76dc19e..ce75647 100644
--- a/lib/getaddrinfo.c
+++ b/lib/getaddrinfo.c
@@ -59,6 +59,9 @@
 # define WIN32_NATIVE
 #endif
 
+/* gl_sockets_startup */
+#include "sockets.h"
+
 #ifdef WIN32_NATIVE
 typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*,
                                         const struct addrinfo*,
@@ -101,6 +104,8 @@ use_win32_p (void)
       return 0;
     }
 
+  gl_sockets_startup (SOCKETS_1_1);
+
   return 1;
 }
 #endif
diff --git a/modules/getaddrinfo b/modules/getaddrinfo
index f513652..1aa7208 100644
--- a/modules/getaddrinfo
+++ b/modules/getaddrinfo
@@ -17,6 +17,7 @@ netdb
 strdup
 servent
 hostent
+sockets
 
 configure.ac:
 gl_GETADDRINFO
diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c
index bd245b4..15d6569 100644
--- a/tests/test-getaddrinfo.c
+++ b/tests/test-getaddrinfo.c
@@ -161,25 +161,6 @@ simple (char const *host, char const *service)
 
 int main (void)
 {
-#if _WIN32
-  {
-    WORD requested;
-    WSADATA data;
-    int err;
-
-    requested = MAKEWORD (1, 1);
-    err = WSAStartup (requested, &data);
-    if (err != 0)
-      return 1;
-
-    if (data.wVersion < requested)
-      {
-        WSACleanup ();
-        return 2;
-      }
-  }
-#endif
-
   return simple (HOST1, SERV1)
     + simple (HOST2, SERV2)
     + simple (HOST3, SERV3)
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]