From c42518b8d467f7bcc8cbb7aeb64cb779a79b1bab Mon Sep 17 00:00:00 2001 From: BozaB Date: Thu, 26 Aug 2021 11:55:52 +0800 Subject: [PATCH 1/2] fix:ipv4 column append problem --- clickhouse/columns/ip4.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clickhouse/columns/ip4.cpp b/clickhouse/columns/ip4.cpp index fd78305e..5ea74d7c 100644 --- a/clickhouse/columns/ip4.cpp +++ b/clickhouse/columns/ip4.cpp @@ -25,11 +25,11 @@ ColumnIPv4::ColumnIPv4(ColumnRef data) } void ColumnIPv4::Append(const std::string& str) { - in_addr_t addr = inet_addr(str.c_str()); - if (addr == INADDR_NONE) { + 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)); + data_->Append(htonl(addr.s_addr)); } void ColumnIPv4::Append(uint32_t ip) { From bbe7a276b434770476a00f2659bdfd6ecc52b2da Mon Sep 17 00:00:00 2001 From: BozaB Date: Sat, 18 Sep 2021 13:53:06 +0800 Subject: [PATCH 2/2] add: Add test cases related to the problematic ip. --- tests/simple/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/simple/main.cpp b/tests/simple/main.cpp index 41855514..1e7ec647 100644 --- a/tests/simple/main.cpp +++ b/tests/simple/main.cpp @@ -442,6 +442,7 @@ inline void IPExample(Client &client) { auto v4 = std::make_shared(); v4->Append("127.0.0.1"); + v4->Append("255.255.255.255"); v4->Append(3585395774); v4->Append(0);