On 9/27/21 9:40 AM, Alex Henrie wrote:
IP_PKTINFO already had tests, but it doesn't hurt to add a few more. IP_RECVTTL and IP_RECVTCLASS didn't have any tests.
Signed-off-by: Alex Henrie alexhenrie24@gmail.com
dlls/ws2_32/tests/sock.c | 120 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+)
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 8cbb393b542..4105ce624b2 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1984,6 +1984,125 @@ static void test_ip_pktinfo(void) CloseHandle(ov.hEvent); }
+static void test_ipv4_cmsg(void) +{
- static const DWORD off = 0;
- static const DWORD on = 1;
- SOCKADDR_IN 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 *int_data = (INT *)WSA_CMSG_DATA(header);
- IN_PKTINFO *pkt_info = (IN_PKTINFO *)WSA_CMSG_DATA(header);
- DWORD count, state;
- int rc;
- localhost.sin_family = AF_INET;
- localhost.sin_port = htons(SERVERPORT);
- inet_pton(AF_INET, "127.0.0.1", &localhost.sin_addr);
- client = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- ok(client != INVALID_SOCKET, "failed to create socket, error %u\n", WSAGetLastError());
- server = socket(AF_INET, 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_IP, IP_RECVTTL, (const char *)&on, sizeof(on));
+todo_wine
- ok(!rc, "failed to set IP_RECVTTL, error %u\n", WSAGetLastError());
- state = 0;
- count = sizeof(state);
- rc = getsockopt(server, IPPROTO_IP, IP_RECVTTL, (char *)&state, (INT *)&count);
+todo_wine
- ok(!rc, "failed to get IP_RECVTTL, 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);
- ok(header->cmsg_level == IPPROTO_IP, "expected IPPROTO_IP, got %i\n", header->cmsg_level);
+todo_wine
- ok(header->cmsg_type == IP_TTL || broken(header->cmsg_type == IP_HOPLIMIT) /* win8 */,
"expected IP_TTL, got %i\n", header->cmsg_type);
Actually, every version up to and including win10 v1607 returns IP_HOPLIMIT here. I'm also not sure I see a reason to mark it broken; it certainly can't be called incorrect.
+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(*int_data >= 32, "expected at least 32, got %i\n", *int_data);
- setsockopt(server, IPPROTO_IP, IP_RECVTTL, (const char *)&off, sizeof(off));
- ok(!rc, "failed to clear IP_RECVTTL, error %u\n", WSAGetLastError());
- memset(control, 0, sizeof(control));
- msg.Control.len = sizeof(control);
- rc = setsockopt(server, IPPROTO_IP, IP_PKTINFO, (const char *)&on, sizeof(on));
- ok(!rc, "failed to set IP_PKTINFO, error %u\n", WSAGetLastError());
- state = 0;
- count = sizeof(state);
- rc = getsockopt(server, IPPROTO_IP, IP_PKTINFO, (char *)&state, (INT *)&count);
- ok(!rc, "failed to get IP_PKTINFO, error %u\n", WSAGetLastError());
- 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);
- ok(header->cmsg_level == IPPROTO_IP, "expected IPPROTO_IP, got %i\n", header->cmsg_level);
- ok(header->cmsg_type == IP_PKTINFO, "expected IP_PKTINFO, got %i\n", header->cmsg_type);
- ok(header->cmsg_len == sizeof(*header) + sizeof(IN_PKTINFO),
"expected length %i, got %i\n", (INT)(sizeof(*header) + sizeof(IN_PKTINFO)), (INT)header->cmsg_len);
These can be %zu or %Iu. There are many other instances in this patch. There are also many instances of using %i for an unsigned variable.
- ok(!memcmp(&pkt_info->ipi_addr, &localhost.sin_addr, sizeof(IN_ADDR)), "expected 127.0.0.1\n");
- rc = setsockopt(server, IPPROTO_IP, IP_PKTINFO, (const char *)&off, sizeof(off));
- ok(!rc, "failed to clear IP_PKTINFO, error %u\n", WSAGetLastError());
- memset(control, 0, sizeof(control));
- msg.Control.len = sizeof(control);
- rc = setsockopt(server, IPPROTO_IP, IP_RECVTCLASS, (const char *)&on, sizeof(on));
+todo_wine
- ok(!rc, "failed to set IP_RECVTCLASS, error %u\n", WSAGetLastError());
- state = 0;
- count = sizeof(state);
- rc = getsockopt(server, IPPROTO_IP, IP_RECVTCLASS, (char *)&state, (INT *)&count);
+todo_wine
- ok(!rc, "failed to get IP_RECVTCLASS, 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);
- ok(header->cmsg_level == IPPROTO_IP, "expected IPPROTO_IP, got %i\n", header->cmsg_level);
+todo_wine
- ok(header->cmsg_type == IP_TOS || broken(header->cmsg_type == IP_TCLASS) /* win8 */,
"expected IP_TOS, got %i\n", header->cmsg_type);
Same here, every version of Windows up to and including v1607 returns IP_TCLASS.
+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);
- ok(*int_data == 0, "expected 0, got %i\n", *int_data);
- rc = setsockopt(server, IPPROTO_IP, IP_RECVTCLASS, (const char *)&off, sizeof(off));
+todo_wine
- ok(!rc, "failed to clear IP_RECVTCLASS, error %u\n", WSAGetLastError());
- closesocket(server);
- closesocket(client);
+}
- static void test_ipv6_cmsg(void) { static const DWORD off = 0;
@@ -11767,6 +11886,7 @@ START_TEST( sock ) test_set_getsockopt(); test_so_reuseaddr(); test_ip_pktinfo();
- test_ipv4_cmsg(); test_ipv6_cmsg(); test_extendedSocketOptions(); test_so_debug();