Always try to resolve a hostname to IPv4 first

This commit is contained in:
Cameron Gutman 2016-04-02 14:06:43 -04:00
parent 61aaca31d4
commit 4055fb6d77

View File

@ -151,23 +151,34 @@ static void ClInternalConnectionTerminated(long errorCode)
PltCloseThread(&terminationCallbackThread);
}
static int resolveHostName(const char*host)
static int resolveHostName(const char* host)
{
struct addrinfo hints, *res;
int err;
// We must first try IPv4-only because GFE doesn't listen on IPv6,
// so we'll only want to use an IPv6 address if it's the only address we have.
// For NAT64 networks, the IPv4 address resolution will fail but the IPv6 address
// will give us working connectivity to the host. All other networks will use IPv4
// addresses.
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_family = AF_INET;
hints.ai_flags = AI_ADDRCONFIG;
err = getaddrinfo(host, NULL, &hints, &res);
if (err != 0) {
Limelog("getaddrinfo() failed: %d\n", err);
return err;
}
if (res == NULL) {
Limelog("getaddrinfo() returned success without addresses\n");
return -1;
if (err != 0 || res == NULL) {
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_ADDRCONFIG;
err = getaddrinfo(host, NULL, &hints, &res);
if (err != 0) {
Limelog("getaddrinfo() failed: %d\n", err);
return err;
}
if (res == NULL) {
Limelog("getaddrinfo() returned success without addresses\n");
return -1;
}
}
// Use the first address in the list