Retry getaddrinfo with IPv4 only after an error

This commit is contained in:
SChernykh 2023-01-27 10:29:04 +01:00
parent 8876af53d8
commit c7ba11c607
2 changed files with 12 additions and 2 deletions

View file

@ -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;

View file

@ -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];