int _ResolveIPv4Address(const char* ipv4_str, char* buffer, int bufferSize)
{
struct addrinfo hints, *res; memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_DEFAULT; int error = getaddrinfo(ipv4_str, "http", &hints, &res); if (error)
{
/*NOTREACHED*/
return error;
} // get the first
if (res->ai_family == AF_INET6)
{
// get ipv6 address
struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)res->ai_addr;
inet_ntop(AF_INET6, &ipv6->sin6_addr, buffer, bufferSize);
}
else
{
// get ipv4 address
struct sockaddr_in* ipv4 = (struct sockaddr_in*)res->ai_addr;
inet_ntop(AF_INET, &ipv4->sin_addr, buffer, bufferSize);
} freeaddrinfo(res);
return 0;
}