Example #1
0
IPAddress::IPAddress(const uint8_t *address) {
    setV4();
    (*this)[0] = address[0];
    (*this)[1] = address[1];
    (*this)[2] = address[2];
    (*this)[3] = address[3];
}
Example #2
0
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) {
    setV4();
    (*this)[0] = first_octet;
    (*this)[1] = second_octet;
    (*this)[2] = third_octet;
    (*this)[3] = fourth_octet;
}
int AddressCommand::set(const char *pcszAdapter, const char *pcszAddress, const char *pcszNetmask)
{
    if (isAddrV6(pcszAddress))
    {
        removeAddresses(pcszAdapter, "inet6");
        return addV6(pcszAdapter, pcszAddress, pcszNetmask);
    }
    int rc = setV4(pcszAdapter, pcszAddress, pcszNetmask);
    if (rc == ENOTSUP)
    {
        removeAddresses(pcszAdapter, "inet");
        rc = addV4(pcszAdapter, pcszAddress, pcszNetmask);
    }
    return rc;
}
Example #4
0
bool IPAddress::fromString4(const char *address) {
    // TODO: (IPv4) add support for "a", "a.b", "a.b.c" formats

    uint16_t acc = 0; // Accumulator
    uint8_t dots = 0;

    while (*address)
    {
        char c = *address++;
        if (c >= '0' && c <= '9')
        {
            acc = acc * 10 + (c - '0');
            if (acc > 255) {
                // Value out of [0..255] range
                return false;
            }
        }
        else if (c == '.')
        {
            if (dots == 3) {
                // Too much dots (there must be 3 dots)
                return false;
            }
            (*this)[dots++] = acc;
            acc = 0;
        }
        else
        {
            // Invalid char
            return false;
        }
    }

    if (dots != 3) {
        // Too few dots (there must be 3 dots)
        return false;
    }
    (*this)[3] = acc;

    setV4();
    return true;
}
Example #5
0
void IPAddress::ctor32(uint32_t address) {
    setV4();
    v4() = address;
}
Example #6
0
IPAddress& IPAddress::operator=(uint32_t address) {
    setV4();
    v4() = address;
    return *this;
}
Example #7
0
IPAddress& IPAddress::operator=(const uint8_t *address) {
    setV4();
    v4() = *reinterpret_cast<const uint32_t*>(address);
    return *this;
}