ws2_32: getsockopt should fail for SO_LINGER and UDP sockets
Alexandre Goujon
ale.goujon at gmail.com
Wed Feb 23 13:37:19 CST 2011
---
dlls/ws2_32/socket.c | 16 +++++++++++++++-
dlls/ws2_32/tests/sock.c | 3 +--
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index f74fd36..1d1bc11 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -2565,7 +2565,7 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level,
case WS_SO_LINGER:
{
struct linger lingval;
- unsigned int len = sizeof(struct linger);
+ unsigned int len = sizeof(struct linger), type, int_len = sizeof(int);
/* struct linger and LINGER have different sizes */
if (!optlen || *optlen < sizeof(LINGER) || !optval)
@@ -2576,6 +2576,20 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level,
if ( (fd = get_sock_fd( s, 0, NULL )) == -1)
return SOCKET_ERROR;
+ if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &int_len) != 0 )
+ {
+ SetLastError((errno == EBADF) ? WSAENOTSOCK : wsaErrno());
+ release_sock_fd( s, fd );
+ return SOCKET_ERROR;
+ }
+
+ if(type == SOCK_DGRAM)
+ {
+ SetLastError(WSAENOPROTOOPT);
+ release_sock_fd( s, fd );
+ return SOCKET_ERROR;
+ }
+
if (getsockopt(fd, SOL_SOCKET, SO_LINGER, &lingval, &len) != 0 )
{
SetLastError((errno == EBADF) ? WSAENOTSOCK : wsaErrno());
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index d2f011f..dfc51df 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -2416,9 +2416,8 @@ static void test_extendedSocketOptions(void)
optlen = sizeof(LINGER);
ret = getsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&linger_val, &optlen);
- todo_wine{
ok(ret == SOCKET_ERROR, "getsockopt should fail for UDP sockets but return value is 0x%08x\n", ret);
- }
+ ok(WSAGetLastError() == WSAENOPROTOOPT, "got %d expected WSAENOPROTOOPT\n", WSAGetLastError() );
closesocket(sock);
--
1.7.0.4
More information about the wine-patches
mailing list