mdlayher / raw

Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed.
MIT License
425 stars 71 forks source link

htons should depend on host endianness #72

Open bhesmans opened 2 years ago

bhesmans commented 2 years ago

func htons should take host endianness into account:

func htons(i uint16) uint16 {
    return (i<<8)&0xff00 | i>>8
}

Depending on host endianness this should be a no-op or not.

The issue was spotted when trying to use this lib on a device with a different endianness...