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

Function LookupSubNet

src/netbase.cpp:533–562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

531}
532
533bool LookupSubNet(const char* pszName, CSubNet& ret) {
534 std::string strSubnet(pszName);
535 size_t slash = strSubnet.find_last_of('/');
536 std::vector<CNetAddr> vIP;
537
538 std::string strAddress = strSubnet.substr(0, slash);
539 if (LookupHost(strAddress.c_str(), vIP, 1, false)) {
540 CNetAddr network = vIP[0];
541 if (slash != strSubnet.npos) {
542 std::string strNetmask = strSubnet.substr(slash + 1);
543 int32_t n;
544 // IPv4 addresses start at offset 12, and first 12 bytes must match, so just offset n
545 if (ParseInt32(strNetmask, &n)) { // If valid number, assume /24 syntax
546 ret = CSubNet(network, n);
547 return ret.IsValid();
548 } else // If not a valid number, try full netmask syntax
549 {
550 // Never allow lookup for netmask
551 if (LookupHost(strNetmask.c_str(), vIP, 1, false)) {
552 ret = CSubNet(network, vIP[0]);
553 return ret.IsValid();
554 }
555 }
556 } else {
557 ret = CSubNet(network);
558 return ret.IsValid();
559 }
560 }
561 return false;
562}
563
564void CNetAddr::Init() { memset(ip, 0, sizeof(ip)); }
565

Callers 1

InitHTTPAllowListFunction · 0.85

Calls 4

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

Tested by

no test coverage detected