Skip to content

Commit a989f98

Browse files
committed
refactor: net: subnet lookup: use single-result LookupHost()
plus describe single IP subnet case for more clarity
1 parent 4ba1bab commit a989f98

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
@@ -823,14 +823,11 @@ bool LookupSubNet(const std::string& strSubnet, CSubNet& ret, DNSLookupFn dns_lo
823823
return false;
824824
}
825825
size_t slash = strSubnet.find_last_of('/');
826-
std::vector<CNetAddr> vIP;
826+
CNetAddr network;
827827

828828
std::string strAddress = strSubnet.substr(0, slash);
829-
// TODO: Use LookupHost(const std::string&, CNetAddr&, bool) instead to just get
830-
// one CNetAddr.
831-
if (LookupHost(strAddress, vIP, 1, false, dns_lookup_function))
829+
if (LookupHost(strAddress, network, false, dns_lookup_function))
832830
{
833-
CNetAddr network = vIP[0];
834831
if (slash != strSubnet.npos)
835832
{
836833
std::string strNetmask = strSubnet.substr(slash + 1);
@@ -842,14 +839,15 @@ bool LookupSubNet(const std::string& strSubnet, CSubNet& ret, DNSLookupFn dns_lo
842839
}
843840
else // If not a valid number, try full netmask syntax
844841
{
842+
CNetAddr netmask;
845843
// Never allow lookup for netmask
846-
if (LookupHost(strNetmask, vIP, 1, false, dns_lookup_function)) {
847-
ret = CSubNet(network, vIP[0]);
844+
if (LookupHost(strNetmask, netmask, false, dns_lookup_function)) {
845+
ret = CSubNet(network, netmask);
848846
return ret.IsValid();
849847
}
850848
}
851849
}
852-
else
850+
else // Single IP subnet (<ipv4>/32 or <ipv6>/128)
853851
{
854852
ret = CSubNet(network);
855853
return ret.IsValid();

0 commit comments

Comments
 (0)