Example #1
0
/**
 * Parses an IPv4 or IPv6 address.
 * @param s
 *  The string to parse.
 * @param result
 *  The address where to store the result.
 * @return
 *  TRUE if parsing succeeds, FALSE otherwise.
 */
static BOOL
parseAddressWithoutMask(char *s, struct Address *result)
{
    size_t const len = strlen(s);
    if (strspn(s, "0123456789.") == len) {
        return parseIPv4Address(s, result);
    }
    else if (strspn(s, "0123456789abcdefABCDEF:.") == len) {
        return parseIPv6Address(s, result);
    }
    else {
        result->type = ERR_INVALID_ADDRESS;
        return FALSE;
    }
}
Example #2
0
bool Uri::Private::parseIPLiteral()
{
    if (!expectChar('[')) {
        return false;
    }
    const size_t parserOldPos = m_parserPos;
    if (parseIPv6Address()) {
        if (!expectChar(']')) {
            return false;
        }
        return true;
    }
    m_parserPos = parserOldPos;
    if (parseIPvFuture()) {
        if (!expectChar(']')) {
            return false;
        }
        return true;
    }
    return false;
}