aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorW. J. van der Laan <laanwj@protonmail.com>2021-12-06 19:49:56 +0100
committerW. J. van der Laan <laanwj@protonmail.com>2021-12-06 19:59:35 +0100
commit786ffb3ae488061e13c02ad3fb34a5d2fc785b3d (patch)
treead47259c46a5b2ff25e41e62ac82d77d9fa5bc93 /src
parent695ba2fe5446c633c33959786145b6f2efcaa1f1 (diff)
parenta989f98d240a84b5c798252acaa4a316ac711189 (diff)
downloadbitcoin-786ffb3ae488061e13c02ad3fb34a5d2fc785b3d.tar.xz
Merge bitcoin/bitcoin#17160: refactor: net: subnet lookup: use single-result LookupHost()
a989f98d240a84b5c798252acaa4a316ac711189 refactor: net: subnet lookup: use single-result LookupHost() (Sebastian Falbesoner) Pull request description: plus describe single IP subnet case for more clarity ACKs for top commit: jonatack: utACK a989f98d240a84b5c798252acaa4a316ac711189 the patch rebases cleanly to master, the debug build is green, and it is essentially the same patch as c8991f0251dd2a modulo local variable naming, braced initialization, and a comment vasild: ACK a989f98d240a84b5c798252acaa4a316ac711189 Tree-SHA512: 082d3481b1fa5e5f3267b7c4a812954b67b36d1f94c5296fe20110699f053e5042dfa13f728ae20249e9b8d71e930c3b119410125d0faeccdfbdc259223ee3a6
Diffstat (limited to 'src')
-rw-r--r--src/netbase.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp
index 6191f25cd9..3cb12f1abc 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -682,14 +682,11 @@ bool LookupSubNet(const std::string& strSubnet, CSubNet& ret, DNSLookupFn dns_lo
return false;
}
size_t slash = strSubnet.find_last_of('/');
- std::vector<CNetAddr> vIP;
+ CNetAddr network;
std::string strAddress = strSubnet.substr(0, slash);
- // TODO: Use LookupHost(const std::string&, CNetAddr&, bool) instead to just get
- // one CNetAddr.
- if (LookupHost(strAddress, vIP, 1, false, dns_lookup_function))
+ if (LookupHost(strAddress, network, false, dns_lookup_function))
{
- CNetAddr network = vIP[0];
if (slash != strSubnet.npos)
{
std::string strNetmask = strSubnet.substr(slash + 1);
@@ -701,14 +698,15 @@ bool LookupSubNet(const std::string& strSubnet, CSubNet& ret, DNSLookupFn dns_lo
}
else // If not a valid number, try full netmask syntax
{
+ CNetAddr netmask;
// Never allow lookup for netmask
- if (LookupHost(strNetmask, vIP, 1, false, dns_lookup_function)) {
- ret = CSubNet(network, vIP[0]);
+ if (LookupHost(strNetmask, netmask, false, dns_lookup_function)) {
+ ret = CSubNet(network, netmask);
return ret.IsValid();
}
}
}
- else
+ else // Single IP subnet (<ipv4>/32 or <ipv6>/128)
{
ret = CSubNet(network);
return ret.IsValid();