mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 01:15:46 +00:00
Always try to resolve a hostname to IPv4 first
This commit is contained in:
parent
61aaca31d4
commit
4055fb6d77
@ -151,23 +151,34 @@ 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));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = AF_UNSPEC;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_flags = AI_ADDRCONFIG;
|
hints.ai_flags = AI_ADDRCONFIG;
|
||||||
err = getaddrinfo(host, NULL, &hints, &res);
|
err = getaddrinfo(host, NULL, &hints, &res);
|
||||||
if (err != 0) {
|
if (err != 0 || res == NULL) {
|
||||||
Limelog("getaddrinfo() failed: %d\n", err);
|
memset(&hints, 0, sizeof(hints));
|
||||||
return err;
|
hints.ai_family = AF_UNSPEC;
|
||||||
}
|
hints.ai_flags = AI_ADDRCONFIG;
|
||||||
|
err = getaddrinfo(host, NULL, &hints, &res);
|
||||||
if (res == NULL) {
|
if (err != 0) {
|
||||||
Limelog("getaddrinfo() returned success without addresses\n");
|
Limelog("getaddrinfo() failed: %d\n", err);
|
||||||
return -1;
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res == NULL) {
|
||||||
|
Limelog("getaddrinfo() returned success without addresses\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the first address in the list
|
// Use the first address in the list
|
||||||
|
Loading…
x
Reference in New Issue
Block a user