-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TryParse scoped ipv6 addressess #3896
Comments
Hi, @diridari ! IPv6AddressImpl IPv6AddressImpl::parse(const std::string& addr)
{
if (addr.empty()) return IPv6AddressImpl();
#if defined(_WIN32)
struct addrinfo* pAI;
struct addrinfo hints;
std::memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_NUMERICHOST;
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));
freeaddrinfo(pAI);
return result;
}
else return IPv6AddressImpl();
#else
struct in6_addr ia;
std::string::size_type pos = addr.find('%');
if (std::string::npos != pos)
{
std::string::size_type start = ('[' == addr[0]) ? 1 : 0;
std::string unscopedAddr(addr, start, pos - start);
std::string scope(addr, pos + 1, addr.size() - start - pos);
Poco::UInt32 scopeId(0);
if (!(scopeId = if_nametoindex(scope.c_str())))
return IPv6AddressImpl();
if (inet_pton(AF_INET6, unscopedAddr.c_str(), &ia) == 1)
return IPv6AddressImpl(&ia, scopeId);
else
return IPv6AddressImpl();
}
else
{
if (inet_pton(AF_INET6, addr.c_str(), &ia) == 1)
return IPv6AddressImpl(&ia);
else
return IPv6AddressImpl();
}
#endif
} Note, that scoped interface should be correct name from you system, i.e. when ipv6 is parsing, calls |
This issue is stale because it has been open for 365 days with no activity. |
This issue was closed because it has been inactive for 60 days since being marked as stale. |
Can you reopen? The code is buggy. When using a valid IP address like: [fe80::1592:96a0:88bf:d2d7%brv301] the code properly detect the opening '[' at line 674. But when it builds the scope string at line 676 forget to not include the ']' at the end. |
can someone write some test cases reproducing the problem and create a PR where this can be fixed? |
I would like to parse scoped ipv6 addressees.
i am using poco 1.11.0
The text was updated successfully, but these errors were encountered: