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
+12 -1
View File
@@ -151,11 +151,21 @@ static void ClInternalConnectionTerminated(long errorCode)
PltCloseThread(&terminationCallbackThread); PltCloseThread(&terminationCallbackThread);
} }
static int resolveHostName(const char*host) static int resolveHostName(const char* host)
{ {
struct addrinfo hints, *res; struct addrinfo hints, *res;
int err; 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_INET;
hints.ai_flags = AI_ADDRCONFIG;
err = getaddrinfo(host, NULL, &hints, &res);
if (err != 0 || res == NULL) {
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_ADDRCONFIG; hints.ai_flags = AI_ADDRCONFIG;
@@ -169,6 +179,7 @@ static int resolveHostName(const char*host)
Limelog("getaddrinfo() returned success without addresses\n"); Limelog("getaddrinfo() returned success without addresses\n");
return -1; return -1;
} }
}
// Use the first address in the list // Use the first address in the list
memcpy(&RemoteAddr, res->ai_addr, res->ai_addrlen); memcpy(&RemoteAddr, res->ai_addr, res->ai_addrlen);