Retry `getaddrinfo` with IPv4 only after an error

wow
_XxFedexX_ 1 year ago
parent 77b141719a
commit 4b88d74f7c

@ -497,7 +497,12 @@ void P2PServer::load_peer_list()
hints.ai_flags = AI_ADDRCONFIG;
addrinfo* result;
const int err = getaddrinfo(nodes[i], nullptr, &hints, &result);
int err = getaddrinfo(nodes[i], nullptr, &hints, &result);
if (err) {
LOGWARN(4, "getaddrinfo failed for " << nodes[i] << ": " << gai_strerror(err) << ", retrying with IPv4 only");
hints.ai_family = AF_INET;
err = getaddrinfo(nodes[i], nullptr, &hints, &result);
}
if (err == 0) {
for (addrinfo* r = result; r != NULL; r = r->ai_next) {
const char* addr_str;

@ -420,7 +420,12 @@ bool resolve_host(std::string& host, bool& is_v6)
hints.ai_flags = AI_ADDRCONFIG;
addrinfo* r = nullptr;
const int err = getaddrinfo(host.c_str(), nullptr, &hints, &r);
int err = getaddrinfo(host.c_str(), nullptr, &hints, &r);
if (err) {
LOGWARN(4, "getaddrinfo failed for " << host << ": " << gai_strerror(err) << ", retrying with IPv4 only");
hints.ai_family = AF_INET;
err = getaddrinfo(host.c_str(), nullptr, &hints, &r);
}
if ((err == 0) && r) {
const char* addr_str = nullptr;
char addr_str_buf[64];

Loading…
Cancel
Save