Endian-ness
Prev | Chapter 3. Software | Next

## Endian-ness

Atheros vendor-specific messages contain information in mixed endian format. The Ethernet header portion is sent big endian but the Atheros header and payload are sent in little endian . The traditional endian converstion functions `htons()`, `htonl()`, `ntohs()` and `ntohl()` can be used to perform platform independent conversions on the Ethernet header but not the Atheros header payload.

The Open Powerline Toolkit includes similar macros `HTOLE16`, `HTOLE32`, `LE16TOH` and `LE32TOH` in endian.h which serve the same function but conform to recommendations for standarized byte order function on Linux, OpenBSD and FreeBSD. Observe that the names are independent of any network implications.

    #if BYTE_ORDER == BIG_ENDIAN
    #	define LE16TOH(x) __bswap_16(x)
    #	define LE32TOH(x) __bswap_32(x)
    #	define LE64TOH(x) __bswap_64(x)
    #	define HTOLE16(x) __bswap_16(x)
    #	define HTOLE32(x) __bswap_32(x)
    #	define HTOLE64(x) __bswap_64(x)
    #elif BYTE_ORDER == LITTLE_ENDIAN
    #	define LE16TOH(x) (x)
    #	define LE32TOH(x) (x)
    #	define LE64TOH(x) (x)
    #	define HTOLE16(x) (x)
    #	define HTOLE32(x) (x)
    #	define HTOLE64(x) (x)
    #else
    #error "Undefined host byte order."
    #endif

In addition, the Open Powerline Toolkit includes function endian that reverses byte order over a variable-length memory region.

Prev | Up | Next
Structure Packing | Home | Packet Basics