refactor: net: subnet lookup: use single-result LookupHost()
plus describe single IP subnet case for more clarity
This commit is contained in:
1 parent
4ba1bab443
commit
a989f98d24
1 file changed
+6
-8
+6
-8
@@ -823,14 +823,11 @@ bool LookupSubNet(const std::string& strSubnet, CSubNet& ret, DNSLookupFn dns_lo
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t slash = strSubnet.find_last_of('/');
|
size_t slash = strSubnet.find_last_of('/');
|
||||||
std::vector<CNetAddr> vIP;
|
CNetAddr network;
|
||||||
|
|
||||||
std::string strAddress = strSubnet.substr(0, slash);
|
std::string strAddress = strSubnet.substr(0, slash);
|
||||||
// TODO: Use LookupHost(const std::string&, CNetAddr&, bool) instead to just get
|
if (LookupHost(strAddress, network, false, dns_lookup_function))
|
||||||
// one CNetAddr.
|
|
||||||
if (LookupHost(strAddress, vIP, 1, false, dns_lookup_function))
|
|
||||||
{
|
{
|
||||||
CNetAddr network = vIP[0];
|
|
||||||
if (slash != strSubnet.npos)
|
if (slash != strSubnet.npos)
|
||||||
{
|
{
|
||||||
std::string strNetmask = strSubnet.substr(slash + 1);
|
std::string strNetmask = strSubnet.substr(slash + 1);
|
||||||
@@ -842,14 +839,15 @@ bool LookupSubNet(const std::string& strSubnet, CSubNet& ret, DNSLookupFn dns_lo
|
|||||||
}
|
}
|
||||||
else // If not a valid number, try full netmask syntax
|
else // If not a valid number, try full netmask syntax
|
||||||
{
|
{
|
||||||
|
CNetAddr netmask;
|
||||||
// Never allow lookup for netmask
|
// Never allow lookup for netmask
|
||||||
if (LookupHost(strNetmask, vIP, 1, false, dns_lookup_function)) {
|
if (LookupHost(strNetmask, netmask, false, dns_lookup_function)) {
|
||||||
ret = CSubNet(network, vIP[0]);
|
ret = CSubNet(network, netmask);
|
||||||
return ret.IsValid();
|
return ret.IsValid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else // Single IP subnet (<ipv4>/32 or <ipv6>/128)
|
||||||
{
|
{
|
||||||
ret = CSubNet(network);
|
ret = CSubNet(network);
|
||||||
return ret.IsValid();
|
return ret.IsValid();
|
||||||
|
|||||||
Reference in new issue
Block a user