--- dlls/ws2_32/socket.c | 17 +++++++++-------- dlls/ws2_32/tests/sock.c | 10 ++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 262171ebab0..1d0caab5d1c 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -4253,13 +4253,14 @@ WS_u_short WINAPI WS_htons(WS_u_short hostshort)
/*********************************************************************** * WSAHtonl (WS2_32.46) - * From MSDN description of error codes, this function should also - * check if WinSock has been initialized and the socket is a valid - * socket. But why? This function only translates a host byte order - * u_long into a network byte order u_long... */ int WINAPI WSAHtonl(SOCKET s, WS_u_long hostlong, WS_u_long *lpnetlong) { + if(!num_startup){ + SetLastError(WSANOTINITIALISED); + return SOCKET_ERROR; + } + if (lpnetlong) { *lpnetlong = htonl(hostlong); @@ -4271,13 +4272,13 @@ int WINAPI WSAHtonl(SOCKET s, WS_u_long hostlong, WS_u_long *lpnetlong)
/*********************************************************************** * WSAHtons (WS2_32.47) - * From MSDN description of error codes, this function should also - * check if WinSock has been initialized and the socket is a valid - * socket. But why? This function only translates a host byte order - * u_short into a network byte order u_short... */ int WINAPI WSAHtons(SOCKET s, WS_u_short hostshort, WS_u_short *lpnetshort) { + if(!num_startup){ + SetLastError(WSANOTINITIALISED); + return SOCKET_ERROR; + }
if (lpnetshort) { diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 5a1a271b099..90987532b03 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1089,6 +1089,16 @@ static void test_WithoutWSAStartup(void) ok(gethostbyname("localhost") == NULL, "gethostbyname() succeeded unexpectedly\n"); err = WSAGetLastError(); ok(err == WSANOTINITIALISED, "Expected 10093, received %d\n", err); + + WSASetLastError(0xdeadbeef); + ok(SOCKET_ERROR == WSAHtonl(0, 0, 0), "Expected SOCKET_ERROR, but was successful\n"); + err = WSAGetLastError(); + ok(err == WSANOTINITIALISED, "Expected 10093, received %d\n", err); + + WSASetLastError(0xdeadbeef); + ok(SOCKET_ERROR == WSAHtons(0, 0, 0), "Expected SOCKET_ERROR, but was successful\n"); + err = WSAGetLastError(); + ok(err == WSANOTINITIALISED, "Expected 10093, received %d\n", err); }
static void test_WithWSAStartup(void)
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=88928
Your paranoid android.
=== w8 (32 bit report) ===
ws2_32: sock.c:6306: Test failed: wrong count 0 sock.c:6315: Test failed: wrong count 8
Hello Walter, thanks for the patch!
Note that all patches need a Signed-off-by tag, to denote that the patch meets the technical and legal requirements of the project.
With respect to the content of this patch, do you have an application that needs this? Failing that, I'm not sure it's worth adding to the code. Yes, the tests confirm it, but it's more code to add for no good reason.
On 4/18/21 3:36 PM, Walter Procyk wrote:
dlls/ws2_32/socket.c | 17 +++++++++-------- dlls/ws2_32/tests/sock.c | 10 ++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 262171ebab0..1d0caab5d1c 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -4253,13 +4253,14 @@ WS_u_short WINAPI WS_htons(WS_u_short hostshort)
/***********************************************************************
WSAHtonl (WS2_32.46)
- From MSDN description of error codes, this function should also
- check if WinSock has been initialized and the socket is a valid
- socket. But why? This function only translates a host byte order
*/ int WINAPI WSAHtonl(SOCKET s, WS_u_long hostlong, WS_u_long *lpnetlong) {
- u_long into a network byte order u_long...
- if(!num_startup){
SetLastError(WSANOTINITIALISED);
return SOCKET_ERROR;
- }
if (lpnetlong) { *lpnetlong = htonl(hostlong);
@@ -4271,13 +4272,13 @@ int WINAPI WSAHtonl(SOCKET s, WS_u_long hostlong, WS_u_long *lpnetlong)
/***********************************************************************
WSAHtons (WS2_32.47)
- From MSDN description of error codes, this function should also
- check if WinSock has been initialized and the socket is a valid
- socket. But why? This function only translates a host byte order
*/ int WINAPI WSAHtons(SOCKET s, WS_u_short hostshort, WS_u_short *lpnetshort) {
- u_short into a network byte order u_short...
if(!num_startup){
SetLastError(WSANOTINITIALISED);
return SOCKET_ERROR;
}
if (lpnetshort) {
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 5a1a271b099..90987532b03 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1089,6 +1089,16 @@ static void test_WithoutWSAStartup(void) ok(gethostbyname("localhost") == NULL, "gethostbyname() succeeded unexpectedly\n"); err = WSAGetLastError(); ok(err == WSANOTINITIALISED, "Expected 10093, received %d\n", err);
WSASetLastError(0xdeadbeef);
ok(SOCKET_ERROR == WSAHtonl(0, 0, 0), "Expected SOCKET_ERROR, but was successful\n");
err = WSAGetLastError();
ok(err == WSANOTINITIALISED, "Expected 10093, received %d\n", err);
WSASetLastError(0xdeadbeef);
ok(SOCKET_ERROR == WSAHtons(0, 0, 0), "Expected SOCKET_ERROR, but was successful\n");
err = WSAGetLastError();
ok(err == WSANOTINITIALISED, "Expected 10093, received %d\n", err); }
static void test_WithWSAStartup(void)