mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-11 21:22:47 +01:00
net: Allow DNS lookups on nodes with IPV6 lo only
AI_ADDRCONFIG prevents ::1 from being considered a valid address on hosts that have a IPV6 loopback IP address but no other IPV6 interfaces.
This commit is contained in:
@@ -48,6 +48,7 @@ std::vector<CNetAddr> WrappedGetAddrInfo(const std::string& name, bool allow_loo
|
||||
ai_hint.ai_protocol = IPPROTO_TCP;
|
||||
// We don't care which address family (IPv4 or IPv6) is returned
|
||||
ai_hint.ai_family = AF_UNSPEC;
|
||||
|
||||
// If we allow lookups of hostnames, use the AI_ADDRCONFIG flag to only
|
||||
// return addresses whose family we have an address configured for.
|
||||
//
|
||||
@@ -59,7 +60,17 @@ std::vector<CNetAddr> WrappedGetAddrInfo(const std::string& name, bool allow_loo
|
||||
addrinfo* ai_res{nullptr};
|
||||
const int n_err{getaddrinfo(name.c_str(), nullptr, &ai_hint, &ai_res)};
|
||||
if (n_err != 0) {
|
||||
return {};
|
||||
if ((ai_hint.ai_flags & AI_ADDRCONFIG) == AI_ADDRCONFIG) {
|
||||
// AI_ADDRCONFIG on some systems may exclude loopback-only addresses
|
||||
// If first lookup failed we perform a second lookup without AI_ADDRCONFIG
|
||||
ai_hint.ai_flags = (ai_hint.ai_flags & ~AI_ADDRCONFIG);
|
||||
const int n_err_retry{getaddrinfo(name.c_str(), nullptr, &ai_hint, &ai_res)};
|
||||
if (n_err_retry != 0) {
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
// Traverse the linked list starting with ai_trav.
|
||||
|
||||
Reference in New Issue
Block a user