Skip to content

endian: fix big endian detection#110

Merged
mosajjal merged 1 commit intogopacket:masterfrom
mejedi:bugfix-htons
Feb 6, 2025
Merged

endian: fix big endian detection#110
mosajjal merged 1 commit intogopacket:masterfrom
mejedi:bugfix-htons

Conversation

@mejedi
Copy link
Copy Markdown
Contributor

@mejedi mejedi commented Jan 27, 2025

The prior implementation of Htons attempted big endian detection via comparison of binary.NativeEndian.String() with binary.BigEndian.String(). It turns out that the former always returns "NativeEndian", hence it didn't work as intended.

Rewrite endian detection by passing []byte{0x12, 0x34} through Endian.Uint16(). Add test to ensure that detection works both on little and big endian CPUs.

The prior implementation of Htons attempted big endian detection via
comparison of binary.NativeEndian.String() with binary.BigEndian.String().
It turns out that the former always returns "NativeEndian", hence it
didn't work as intended.

Rewrite endian detection by passing []byte{0x12, 0x34} through
Endian.Uint16(). Add test to ensure that detection works both on little
and big endian CPUs.
@mejedi
Copy link
Copy Markdown
Contributor Author

mejedi commented Jan 27, 2025

@mosajjal sorry for messing it up on the first try

@mosajjal mosajjal merged commit 9c54b11 into gopacket:master Feb 6, 2025
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.

2 participants