mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-31 14:39:53 +01:00
fix(IPAddress): windows scoped test #4644
This commit is contained in:
parent
59afdc2c04
commit
13ea31f442
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user