| 612 | } |
| 613 | |
| 614 | bool 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 |
| 652 | std::string NetworkErrorString(int err) |