.NET 6's HTTP/Socket code queries this. Winsock allows getsockname on the AcceptEx AcceptSocket, but only if SO_UPDATE_ACCEPT_CONTEXT is set.
Signed-off-by: David Curtiss david.curtiss@ni.com
-- v3: Set bound in accept_into_socket instead of changing getsockname ws2_32: Allow getsockname after AcceptEx
From: David Curtiss david.curtiss@ni.com
.NET 6's HTTP/Socket code queries this. Winsock allows getsockname on the AcceptEx AcceptSocket, but only if SO_UPDATE_ACCEPT_CONTEXT is set.
Signed-off-by: David Curtiss david.curtiss@ni.com --- dlls/ws2_32/tests/sock.c | 9 +++++++++ server/sock.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 4a4a3a84e51..7eba12dee37 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -8064,6 +8064,15 @@ static void test_AcceptEx(void) ok(bret, "GetOverlappedResult failed, error %ld\n", GetLastError()); ok(bytesReturned == 0, "bytesReturned isn't supposed to be %ld\n", bytesReturned);
+ /* Try to call getsockname on the acceptor socket. + * + * On Windows, this requires setting SO_UPDATE_ACCEPT_CONTEXT. */ + iret = setsockopt(acceptor, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char *)&listener, sizeof(SOCKET)); + ok(!iret, "Failed to set accept context %ld\n", GetLastError()); + iret = getsockname(acceptor, (struct sockaddr *)&peerAddress, &remoteSize); + ok(!iret, "getsockname failed.\n"); + ok(remoteSize == sizeof(struct sockaddr_in), "got remote size %u\n", remoteSize); + closesocket(connector); connector = INVALID_SOCKET; closesocket(acceptor); diff --git a/server/sock.c b/server/sock.c index 77a88a7fcf7..db63c505770 100644 --- a/server/sock.c +++ b/server/sock.c @@ -2716,7 +2716,7 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) }
case IOCTL_AFD_GETSOCKNAME: - if (!sock->bound) + if (!sock->addr_len) { set_error( STATUS_INVALID_PARAMETER ); return;
From: David Curtiss david.curtiss@ni.com
--- server/sock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/server/sock.c b/server/sock.c index db63c505770..57555c392b8 100644 --- a/server/sock.c +++ b/server/sock.c @@ -1832,6 +1832,7 @@ static int accept_into_socket( struct sock *sock, struct sock *acceptsock ) }
acceptsock->state = SOCK_CONNECTED; + acceptsock->bound = 1; acceptsock->pending_events = 0; acceptsock->reported_events = 0; acceptsock->proto = sock->proto; @@ -2716,7 +2717,7 @@ static void sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) }
case IOCTL_AFD_GETSOCKNAME: - if (!sock->addr_len) + if (!sock->bound) { set_error( STATUS_INVALID_PARAMETER ); return;
Can you please make this a single, self-contained commit, instead of fixing it up with a separate commit? We don't squash anything when merging, and we want to have a sensible commit history.