kbandla / dpkt

fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols
Other
1.09k stars 270 forks source link

Big endian arch bugfixes #510

Closed obormot closed 3 years ago

obormot commented 3 years ago

As was highlighted in #505 some unit tests were failing on IBM System Z, which is a big endian architecture. I've reproduced all the failures on QEMU PowerPC VM which is also big endian. In most cases the failures were due to decoders using socket.ntohs() to convert from network byte order to host byte order, assuming host is little endian (x86). On BE systems the function didn't actually convert since the host itself is BE, producing incorrect fields in the decoders. This patch introduces compat.ntole() function which always converts from network order to LE and works consistently on both LE and BE systems.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.06%) to 92.461% when pulling aef29e85ec8c296c0412b71d183d05e342b3fc44 on fix-big-endian-2 into b930e14e2d5b96bae68a2ec619b07e55bec4935a on master.