Alexandre Goujon : ws2_32: Make gethostbyname fail if WSAStartup was not called before.

Alexandre Julliard julliard at winehq.org
Wed Feb 23 13:01:52 CST 2011


Module: wine
Branch: master
Commit: 778757ba7434162edf35391f8a7b63b756b3ef59
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=778757ba7434162edf35391f8a7b63b756b3ef59

Author: Alexandre Goujon <ale.goujon at gmail.com>
Date:   Tue Feb 22 21:02:22 2011 +0100

ws2_32: Make gethostbyname fail if WSAStartup was not called before.

---

 dlls/ws2_32/socket.c     |    4 ++++
 dlls/ws2_32/tests/sock.c |    6 ++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index f3a521c..f74fd36 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -4606,6 +4606,10 @@ struct WS_hostent* WINAPI WS_gethostbyname(const char* name)
     int locerr = ENOBUFS;
 #endif
     char hostname[100];
+    if(!num_startup) {
+        SetLastError(WSANOTINITIALISED);
+        return NULL;
+    }
     if( gethostname( hostname, 100) == -1) {
         SetLastError( WSAENOBUFS); /* appropriate ? */
         return retval;
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index de647f1..d2f011f 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -834,8 +834,6 @@ out:
 }
 
 /* Tests for WSAStartup */
-
-/* This should fail. WSAStartup should be called before any network function is used. */
 static void test_WithoutWSAStartup(void)
 {
     LPVOID ptr;
@@ -843,8 +841,8 @@ static void test_WithoutWSAStartup(void)
     WSASetLastError(0xdeadbeef);
     ptr = gethostbyname("localhost");
 
-    todo_wine ok(ptr == NULL, "gethostbyname() succeeded unexpectedly: %d\n", WSAGetLastError());
-    todo_wine ok(WSAGetLastError() == WSANOTINITIALISED, "gethostbyname() failed with unexpected error: %d\n",
+    ok(ptr == NULL, "gethostbyname() succeeded unexpectedly: %d\n", WSAGetLastError());
+    ok(WSAGetLastError() == WSANOTINITIALISED, "gethostbyname() failed with unexpected error: %d\n",
                 WSAGetLastError());
 }
 




More information about the wine-cvs mailing list