Skip to content

ipv4 column append problem #88

Description

@BozaB

Dear clickhouse-cpp team,

The following function in clickhouse-cpp/clickhouse/columns/ip4.cpp is always thrown an exception, when ipv4 address is 255.255.255.255:

void ColumnIPv4::Append(const std::string& str) {
    in_addr_t addr = inet_addr(str.c_str());
    if (addr == INADDR_NONE) {
        throw std::runtime_error("invalid IPv4 format, ip: " + str);
    }
    data_->Append(htonl(addr));
}

Because inet_addr function is obsolete, and this is a known issue. https://www.gnu.org/software/libc/manual/html_node/Host-Address-Functions.html

The possible solution is the following:

void ColumnIPv4::Append(const std::string& str) {
    struct in_addr addr;
    if (inet_aton(str.c_str(),&addr) == 0) {
        throw std::runtime_error("invalid IPv4 format, ip: " + str);
    }
    data_->Append(htonl(addr.s_addr));
}

Please solve this problem.

Thank you and best regards,
BB

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions