Repository navigation
pkg/portutil/procnet: support big-endian hosts in ParseAddress - #5100
Merged
AkihiroSuda merged 1 commit intoJul 26, 2026
Merged
Conversation
AkihiroSuda
reviewed
Jul 25, 2026
|
|
||
| ip, _, err = ParseAddressWithEndian("0100007F:0050", false) | ||
| assert.NilError(t, err) | ||
| assert.Check(t, net.ParseIP("127.0.0.1").Equal(ip)) |
Member
There was a problem hiding this comment.
Should test IPv6 in little endian too?
Contributor
Author
There was a problem hiding this comment.
I switched to binary.ByteOrder, ParseAddressWithByteOrder takes the order and ParseAddress passes binary.NativeEndian.
AkihiroSuda
reviewed
Jul 25, 2026
| // explicitly. The kernel writes each 4-byte group of the address in the host's | ||
| // native byte order, the bytes are reversed on little-endian hosts and kept | ||
| // as-is on big-endian hosts (for example, s390x). | ||
| func ParseAddressWithEndian(s string, isBE bool) (net.IP, uint16, error) { |
Member
There was a problem hiding this comment.
Should this take https://pkg.go.dev/encoding/binary#ByteOrder as an argument
Contributor
Author
There was a problem hiding this comment.
Added little-endian IPv6 case, PTAL
The /proc/net/{tcp,tcp6} address bytes are written in the host's native
byte order. ParseAddress unconditionally reversed each 4-byte group, which
is correct on little-endian hosts but mangles the address on big-endian
hosts such as s390x (e.g. 7F000001 parsed to 1.0.0.127 instead of
127.0.0.1).
Add ParseAddressWithByteOrder, reading each group with the given
binary.ByteOrder and writing it back in network order; ParseAddress passes
binary.NativeEndian. Little-endian behavior is unchanged.
Fixes containerd#4465
Signed-off-by: Saleh <root@lr0.org>
larrasket
force-pushed
the
fix-4465-procnet-bigendian
branch
from
July 25, 2026 16:19
9c43648 to
ec50c5e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/proc/net/{tcp,tcp6}address bytes are written in the host's byte order. ParseAddress reversed each 4-byte group, which mangles the address on big-endian hosts such as s390x (e.g. 7F000001 parsed to 1.0.0.127 instead of 127.0.0.1).Add ParseAddressWithEndian and select the byte order from golang.org/x/sys/cpu.IsBigEndian, keeping the existing behavior on little-endian hosts.
Fixes #4465