| 531 | } |
| 532 | |
| 533 | bool 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 | |
| 564 | void CNetAddr::Init() { memset(ip, 0, sizeof(ip)); } |
| 565 |
no test coverage detected