fix(IPAddress): windows scoped test #4644

This commit is contained in:
Alex Fabijanic 2024-10-30 22:16:27 -05:00 committed by Aleksandar Fabijanic
parent 59afdc2c04
commit 13ea31f442
2 changed files with 13 additions and 3 deletions

View File

@ -658,10 +658,15 @@ IPv6AddressImpl IPv6AddressImpl::parse(const std::string& addr)
struct addrinfo hints;
std::memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_NUMERICHOST;
// for the reason why this is not AF_INET6, see
// https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/getaddrinfo-fails-error-11001-call-af-inet6-family
hints.ai_family = AF_UNSPEC;
int rc = getaddrinfo(addr.c_str(), NULL, &hints, &pAI);
if (rc == 0)
{
IPv6AddressImpl result = IPv6AddressImpl(&reinterpret_cast<struct sockaddr_in6*>(pAI->ai_addr)->sin6_addr, static_cast<int>(reinterpret_cast<struct sockaddr_in6*>(pAI->ai_addr)->sin6_scope_id));
IPv6AddressImpl result = IPv6AddressImpl(
&reinterpret_cast<struct sockaddr_in6*>(pAI->ai_addr)->sin6_addr,
static_cast<int>(reinterpret_cast<struct sockaddr_in6*>(pAI->ai_addr)->sin6_scope_id));
freeaddrinfo(pAI);
return result;
}

View File

@ -745,14 +745,19 @@ void IPAddressTest::testScoped()
IPAddress ip;
assertFalse (IPAddress::tryParse("fe80::1592:96a0:88bf:d2d7%xyzabc123", ip));
std::string scope;
auto it = m.begin();
auto end = m.end();
for (; it != end; ++it)
{
scope = it->second.adapterName();
#if defined(_WIN32)
int scope = it->second.index();
assertTrue(IPAddress::tryParse(Poco::format("[fe80::1592:96a0:88bf:d2d7%%%d]", scope), ip));
assertTrue(IPAddress::tryParse(Poco::format("fe80::1592:96a0:88bf:d2d7%%%d", scope), ip));
#else
std::string scope = it->second.adapterName();
assertTrue (IPAddress::tryParse(Poco::format("[fe80::1592:96a0:88bf:d2d7%%%s]", scope), ip));
assertTrue (IPAddress::tryParse(Poco::format("fe80::1592:96a0:88bf:d2d7%%%s", scope), ip));
#endif
}
#endif
}