|
|
|
@ -14,22 +14,24 @@ namespace Bk::Net { |
|
|
|
|
hints.ai_family = ai_family;
|
|
|
|
|
hints.ai_socktype = SOCK_STREAM; |
|
|
|
|
|
|
|
|
|
if ((status = getaddrinfo(host_name.c_str(), NULL, &hints, &res)) != 0) { |
|
|
|
|
if ((status = getaddrinfo(host_name.c_str(), NULL, &hints, &res)) != 0)
|
|
|
|
|
{ |
|
|
|
|
output.push_back(""); |
|
|
|
|
return output; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(p = res;p != NULL; p = p->ai_next) { |
|
|
|
|
for(p = res;p != NULL; p = p->ai_next)
|
|
|
|
|
{ |
|
|
|
|
void *addr; |
|
|
|
|
if (p->ai_family == AF_INET) { // IPv4
|
|
|
|
|
if (p->ai_family == AF_INET)
|
|
|
|
|
{ |
|
|
|
|
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr; |
|
|
|
|
addr = &(ipv4->sin_addr); |
|
|
|
|
} else { // IPv6
|
|
|
|
|
} else
|
|
|
|
|
{ |
|
|
|
|
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr; |
|
|
|
|
addr = &(ipv6->sin6_addr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// convert the IP to a string
|
|
|
|
|
inet_ntop(p->ai_family, addr, ip_address, sizeof ip_address); |
|
|
|
|
output.push_back(ip_address); |
|
|
|
|
} |
|
|
|
|