ws2_32: make gethostbyname fail if WSAStartup was not called before
Alexandre Goujon
ale.goujon at gmail.com
Sun Feb 20 06:51:10 CST 2011
---
dlls/ws2_32/socket.c | 7 +++++++
dlls/ws2_32/tests/sock.c | 6 ++----
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index f3a521c..f9fe660 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -327,6 +327,8 @@ struct route {
static INT num_startup; /* reference counter */
static FARPROC blocking_hook = (FARPROC)WSA_DefaultBlockingHook;
+static BOOL WSAStartup_called = FALSE;
+
/* function prototypes */
static struct WS_hostent *WS_create_he(char *name, int aliases, int addresses, int fill_addresses);
static struct WS_hostent *WS_dup_he(const struct hostent* p_he);
@@ -1104,6 +1106,7 @@ int WINAPI WSAStartup(WORD wVersionRequested, LPWSADATA lpWSAData)
/* don't do anything with lpWSAData->lpVendorInfo */
/* (some apps don't allocate the space for this field) */
+ WSAStartup_called = TRUE;
TRACE("succeeded\n");
return 0;
}
@@ -4606,6 +4609,10 @@ struct WS_hostent* WINAPI WS_gethostbyname(const char* name)
int locerr = ENOBUFS;
#endif
char hostname[100];
+ if(!WSAStartup_called) {
+ 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());
}
--
1.7.0.4
More information about the wine-patches
mailing list