Add workaround for broken getaddrinfo in Apple's NAT64 environment.

This commit is contained in:
Christopher Kohlhoff 2017-01-14 12:24:45 +11:00
parent bc6e494d2d
commit 595ff85c33

View File

@ -3327,6 +3327,37 @@ asio::error_code getaddrinfo(const char* host,
return ec = translate_addrinfo_error(error);
#else
int error = ::getaddrinfo(host, service, &hints, result);
#if defined(__MACH__) && defined(__APPLE__)
using namespace std; // For isdigit and atoi.
if (error == 0 && service && isdigit(static_cast<unsigned char>(service[0])))
{
u_short_type port = host_to_network_short(atoi(service));
for (addrinfo_type* ai = *result; ai; ai = ai->ai_next)
{
switch (ai->ai_family)
{
case ASIO_OS_DEF(AF_INET):
{
sockaddr_in4_type* sinptr =
reinterpret_cast<sockaddr_in4_type*>(ai->ai_addr);
if (sinptr->sin_port == 0)
sinptr->sin_port = port;
break;
}
case ASIO_OS_DEF(AF_INET6):
{
sockaddr_in6_type* sin6ptr =
reinterpret_cast<sockaddr_in6_type*>(ai->ai_addr);
if (sin6ptr->sin6_port == 0)
sin6ptr->sin6_port = port;
break;
}
default:
break;
}
}
}
#endif
return ec = translate_addrinfo_error(error);
#endif
}