src/netbase.cpp
bool LookupSubNet(const std::string& strSubnet, CSubNet& ret)
{
    if (!ValidAsCString(strSubnet)) {
        return false;
    }
    size_t slash = strSubnet.find_last_of('/');
    std::vector<CNetAddr> vIP;

    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))
    {
        CNetAddr network = vIP[0];
        if (slash != strSubnet.npos)
        {
            std::string strNetmask = strSubnet.substr(slash + 1);
            int32_t n;
            if (ParseInt32(strNetmask, &n)) {
                // If valid number, assume CIDR variable-length subnet masking
                ret = CSubNet(network, n);
                return ret.IsValid();
            }
            else // If not a valid number, try full netmask syntax
            {
                // Never allow lookup for netmask
                if (LookupHost(strNetmask, vIP, 1, false)) {
                    ret = CSubNet(network, vIP[0]);
                    return ret.IsValid();
                }
            }
        }
        else
        {
            ret = CSubNet(network);
            return ret.IsValid();
        }
    }
    return false;
}
/**
 * Parse and resolve a specified subnet string into the appropriate internal
 * representation.
 *
 * @param strSubnet A string representation of a subnet of the form `network
 *                address [ "/", ( CIDR-style suffix | netmask ) ]`(e.g.
 *                `2001:db8::/32`, `192.0.2.0/255.255.255.0`, or `8.8.8.8`).
 * @param ret The resulting internal representation of a subnet.
 *
 * @returns Whether the operation succeeded or not.
 */
Parse and resolve a specified subnet string into the appropriate internal
representation.

@param strSubnet A string representation of a subnet of the form `network
address [ "/", ( CIDR-style suffix | netmask ) ]`.
@param ret The resulting internal representation of a subnet.

@returns Whether the operation succeeded or not.
Parse and resolve a specified subnet string into the appropriate internal representation . @param strSubnet A string representation of a subnet of the form ` network address [ " / " ( CIDR - style suffix | netmask ) ] ` . @param ret The resulting internal representation of a subnet . @returns Whether the operation succeeded or not .
bool LookupSubNet(const std::string& strSubnet, CSubNet& ret)
{
    if (!ValidAsCString(strSubnet)) {
        return false;
    }
    size_t slash = strSubnet.find_last_of('/');
    std::vector<CNetAddr> vIP;
    std::string strAddress = strSubnet.substr(0, slash);
    if (LookupHost(strAddress, vIP, 1, false))
    {
        CNetAddr network = vIP[0];
        if (slash != strSubnet.npos)
        {
            std::string strNetmask = strSubnet.substr(slash + 1);
            int32_t n;
            if (ParseInt32(strNetmask, &n)) {
                ret = CSubNet(network, n);
                return ret.IsValid();
            }
            else 
            {
                if (LookupHost(strNetmask, vIP, 1, false)) {
                    ret = CSubNet(network, vIP[0]);
                    return ret.IsValid();
                }
            }
        }
        else
        {
            ret = CSubNet(network);
            return ret.IsValid();
        }
    }
    return false;
}
bool LookupSubNet ( const std :: string & strSubnet , CSubNet & ret ) { if ( ! ValidAsCString ( strSubnet ) ) { return false ; } size_t slash = strSubnet . find_last_of ( ' ' ) ; std :: vector < CNetAddr > vIP ; std :: string strAddress = strSubnet . substr ( 0 , slash ) ; if ( LookupHost ( strAddress , vIP , 1 , false ) ) { CNetAddr network = vIP [ 0 ] ; if ( slash != strSubnet . npos ) { std :: string strNetmask = strSubnet . substr ( slash + 1 ) ; int32_t n ; if ( ParseInt32 ( strNetmask , & n ) ) { ret = CSubNet ( network , n ) ; return ret . IsValid ( ) ; } else { if ( LookupHost ( strNetmask , vIP , 1 , false ) ) { ret = CSubNet ( network , vIP [ 0 ] ) ; return ret . IsValid ( ) ; } } } else { ret = CSubNet ( network ) ; return ret . IsValid ( ) ; } } return false ; }
Parse and resolve a specified subnet string into the appropriate internal
 representation.
Parse and resolve a specified subnet string into the appropriate internal representation .
// TODO: Use LookupHost(const std::string&, CNetAddr&, bool) instead to just get //       one CNetAddr. // If valid number, assume CIDR variable-length subnet masking // If not a valid number, try full netmask syntax // Never allow lookup for netmask