Commit 569f1ac0 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

ws2_32: Move the getpeername() implementation to ntdll.

This adds todo_wine to a couple of tests; however, these are overly zealous invalid parameter tests, and fixing them is nontrivial. Signed-off-by: 's avatarZebediah Figura <z.figura12@gmail.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 93d001fa
...@@ -1540,6 +1540,32 @@ NTSTATUS sock_ioctl( HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc, void *apc ...@@ -1540,6 +1540,32 @@ NTSTATUS sock_ioctl( HANDLE handle, HANDLE event, PIO_APC_ROUTINE apc, void *apc
break; break;
} }
case IOCTL_AFD_WINE_GETPEERNAME:
{
union unix_sockaddr unix_addr;
socklen_t unix_len = sizeof(unix_addr);
int len;
if ((status = server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL )))
return status;
if (getpeername( fd, &unix_addr.addr, &unix_len ) < 0)
{
status = sock_errno_to_status( errno );
break;
}
len = sockaddr_from_unix( &unix_addr, out_buffer, out_size );
if (out_size < len)
{
status = STATUS_BUFFER_TOO_SMALL;
break;
}
io->Information = len;
status = STATUS_SUCCESS;
break;
}
default: default:
{ {
if ((code >> 16) == FILE_DEVICE_NETWORK) if ((code >> 16) == FILE_DEVICE_NETWORK)
......
...@@ -2077,42 +2077,35 @@ static BOOL WINAPI WS2_DisconnectEx( SOCKET s, OVERLAPPED *overlapped, DWORD fla ...@@ -2077,42 +2077,35 @@ static BOOL WINAPI WS2_DisconnectEx( SOCKET s, OVERLAPPED *overlapped, DWORD fla
return !status; return !status;
} }
/*********************************************************************** /***********************************************************************
* getpeername (WS2_32.5) * getpeername (ws2_32.5)
*/ */
int WINAPI WS_getpeername(SOCKET s, struct WS_sockaddr *name, int *namelen) int WINAPI WS_getpeername( SOCKET s, struct WS_sockaddr *addr, int *len )
{ {
int fd; IO_STATUS_BLOCK io;
int res; NTSTATUS status;
TRACE("socket %04lx, ptr %p, len %08x\n", s, name, namelen ? *namelen : 0);
fd = get_sock_fd( s, 0, NULL ); TRACE( "socket %#lx, addr %p, len %d\n", s, addr, len ? *len : 0 );
res = SOCKET_ERROR;
if (fd != -1) if (!socket_list_find( s ))
{ {
union generic_unix_sockaddr uaddr; WSASetLastError( WSAENOTSOCK );
socklen_t uaddrlen = sizeof(uaddr); return -1;
}
if (getpeername(fd, &uaddr.addr, &uaddrlen) == 0) if (!len)
{ {
if (!name || !namelen) SetLastError( WSAEFAULT );
SetLastError(WSAEFAULT); return -1;
else if (ws_sockaddr_u2ws(&uaddr.addr, name, namelen) != 0)
/* The buffer was too small */
SetLastError(WSAEFAULT);
else
{
res = 0;
TRACE("=> %s\n", debugstr_sockaddr(name));
}
}
else
SetLastError(wsaErrno());
release_sock_fd( s, fd );
} }
return res;
status = NtDeviceIoControlFile( (HANDLE)s, NULL, NULL, NULL, &io,
IOCTL_AFD_WINE_GETPEERNAME, NULL, 0, addr, *len );
if (!status)
*len = io.Information;
SetLastError( NtStatusToWSAError( status ) );
return status ? -1 : 0;
} }
......
...@@ -7752,7 +7752,7 @@ static void test_getpeername(void) ...@@ -7752,7 +7752,7 @@ static void test_getpeername(void)
ret = getpeername(sock, NULL, NULL); ret = getpeername(sock, NULL, NULL);
ok(ret == SOCKET_ERROR, "Expected getpeername to return SOCKET_ERROR, got %d\n", ret); ok(ret == SOCKET_ERROR, "Expected getpeername to return SOCKET_ERROR, got %d\n", ret);
ok(WSAGetLastError() == WSAENOTCONN, todo_wine ok(WSAGetLastError() == WSAENOTCONN,
"Expected WSAGetLastError() to return WSAENOTCONN, got %d\n", WSAGetLastError()); "Expected WSAGetLastError() to return WSAENOTCONN, got %d\n", WSAGetLastError());
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
...@@ -7767,7 +7767,7 @@ static void test_getpeername(void) ...@@ -7767,7 +7767,7 @@ static void test_getpeername(void)
ret = getpeername(sock, NULL, NULL); ret = getpeername(sock, NULL, NULL);
ok(ret == SOCKET_ERROR, "Expected getpeername to return SOCKET_ERROR, got %d\n", ret); ok(ret == SOCKET_ERROR, "Expected getpeername to return SOCKET_ERROR, got %d\n", ret);
ok(WSAGetLastError() == WSAENOTCONN, todo_wine ok(WSAGetLastError() == WSAENOTCONN,
"Expected WSAGetLastError() to return WSAENOTCONN, got %d\n", WSAGetLastError()); "Expected WSAGetLastError() to return WSAENOTCONN, got %d\n", WSAGetLastError());
ret = connect(sock, (struct sockaddr*)&sa, sizeof(sa)); ret = connect(sock, (struct sockaddr*)&sa, sizeof(sa));
......
...@@ -156,6 +156,7 @@ struct afd_get_events_params ...@@ -156,6 +156,7 @@ struct afd_get_events_params
#define IOCTL_AFD_WINE_GET_INTERFACE_LIST CTL_CODE(FILE_DEVICE_NETWORK, 213, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_AFD_WINE_GET_INTERFACE_LIST CTL_CODE(FILE_DEVICE_NETWORK, 213, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_AFD_WINE_KEEPALIVE_VALS CTL_CODE(FILE_DEVICE_NETWORK, 214, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_AFD_WINE_KEEPALIVE_VALS CTL_CODE(FILE_DEVICE_NETWORK, 214, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_AFD_WINE_MESSAGE_SELECT CTL_CODE(FILE_DEVICE_NETWORK, 215, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_AFD_WINE_MESSAGE_SELECT CTL_CODE(FILE_DEVICE_NETWORK, 215, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_AFD_WINE_GETPEERNAME CTL_CODE(FILE_DEVICE_NETWORK, 216, METHOD_BUFFERED, FILE_ANY_ACCESS)
struct afd_create_params struct afd_create_params
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment