Index: winetests/ntdll/rtl.c =================================================================== --- winetests/ntdll/rtl.c (revision 65752) +++ winetests/ntdll/rtl.c (working copy) @@ -25,6 +25,7 @@ #include "ntdll_test.h" #include "inaddr.h" +#include "in6addr.h" #ifndef __WINE_WINTERNL_H @@ -89,6 +90,9 @@ static CHAR * (WINAPI *pRtlIpv4AddressToStringA)(const IN_ADDR *, LPSTR); static NTSTATUS (WINAPI *pRtlIpv4AddressToStringExA)(const IN_ADDR *, USHORT, LPSTR, PULONG); static NTSTATUS (WINAPI *pRtlIpv4StringToAddressA)(PCSTR, BOOLEAN, PCSTR *, IN_ADDR *); +static NTSTATUS (WINAPI *pRtlIpv4StringToAddressExA)(PCTSTR, BOOLEAN, IN_ADDR *, PUSHORT); +static NTSTATUS (WINAPI *pRtlIpv6StringToAddressA)(PCSTR, PCSTR *, struct in6_addr *); +static NTSTATUS (WINAPI *pRtlIpv6StringToAddressExA)(const PCHAR AddressString, struct in6_addr *, PULONG, PUSHORT); static NTSTATUS (WINAPI *pLdrAddRefDll)(ULONG, HMODULE); static NTSTATUS (WINAPI *pLdrLockLoaderLock)(ULONG, ULONG*, ULONG_PTR*); static NTSTATUS (WINAPI *pLdrUnlockLoaderLock)(ULONG, ULONG_PTR); @@ -136,6 +140,9 @@ pRtlIpv4AddressToStringA = (void *)GetProcAddress(hntdll, "RtlIpv4AddressToStringA"); pRtlIpv4AddressToStringExA = (void *)GetProcAddress(hntdll, "RtlIpv4AddressToStringExA"); pRtlIpv4StringToAddressA = (void *)GetProcAddress(hntdll, "RtlIpv4StringToAddressA"); + pRtlIpv4StringToAddressExA = (void *)GetProcAddress(hntdll, "RtlIpv4StringToAddressExA"); + pRtlIpv6StringToAddressA = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressA"); + pRtlIpv6StringToAddressExA = (void *)GetProcAddress(hntdll, "RtlIpv6StringToAddressExA"); pLdrAddRefDll = (void *)GetProcAddress(hntdll, "LdrAddRefDll"); pLdrLockLoaderLock = (void *)GetProcAddress(hntdll, "LdrLockLoaderLock"); pLdrUnlockLoaderLock = (void *)GetProcAddress(hntdll, "LdrUnlockLoaderLock"); @@ -1492,6 +1499,289 @@ } } +static void test_RtlIpv4StringToAddressEx(void) +{ + NTSTATUS res; + IN_ADDR ip, expected_ip; + USHORT port; + struct + { + PCSTR address; + NTSTATUS res; + int ip[4]; + USHORT port; + } tests[] = + { + { "", STATUS_INVALID_PARAMETER, { -1 }, 0xdead }, + { " ", STATUS_INVALID_PARAMETER, { -1 }, 0xdead }, + { "1.1.1.1:", STATUS_INVALID_PARAMETER, { 1, 1, 1, 1 }, 0xdead }, + { "1.1.1.1+", STATUS_INVALID_PARAMETER, { 1, 1, 1, 1 }, 0xdead }, + { "1.1.1.1:1", STATUS_SUCCESS, { 1, 1, 1, 1 }, 0x100 }, + { "0.0.0.0:0", STATUS_INVALID_PARAMETER, { 0, 0, 0, 0 }, 0xdead }, + { "0.0.0.0:1", STATUS_SUCCESS, { 0, 0, 0, 0 }, 0x100 }, + { "1.2.3.4:65535", STATUS_SUCCESS, { 1, 2, 3, 4 }, 65535 }, + { "1.2.3.4:65536", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead }, + { "1.2.3.4:0xffff", STATUS_SUCCESS, { 1, 2, 3, 4 }, 65535 }, + { "1.2.3.4:0XfFfF", STATUS_SUCCESS, { 1, 2, 3, 4 }, 65535 }, + { "1.2.3.4:011064", STATUS_SUCCESS, { 1, 2, 3, 4 }, 0x3412 }, + { "1.2.3.4:1234a", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead }, + { "1.2.3.4:1234+", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead }, + { "1.2.3.4: 1234", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead }, + { "1.2.3.4:\t1234", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead }, + }; + const int testcount = sizeof(tests) / sizeof(tests[0]); + int i, Strict; + + if (!pRtlIpv4StringToAddressExA) + { + skip("RtlIpv4StringToAddressEx not available\n"); + return; + } + + // do not crash, and do not touch the ip / port. + ip.S_un.S_addr = 0xabababab; + port = 0xdead; + res = pRtlIpv4StringToAddressExA(NULL, FALSE, &ip, &port); + ok(res == STATUS_INVALID_PARAMETER, + "[null address] res = 0x%08x, expected 0x%08x\n", + res, STATUS_INVALID_PARAMETER); + ok(ip.S_un.S_addr == 0xabababab, "RtlIpv4StringToAddressExA should not touch the ip!, ip == %x\n", ip.S_un.S_addr); + ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port); + + port = 0xdead; + res = pRtlIpv4StringToAddressExA("1.1.1.1", FALSE, NULL, &port); + ok(res == STATUS_INVALID_PARAMETER, + "[null ip] res = 0x%08x, expected 0x%08x\n", + res, STATUS_INVALID_PARAMETER); + ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port); + + ip.S_un.S_addr = 0xabababab; + port = 0xdead; + res = pRtlIpv4StringToAddressExA("1.1.1.1", FALSE, &ip, NULL); + ok(res == STATUS_INVALID_PARAMETER, + "[null port] res = 0x%08x, expected 0x%08x\n", + res, STATUS_INVALID_PARAMETER); + ok(ip.S_un.S_addr == 0xabababab, "RtlIpv4StringToAddressExA should not touch the ip!, ip == %x\n", ip.S_un.S_addr); + ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port); + + for (i = 0; i < testcount; i++) + { + // Strict is only relevant for the ip address, so make sure that it does not influence the port + for (Strict = 0; Strict < 2; Strict++) + { + ip.S_un.S_addr = 0xabababab; + port = 0xdead; + res = pRtlIpv4StringToAddressExA(tests[i].address, Strict, &ip, &port); + ok(res == tests[i].res, + "[%s] res = 0x%08x, expected 0x%08x\n", + tests[i].address, res, tests[i].res); + if (tests[i].ip[0] == -1) + { + expected_ip.S_un.S_addr = 0xabababab; + } + else + { + expected_ip.S_un.S_un_b.s_b1 = tests[i].ip[0]; + expected_ip.S_un.S_un_b.s_b2 = tests[i].ip[1]; + expected_ip.S_un.S_un_b.s_b3 = tests[i].ip[2]; + expected_ip.S_un.S_un_b.s_b4 = tests[i].ip[3]; + } + ok(ip.S_un.S_addr == expected_ip.S_un.S_addr, + "[%s] ip = %08x, expected %08x\n", + tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr); + ok(port == tests[i].port, + "[%s] port = %u, expected %u\n", + tests[i].address, port, tests[i].port); + } + } +} + +// ipv6 addresses from https://github.com/beaugunderson/javascript-ipv6/tree/master/test/data +static void test_RtlIpv6StringToAddress(void) +{ + NTSTATUS res; + IN6_ADDR ip, expected_ip; + PCSTR terminator; + CHAR dummy; + struct + { + PCSTR address; + NTSTATUS res; + int terminator_offset; + int ip[8]; + } tests[] = + { + // according to the github, all these should succeed: + { "0000:0000:0000:0000:0000:0000:0000:0000", STATUS_SUCCESS, 39, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "0000:0000:0000:0000:0000:0000:0000:0001", STATUS_SUCCESS, 39, { 0, 0, 0, 0, 0, 0, 0, 0x100 } }, + { "0:0:0:0:0:0:0:0", STATUS_SUCCESS, 15, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "0:0:0:0:0:0:0:1", STATUS_SUCCESS, 15, { 0, 0, 0, 0, 0, 0, 0, 0x100 } }, + { "0:0:0:0:0:0:0::", STATUS_INVALID_PARAMETER, 13, { 0, 0, 0, 0, 0, 0, 0xabab, 0xabab } }, + { "0:0:0:0:0:0:13.1.68.3", STATUS_SUCCESS, 21, { 0, 0, 0, 0, 0, 0, 0x10d, 0x344 } }, + { "0:0:0:0:0:0::", STATUS_SUCCESS, 13, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "0:0:0:0:0::", STATUS_SUCCESS, 11, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "0:0:0:0:0:FFFF:129.144.52.38", STATUS_SUCCESS, 28, { 0, 0, 0, 0, 0, 0xffff, 0x9081, 0x2634 } }, + { "0::", STATUS_SUCCESS, 3, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "0:1:2:3:4:5:6:7", STATUS_SUCCESS, 15, { 0, 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700 } }, + { "1080:0:0:0:8:800:200c:417a", STATUS_SUCCESS, 26, { 0x8010, 0, 0, 0, 0x800, 0x8, 0x0c20, 0x7a41 } }, + { "0:a:b:c:d:e:f::", STATUS_INVALID_PARAMETER, 13, { 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00, 0xabab, 0xabab } }, + { "1111:2222:3333:4444:5555:6666:123.123.123.123", STATUS_SUCCESS, 45, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } }, + { "1111:2222:3333:4444:5555:6666:7777:8888", STATUS_SUCCESS, 39, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } }, + { "1111:2222:3333:4444:5555:6666:7777::", STATUS_INVALID_PARAMETER, 34, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0xabab, 0xabab } }, + { "1111:2222:3333:4444:5555:6666::", STATUS_SUCCESS, 31, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0 } }, + { "1111:2222:3333:4444:5555:6666::8888", STATUS_SUCCESS, 35, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0, 0x8888 } }, + { "1111:2222:3333:4444:5555::", STATUS_SUCCESS, 26, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0 } }, + { "1111:2222:3333:4444:5555::123.123.123.123", STATUS_SUCCESS, 41, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7b7b, 0x7b7b } }, + { "1111:2222:3333:4444:5555::7777:8888", STATUS_SUCCESS, 35, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0x7777, 0x8888 } }, + { "1111:2222:3333:4444:5555::8888", STATUS_SUCCESS, 30, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0, 0, 0x8888 } }, + { "1111::", STATUS_SUCCESS, 6, { 0x1111, 0, 0, 0, 0, 0, 0, 0 } }, + { "1111::123.123.123.123", STATUS_SUCCESS, 21, { 0x1111, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } }, + { "1111::3333:4444:5555:6666:123.123.123.123", STATUS_SUCCESS, 41, { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } }, + { "1111::3333:4444:5555:6666:7777:8888", STATUS_SUCCESS, 35, { 0x1111, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } }, + { "1111::4444:5555:6666:123.123.123.123", STATUS_SUCCESS, 36, { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7b7b, 0x7b7b } }, + { "1111::4444:5555:6666:7777:8888", STATUS_SUCCESS, 30, { 0x1111, 0, 0, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } }, + { "1111::5555:6666:123.123.123.123", STATUS_SUCCESS, 31, { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7b7b, 0x7b7b } }, + { "1111::5555:6666:7777:8888", STATUS_SUCCESS, 25, { 0x1111, 0, 0, 0, 0x5555, 0x6666, 0x7777, 0x8888 } }, + { "1111::6666:123.123.123.123", STATUS_SUCCESS, 26, { 0x1111, 0, 0, 0, 0, 0x6666, 0x7b7b, 0x7b7b } }, + { "1111::6666:7777:8888", STATUS_SUCCESS, 20, { 0x1111, 0, 0, 0, 0, 0x6666, 0x7777, 0x8888 } }, + { "1111::7777:8888", STATUS_SUCCESS, 15, { 0x1111, 0, 0, 0, 0, 0, 0x7777, 0x8888 } }, + { "1111::8888", STATUS_SUCCESS, 10, { 0x1111, 0, 0, 0, 0, 0, 0, 0x8888 } }, + { "1:2:3:4:5:6:1.2.3.4", STATUS_SUCCESS, 19, { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x201, 0x403 } }, + { "1:2:3:4:5:6:7:8", STATUS_SUCCESS, 15, { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 0x800 } }, + { "1:2:3:4:5:6::", STATUS_SUCCESS, 13, { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0 } }, + { "1:2:3:4:5:6::8", STATUS_SUCCESS, 14, { 0x100, 0x200, 0x300, 0x400, 0x500, 0x600, 0, 0x800 } }, + { "2001:0000:1234:0000:0000:C1C0:ABCD:0876", STATUS_SUCCESS, 39, { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 } }, + { "2001:0000:4136:e378:8000:63bf:3fff:fdd2", STATUS_SUCCESS, 39, { 0x120, 0, 0x3641, 0x78e3, 0x80, 0xbf63, 0xff3f, 0xd2fd } }, + { "2001:0db8:0:0:0:0:1428:57ab", STATUS_SUCCESS, 27, { 0x120, 0xb80d, 0, 0, 0, 0, 0x2814, 0xab57 } }, + { "2001:0db8:1234:ffff:ffff:ffff:ffff:ffff", STATUS_SUCCESS, 39, { 0x120, 0xb80d, 0x3412, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } }, + { "2001::CE49:7601:2CAD:DFFF:7C94:FFFE", STATUS_SUCCESS, 35, { 0x120, 0, 0x49ce, 0x176, 0xad2c, 0xffdf, 0x947c, 0xfeff } }, + { "2001:db8:85a3::8a2e:370:7334", STATUS_SUCCESS, 28, { 0x120, 0xb80d, 0xa385, 0, 0, 0x2e8a, 0x7003, 0x3473 } }, + { "3ffe:0b00:0000:0000:0001:0000:0000:000a", STATUS_SUCCESS, 39, { 0xfe3f, 0xb, 0, 0, 0x100, 0, 0, 0xa00 } }, + { "::", STATUS_SUCCESS, 2, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::0", STATUS_SUCCESS, 3, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::0:0", STATUS_SUCCESS, 5, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::0:0:0", STATUS_SUCCESS, 7, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::0:0:0:0", STATUS_SUCCESS, 9, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::0:0:0:0:0", STATUS_SUCCESS, 11, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::0:0:0:0:0:0", STATUS_SUCCESS, 13, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::0:0:0:0:0:0:0", STATUS_SUCCESS, 13, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::0:a:b:c:d:e:f", STATUS_SUCCESS, 13, { 0, 0, 0, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00 } }, + { "::123.123.123.123", STATUS_SUCCESS, 17, { 0, 0, 0, 0, 0, 0, 0x7b7b, 0x7b7b } }, + { "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", STATUS_SUCCESS, 39, { 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff } }, + + // and all these should fail: + { "':10.0.0.1", STATUS_INVALID_PARAMETER, 0, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "-1", STATUS_INVALID_PARAMETER, 0, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "02001:0000:1234:0000:0000:C1C0:ABCD:0876", STATUS_INVALID_PARAMETER, -1, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1.2.3.4", STATUS_INVALID_PARAMETER, 7, { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1.2.3.4:1111::5555", STATUS_INVALID_PARAMETER, 7, { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1.2.3.4::5555", STATUS_INVALID_PARAMETER, 7, { 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "11112222:3333:4444:5555:6666:1.2.3.4", STATUS_INVALID_PARAMETER, -1, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "11112222:3333:4444:5555:6666:7777:8888", STATUS_INVALID_PARAMETER, -1, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1111", STATUS_INVALID_PARAMETER, 4, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1111:22223333:4444:5555:6666:1.2.3.4", STATUS_INVALID_PARAMETER, -1, { 0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1111:22223333:4444:5555:6666:7777:8888", STATUS_INVALID_PARAMETER, -1, { 0x1111, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1111:2222:", STATUS_INVALID_PARAMETER, 10, { 0x1111, 0x2222, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1111:2222:1.2.3.4", STATUS_INVALID_PARAMETER, 17, { 0x1111, 0x2222, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1111:2222:3333", STATUS_INVALID_PARAMETER, 14, { 0x1111, 0x2222, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1111:2222:3333:4444:5555:6666:7777:1.2.3.4", STATUS_SUCCESS, 36, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x100 } }, + { "1111:2222:3333:4444:5555:6666:7777:8888:", STATUS_SUCCESS, 39, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } }, + { "1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4",STATUS_SUCCESS, 39, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } }, + { "1111:2222:3333:4444:5555:6666:7777:8888:9999", STATUS_SUCCESS, 39, { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888 } }, + { "1111:2222:::", STATUS_SUCCESS, 11, { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 } }, + { "1111::5555:", STATUS_INVALID_PARAMETER, 11, { 0x1111, 0x5555, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1111::3333:4444:5555:6666:7777::", STATUS_SUCCESS, 30, { 0x1111, 0, 0, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777 } }, + { "1111:2222:::4444:5555:6666:1.2.3.4", STATUS_SUCCESS, 11, { 0x1111, 0x2222, 0, 0, 0, 0, 0, 0 } }, + { "1111::3333::5555:6666:1.2.3.4", STATUS_SUCCESS, 10, { 0x1111, 0, 0, 0, 0, 0, 0, 0x3333 } }, + { "12345::6:7:8", STATUS_INVALID_PARAMETER, -1, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1::1.2.256.4", STATUS_INVALID_PARAMETER, -1, { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1::1.2.3.256", STATUS_INVALID_PARAMETER, 12, { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1::1.2.3.300", STATUS_INVALID_PARAMETER, 12, { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1::1.2.3.900", STATUS_INVALID_PARAMETER, 12, { 0x100, 0x201, 0xab03, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1::1.2.300.4", STATUS_INVALID_PARAMETER, -1, { 0x100, 0x201, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1::1.256.3.4", STATUS_INVALID_PARAMETER, -1, { 0x100, 0xab01, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1::256.2.3.4", STATUS_INVALID_PARAMETER, -1, { 0x100, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "1::2::3", STATUS_SUCCESS, 4, { 0x100, 0, 0, 0, 0, 0, 0, 0x200 } }, + { "2001:0000:1234: 0000:0000:C1C0:ABCD:0876", STATUS_INVALID_PARAMETER, 15, { 0x120, 0, 0x3412, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "2001:0000:1234:0000:0000:C1C0:ABCD:0876 0", STATUS_SUCCESS, 39, { 0x120, 0, 0x3412, 0, 0, 0xc0c1, 0xcdab, 0x7608 } }, + { "2001:1:1:1:1:1:255Z255X255Y255", STATUS_INVALID_PARAMETER, 18, { 0x120, 0x100, 0x100, 0x100, 0x100, 0x100, 0xabab, 0xabab } }, + { "2001::FFD3::57ab", STATUS_SUCCESS, 10, { 0x120, 0, 0, 0, 0, 0, 0, 0xd3ff } }, + { ":", STATUS_INVALID_PARAMETER, 0, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { ":1111:2222:3333:4444:5555:6666:1.2.3.4", STATUS_INVALID_PARAMETER, 0, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { ":1111:2222:3333:4444:5555:6666:7777:8888", STATUS_INVALID_PARAMETER, 0, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { ":1111::", STATUS_INVALID_PARAMETER, 0, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + { "::-1", STATUS_SUCCESS, 2, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::.", STATUS_SUCCESS, 2, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::..", STATUS_SUCCESS, 2, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "::...", STATUS_SUCCESS, 2, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + { "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4", STATUS_INVALID_PARAMETER, 0, { 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab, 0xabab } }, + // windows disagrees with that... + // it also seems to directly operate on the ipv6 struct, and sometimes forgets to update the terminator. + }; + const int testcount = sizeof(tests) / sizeof(tests[0]); + int i, j; + + if (!pRtlIpv6StringToAddressA) + { + skip("RtlIpv6StringToAddress not available\n"); + return; + } + + // sanity check + ok(sizeof(ip._S6_un) == (sizeof(USHORT)* 8), "sizeof(ip._S6_un)\n"); + + for (i = 0; i < testcount; i++) + { + terminator = &dummy; + for (j = 0; j < 8; ++j) + ip.s6_words[j] = 0xabab; + res = pRtlIpv6StringToAddressA(tests[i].address, &terminator, &ip); + ok(res == tests[i].res, + "[%s] res = 0x%08x, expected 0x%08x\n", + tests[i].address, res, tests[i].res); + if (tests[i].terminator_offset < 0) + { + ok(terminator == &dummy, + "[%s] terminator = %p, expected it not to change\n", + tests[i].address, terminator, tests[i].address + tests[i].terminator_offset, (int)(terminator - tests[i].address)); + } + else + { + ok(terminator == tests[i].address + tests[i].terminator_offset, + "[%s] terminator = %p, expected %p\n", + tests[i].address, terminator, tests[i].address + tests[i].terminator_offset); + } + if (tests[i].ip[0] == -1) + { + for (j = 0; j < 8; ++j) + expected_ip.s6_words[j] = 0xabab; + } + else + { + for (j = 0; j < 8; ++j) + expected_ip.s6_words[j] = tests[i].ip[j]; + } + ok(!memcmp(ip.s6_addr, expected_ip.s6_addr, sizeof(ip._S6_un)), + "[%s] ip = %x:%x:%x:%x:%x:%x:%x:%x, expected %x:%x:%x:%x:%x:%x:%x:%x\n", + tests[i].address, + ip.s6_words[0], ip.s6_words[1], ip.s6_words[2], ip.s6_words[3], + ip.s6_words[4], ip.s6_words[5], ip.s6_words[6], ip.s6_words[7], + expected_ip.s6_words[0], expected_ip.s6_words[1], expected_ip.s6_words[2], expected_ip.s6_words[3], + expected_ip.s6_words[4], expected_ip.s6_words[5], expected_ip.s6_words[6], expected_ip.s6_words[7]); + } +} + +static void test_RtlIpv6StringToAddressEx(void) +{ + if (!pRtlIpv6StringToAddressExA) + { + skip("RtlIpv6StringToAddressEx not available\n"); + return; + } + skip("No tests yet for RtlIpv6StringToAddressEx\n"); +} + + static void test_LdrAddRefDll(void) { HMODULE mod, mod2; @@ -1631,6 +1921,9 @@ test_RtlIpv4AddressToString(); test_RtlIpv4AddressToStringEx(); test_RtlIpv4StringToAddress(); + test_RtlIpv4StringToAddressEx(); + test_RtlIpv6StringToAddress(); + test_RtlIpv6StringToAddressEx(); test_LdrAddRefDll(); test_LdrLockLoaderLock(); }