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

This commit is contained in:
Alexandre Goujon 2011-02-22 21:02:22 +01:00 committed by Alexandre Julliard
parent f5eb15a2fe
commit 778757ba74
2 changed files with 6 additions and 4 deletions

View File

@ -4606,6 +4606,10 @@ struct WS_hostent* WINAPI WS_gethostbyname(const char* name)
int locerr = ENOBUFS; int locerr = ENOBUFS;
#endif #endif
char hostname[100]; char hostname[100];
if(!num_startup) {
SetLastError(WSANOTINITIALISED);
return NULL;
}
if( gethostname( hostname, 100) == -1) { if( gethostname( hostname, 100) == -1) {
SetLastError( WSAENOBUFS); /* appropriate ? */ SetLastError( WSAENOBUFS); /* appropriate ? */
return retval; return retval;

View File

@ -834,8 +834,6 @@ out:
} }
/* Tests for WSAStartup */ /* Tests for WSAStartup */
/* This should fail. WSAStartup should be called before any network function is used. */
static void test_WithoutWSAStartup(void) static void test_WithoutWSAStartup(void)
{ {
LPVOID ptr; LPVOID ptr;
@ -843,8 +841,8 @@ static void test_WithoutWSAStartup(void)
WSASetLastError(0xdeadbeef); WSASetLastError(0xdeadbeef);
ptr = gethostbyname("localhost"); ptr = gethostbyname("localhost");
todo_wine ok(ptr == NULL, "gethostbyname() succeeded unexpectedly: %d\n", WSAGetLastError()); ok(ptr == NULL, "gethostbyname() succeeded unexpectedly: %d\n", WSAGetLastError());
todo_wine ok(WSAGetLastError() == WSANOTINITIALISED, "gethostbyname() failed with unexpected error: %d\n", ok(WSAGetLastError() == WSANOTINITIALISED, "gethostbyname() failed with unexpected error: %d\n",
WSAGetLastError()); WSAGetLastError());
} }