diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2019-10-16 13:40:17 +0200 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2021-03-16 01:24:58 +0100 |
commit | a989f98d240a84b5c798252acaa4a316ac711189 (patch) | |
tree | 145729a72027ef95dad5bda6562ccb6270cd3dff /src | |
parent | 4ba1bab44390090a939d5ab2dee1440330f9a2d7 (diff) | |
download | bitcoin-a989f98d240a84b5c798252acaa4a316ac711189.tar.xz |
refactor: net: subnet lookup: use single-result LookupHost()
plus describe single IP subnet case for more clarity
Diffstat (limited to 'src')
-rw-r--r-- | src/netbase.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp index b95bb05e71..4d42e83079 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -823,14 +823,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); @@ -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 { + 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(); |