ws2_32/tests: Add tests for IPv6 control messages.

Namely IPV6_HOPLIMIT and IPV6_PKTINFO.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alex Henrie 2021-08-02 23:08:37 -06:00 committed by Alexandre Julliard
parent 42b4061eaf
commit 0e76a54aae
1 changed files with 100 additions and 1 deletions

View File

@ -155,6 +155,7 @@ static DWORD thread_id[1+MAX_CLIENTS];
static HANDLE server_ready;
static HANDLE client_ready[MAX_CLIENTS];
static int client_id;
static GUID WSARecvMsg_GUID = WSAID_WSARECVMSG;
/**************** General utility functions ***************/
@ -1802,7 +1803,6 @@ static void test_ip_pktinfo(void)
ULONG addresses[2] = {inet_addr("127.0.0.1"), htonl(INADDR_ANY)};
char recvbuf[10], pktbuf[512], msg[] = "HELLO";
struct sockaddr_in s1addr, s2addr, s3addr;
GUID WSARecvMsg_GUID = WSAID_WSARECVMSG;
LPFN_WSARECVMSG pWSARecvMsg = NULL;
unsigned int rc, yes = 1;
BOOL foundhdr;
@ -1990,6 +1990,104 @@ static void test_ip_pktinfo(void)
CloseHandle(ov.hEvent);
}
static void test_ipv6_cmsg(void)
{
static const DWORD off = 0;
static const DWORD on = 1;
SOCKADDR_IN6 localhost = {0};
SOCKET client, server;
char payload[] = "HELLO";
char control[100];
WSABUF payload_buf = {sizeof(payload), payload};
WSAMSG msg = {NULL, 0, &payload_buf, 1, {sizeof(control), control}, 0};
WSACMSGHDR *header = (WSACMSGHDR *)control;
LPFN_WSARECVMSG pWSARecvMsg;
INT *hop_limit = (INT *)WSA_CMSG_DATA(header);
IN6_PKTINFO *pkt_info = (IN6_PKTINFO *)WSA_CMSG_DATA(header);
DWORD count, state;
int rc;
localhost.sin6_family = AF_INET6;
localhost.sin6_port = htons(SERVERPORT);
inet_pton(AF_INET6, "::1", &localhost.sin6_addr);
client = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
ok(client != INVALID_SOCKET, "failed to create socket, error %u\n", WSAGetLastError());
server = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
ok(server != INVALID_SOCKET, "failed to create socket, error %u\n", WSAGetLastError());
rc = bind(server, (SOCKADDR *)&localhost, sizeof(localhost));
ok(rc != SOCKET_ERROR, "bind failed, error %u\n", WSAGetLastError());
rc = connect(client, (SOCKADDR *)&localhost, sizeof(localhost));
ok(rc != SOCKET_ERROR, "connect failed, error %u\n", WSAGetLastError());
rc = WSAIoctl(server, SIO_GET_EXTENSION_FUNCTION_POINTER, &WSARecvMsg_GUID, sizeof(WSARecvMsg_GUID),
&pWSARecvMsg, sizeof(pWSARecvMsg), &count, NULL, NULL);
ok(!rc, "failed to get WSARecvMsg, error %u\n", WSAGetLastError());
memset(control, 0, sizeof(control));
msg.Control.len = sizeof(control);
rc = setsockopt(server, IPPROTO_IPV6, IPV6_HOPLIMIT, (const char *)&on, sizeof(on));
todo_wine
ok(!rc, "failed to set IPV6_HOPLIMIT, error %u\n", WSAGetLastError());
state = 0;
count = sizeof(state);
rc = getsockopt(server, IPPROTO_IPV6, IPV6_HOPLIMIT, (char *)&state, (INT *)&count);
todo_wine
ok(!rc, "failed to get IPV6_HOPLIMIT, error %u\n", WSAGetLastError());
todo_wine
ok(state == 1, "expected 1, got %u\n", state);
rc = send(client, payload, sizeof(payload), 0);
ok(rc == sizeof(payload), "send failed, error %u\n", WSAGetLastError());
rc = pWSARecvMsg(server, &msg, &count, NULL, NULL);
ok(!rc, "WSARecvMsg failed, error %u\n", WSAGetLastError());
ok(count == sizeof(payload), "expected length %i, got %i\n", (INT)sizeof(payload), count);
todo_wine
ok(header->cmsg_level == IPPROTO_IPV6, "expected IPPROTO_IPV6, got %i\n", header->cmsg_level);
todo_wine
ok(header->cmsg_type == IPV6_HOPLIMIT, "expected IPV6_HOPLIMIT, got %i\n", header->cmsg_type);
todo_wine
ok(header->cmsg_len == sizeof(*header) + sizeof(INT),
"expected length %i, got %i\n", (INT)(sizeof(*header) + sizeof(INT)), (INT)header->cmsg_len);
todo_wine
ok(*hop_limit >= 32, "expected at least 32, got %i\n", *hop_limit);
setsockopt(server, IPPROTO_IPV6, IPV6_HOPLIMIT, (const char *)&off, sizeof(off));
ok(!rc, "failed to clear IPV6_HOPLIMIT, error %u\n", WSAGetLastError());
memset(control, 0, sizeof(control));
msg.Control.len = sizeof(control);
rc = setsockopt(server, IPPROTO_IPV6, IPV6_PKTINFO, (const char *)&on, sizeof(on));
todo_wine
ok(!rc, "failed to set IPV6_PKTINFO, error %u\n", WSAGetLastError());
state = 0;
count = sizeof(state);
rc = getsockopt(server, IPPROTO_IPV6, IPV6_PKTINFO, (char *)&state, (INT *)&count);
todo_wine
ok(!rc, "failed to get IPV6_PKTINFO, error %u\n", WSAGetLastError());
todo_wine
ok(state == 1, "expected 1, got %u\n", state);
rc = send(client, payload, sizeof(payload), 0);
ok(rc == sizeof(payload), "send failed, error %u\n", WSAGetLastError());
rc = pWSARecvMsg(server, &msg, &count, NULL, NULL);
ok(!rc, "WSARecvMsg failed, error %u\n", WSAGetLastError());
ok(count == sizeof(payload), "expected length %i, got %i\n", (INT)sizeof(payload), count);
todo_wine
ok(header->cmsg_level == IPPROTO_IPV6, "expected IPPROTO_IPV6, got %i\n", header->cmsg_level);
todo_wine
ok(header->cmsg_type == IPV6_PKTINFO, "expected IPV6_PKTINFO, got %i\n", header->cmsg_type);
todo_wine
ok(header->cmsg_len == sizeof(*header) + sizeof(IN6_PKTINFO),
"expected length %i, got %i\n", (INT)(sizeof(*header) + sizeof(IN6_PKTINFO)), (INT)header->cmsg_len);
todo_wine
ok(!memcmp(&pkt_info->ipi6_addr, &localhost.sin6_addr, sizeof(IN6_ADDR)), "expected ::1\n");
rc = setsockopt(server, IPPROTO_IPV6, IPV6_PKTINFO, (const char *)&off, sizeof(off));
todo_wine
ok(!rc, "failed to clear IPV6_PKTINFO, error %u\n", WSAGetLastError());
closesocket(server);
closesocket(client);
}
/************* Array containing the tests to run **********/
#define STD_STREAM_SOCKET \
@ -11385,6 +11483,7 @@ START_TEST( sock )
test_set_getsockopt();
test_so_reuseaddr();
test_ip_pktinfo();
test_ipv6_cmsg();
test_extendedSocketOptions();
test_so_debug();
test_set_only_options();