Skip to content

Commit 786ffb3

Browse files
committed
Merge bitcoin/bitcoin#17160: refactor: net: subnet lookup: use single-result LookupHost()
a989f98 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 a989f98 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 a989f98 Tree-SHA512: 082d3481b1fa5e5f3267b7c4a812954b67b36d1f94c5296fe20110699f053e5042dfa13f728ae20249e9b8d71e930c3b119410125d0faeccdfbdc259223ee3a6
2 parents 695ba2f + a989f98 commit 786ffb3

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/netbase.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -682,14 +682,11 @@ bool LookupSubNet(const std::string& strSubnet, CSubNet& ret, DNSLookupFn dns_lo
682682
return false;
683683
}
684684
size_t slash = strSubnet.find_last_of('/');
685-
std::vector<CNetAddr> vIP;
685+
CNetAddr network;
686686

687687
std::string strAddress = strSubnet.substr(0, slash);
688-
// TODO: Use LookupHost(const std::string&, CNetAddr&, bool) instead to just get
689-
// one CNetAddr.
690-
if (LookupHost(strAddress, vIP, 1, false, dns_lookup_function))
688+
if (LookupHost(strAddress, network, false, dns_lookup_function))
691689
{
692-
CNetAddr network = vIP[0];
693690
if (slash != strSubnet.npos)
694691
{
695692
std::string strNetmask = strSubnet.substr(slash + 1);
@@ -701,14 +698,15 @@ bool LookupSubNet(const std::string& strSubnet, CSubNet& ret, DNSLookupFn dns_lo
701698
}
702699
else // If not a valid number, try full netmask syntax
703700
{
701+
CNetAddr netmask;
704702
// Never allow lookup for netmask
705-
if (LookupHost(strNetmask, vIP, 1, false, dns_lookup_function)) {
706-
ret = CSubNet(network, vIP[0]);
703+
if (LookupHost(strNetmask, netmask, false, dns_lookup_function)) {
704+
ret = CSubNet(network, netmask);
707705
return ret.IsValid();
708706
}
709707
}
710708
}
711-
else
709+
else // Single IP subnet (<ipv4>/32 or <ipv6>/128)
712710
{
713711
ret = CSubNet(network);
714712
return ret.IsValid();

0 commit comments

Comments
 (0)