.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 d501930b32d..93f4f420c66 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -7718,6 +7718,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 b403541fcbf..22fcce50312 100644 --- a/server/sock.c +++ b/server/sock.c @@ -2701,7 +2701,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;