[PATCH] ws2_32/tests: Test getaddrinfo() when we only have local IPv6 address.

Ziqing Hui zhui at codeweavers.com
Wed Mar 2 03:57:28 CST 2022


Signed-off-by: Ziqing Hui <zhui at codeweavers.com>
---
 dlls/ws2_32/tests/protocol.c | 69 ++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/dlls/ws2_32/tests/protocol.c b/dlls/ws2_32/tests/protocol.c
index 374fa01789d..7a1c1ff72b6 100644
--- a/dlls/ws2_32/tests/protocol.c
+++ b/dlls/ws2_32/tests/protocol.c
@@ -2035,6 +2035,25 @@ static void compare_addrinfo(ADDRINFO *a, ADDRINFO *b)
     ok(!a && !b, "Expected both addresses null (%p != %p)\n", a, b);
 }
 
+static BOOL is_ipv6_local(SOCKADDR_IN6 *addr)
+{
+    IN6_ADDR *a = &addr->sin6_addr;
+    return ((a->s6_words[0] == 0) && (a->s6_words[1] == 0) && (a->s6_words[2] == 0) && (a->s6_words[3] == 0) &&
+            (a->s6_words[4] == 0) && (a->s6_words[5] == 0) && (a->s6_words[6] == 0) && (a->s6_words[7] == 0x0100)) ||
+           ((a->s6_bytes[0] == 0xfe) && ((a->s6_bytes[1] & 0xc0) == 0x80));
+}
+
+static BOOL ipv6_found(ADDRINFOA *addr)
+{
+    ADDRINFOA *p;
+    for (p = addr; p; p = p->ai_next)
+    {
+        if (p->ai_family == AF_INET6)
+            return TRUE;
+    }
+    return FALSE;
+}
+
 static void test_getaddrinfo(void)
 {
     int i, ret;
@@ -2042,6 +2061,7 @@ static void test_getaddrinfo(void)
     SOCKADDR_IN *sockaddr;
     CHAR name[256], *ip;
     DWORD size = sizeof(name);
+    BOOL has_ipv6_addr;
 
     memset(&hint, 0, sizeof(ADDRINFOA));
     GetComputerNameExA( ComputerNamePhysicalDnsHostname, name, &size );
@@ -2309,6 +2329,55 @@ static void test_getaddrinfo(void)
     ok(sockaddr->sin_family == AF_INET, "ai_addr->sin_family == %d\n", sockaddr->sin_family);
     ok(sockaddr->sin_port == 0, "ai_addr->sin_port == %d\n", sockaddr->sin_port);
     freeaddrinfo(result);
+
+    /* Check whether we have global IPv6 address */
+    result = NULL;
+    ret = getaddrinfo("", NULL, NULL, &result);
+    ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
+    has_ipv6_addr = FALSE;
+    for (p = result; p; p = p->ai_next)
+    {
+        if (p->ai_family == AF_INET6 && !is_ipv6_local((SOCKADDR_IN6 *)p->ai_addr))
+        {
+            has_ipv6_addr = TRUE;
+            break;
+        }
+    }
+    freeaddrinfo(result);
+
+    result = NULL;
+    ret = getaddrinfo("dns.msftncsi.com", NULL, NULL, &result);
+    ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
+    if (!has_ipv6_addr)
+        todo_wine ok(!ipv6_found(result), "IPv6 address is returned.\n");
+    freeaddrinfo(result);
+
+    for (i = 0; i < ARRAY_SIZE(hinttests); i++)
+    {
+        if (hinttests[i].family != AF_UNSPEC || hinttests[i].error) continue;
+        winetest_push_context("Test %u", i);
+
+        hint.ai_flags = 0;
+        hint.ai_family = hinttests[i].family;
+        hint.ai_socktype = hinttests[i].socktype;
+        hint.ai_protocol = hinttests[i].protocol;
+
+        result = NULL;
+        ret = getaddrinfo("dns.msftncsi.com", NULL, &hint, &result);
+        ok(!ret, "Got unexpected ret %d\n", ret);
+        if (!has_ipv6_addr)
+            todo_wine ok(!ipv6_found(result), "IPv6 address is returned.\n");
+        freeaddrinfo(result);
+
+        hint.ai_family = AF_INET6;
+        result = NULL;
+        ret = getaddrinfo("dns.msftncsi.com", NULL, &hint, &result);
+        if (!has_ipv6_addr)
+            todo_wine ok(ret == WSANO_DATA, "Got unexpected ret %d\n", ret);
+        freeaddrinfo(result);
+
+        winetest_pop_context();
+    }
 }
 
 static void test_dns(void)
-- 
2.25.1




More information about the wine-devel mailing list