Fix name resolution

The ai_addr must be cast into sockaddr_in6 and the sin6_addr member must
be passed to inet_ntop.
This commit is contained in:
Markus Mäkelä 2019-08-14 17:09:24 +03:00
parent 45ed3e085f
commit 98ddf1679b
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19

View File

@ -250,7 +250,9 @@ bool name_lookup(const std::string& host, std::string* addr_out, std::string* er
{
// getaddrinfo may return multiple result addresses. Only consider the first.
char buf[INET6_ADDRSTRLEN];
if (inet_ntop(AF_INET6, results->ai_addr, buf, sizeof(buf)))
in6_addr* addr = &((sockaddr_in6*)results->ai_addr)->sin6_addr;
if (inet_ntop(AF_INET6, addr, buf, sizeof(buf)))
{
*addr_out = buf;
success = true;