Skip to content

Fix ColumnIPv4 byte-order documentation and add IP round-trip tests - #570

Merged
slabko merged 1 commit into
masterfrom
fix/ipv4-byte-order-docs
Sep 28, 2026
Merged

slabko merged 1 commit into
masterfrom
fix/ipv4-byte-order-docs

Conversation

@slabko

@slabko slabko commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ColumnIPv4::Append(uint32_t) was documented as taking a value in host byte order, but it has always interpreted its argument as in_addr::s_addr (network byte order). The existing unit test in ut/columns_ut.cpp already asserted this (Append(3585395774) → "62.204.180.213"). This PR fixes the documentation rather than the behaviour, so existing callers are not silently broken.

Fixes #521

`ColumnIPv4::Append(uint32_t)` was documented as taking a host-order
value, but it has always interpreted its argument as `in_addr::s_addr`
(network byte order), as the existing unit test already asserted.
Correct the documentation rather than the behaviour, so existing
callers are not silently broken.

Rename the `htonl`/`ntohl` calls in `ColumnIPv4` so they read in the
direction they actually convert: incoming `s_addr` values are converted
to the host-order integer that ClickHouse stores natively, and `At()`
converts back. This is behaviour-neutral since both functions perform
the same byte swap.

Add `ClientCase.IPv4RoundTrip` / `IPv6RoundTrip`, which insert
addresses through every `Append` overload and compare against the
server's `toString()`, the only authoritative check of byte order.

Also fix `MakeIPv4s()`: the previous list had a wrong comment, lacked
an actual `255.255.255.255` and contained a duplicate.
@slabko
slabko requested a review from mzitnik as a code owner September 28, 2026 19:31
@slabko
slabko merged commit 890fb0c into master Sep 28, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect byte order conversion in ColumnIPv4::Append() overloads

2 participants