MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / LookupSubNet

Function LookupSubNet

src/netbase.cpp:614–649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

612}
613
614bool LookupSubNet(const char* pszName, CSubNet& ret)
615{
616 std::string strSubnet(pszName);
617 size_t slash = strSubnet.find_last_of('/');
618 std::vector<CNetAddr> vIP;
619
620 std::string strAddress = strSubnet.substr(0, slash);
621 if (LookupHost(strAddress.c_str(), vIP, 1, false))
622 {
623 CNetAddr network = vIP[0];
624 if (slash != strSubnet.npos)
625 {
626 std::string strNetmask = strSubnet.substr(slash + 1);
627 int32_t n;
628 // IPv4 addresses start at offset 12, and first 12 bytes must match, so just offset n
629 if (ParseInt32(strNetmask, &n)) { // If valid number, assume /24 syntax
630 ret = CSubNet(network, n);
631 return ret.IsValid();
632 }
633 else // If not a valid number, try full netmask syntax
634 {
635 // Never allow lookup for netmask
636 if (LookupHost(strNetmask.c_str(), vIP, 1, false)) {
637 ret = CSubNet(network, vIP[0]);
638 return ret.IsValid();
639 }
640 }
641 }
642 else
643 {
644 ret = CSubNet(network);
645 return ret.IsValid();
646 }
647 }
648 return false;
649}
650
651#ifdef WIN32
652std::string NetworkErrorString(int err)

Callers 5

InitHTTPAllowListFunction · 0.85
AppInitMainFunction · 0.85
ResolveSubNetFunction · 0.85
unbanSelectedNodeMethod · 0.85
setbanFunction · 0.85

Calls 4

LookupHostFunction · 0.85
ParseInt32Function · 0.70
CSubNetClass · 0.70
IsValidMethod · 0.45

Tested by 1

ResolveSubNetFunction · 0.68