http://www.csse.uwa.edu.au/~chris/uwasp/endian.html
NAME
Functions to manipulate the byte-ordering (the endianness) of captured data
SYNOPSIS
#include <uwasp.h>
uint16_t le16_to_cpu( uint16_t value );
uint16_t cpu_to_le16( uint16_t value );
uint32_t le32_to_cpu( uint32_t value );
uint32_t cpu_to_le32( uint32_t value );
uint64_t le64_to_cpu( uint64_t value );
uint64_t cpu_to_le64( uint64_t value );
uint16_t be16_to_cpu( uint16_t value );
uint16_t cpu_to_be16( uint16_t value );
uint32_t be32_to_cpu( uint32_t value );
uint32_t cpu_to_be32( uint32_t value );
uint64_t be64_to_cpu( uint64_t value );
uint64_t cpu_to_be64( uint64_t value );
DESCRIPTION
To maintain platform independence of captured data, both when it is transmitted through networks and when stored on disk, all 16-, 32-, and 64-bit integer values are stored in little-endian order.
Little-endian is chosen because the data is most likely to be accessed on little-endian machines, such as the Intel x86 architecture. These functions provide conversions between little-endian, big-endian, and the byte ordering of the CPU on which the data is being processed.
le16_to_cpu(), for example, converts a 16-bit little-endian integer to its 16-bit representation on the current CPU. Similarly, cpu_to_be32() converts the current CPU's 32-bit representation of a integer, to its 32-bit big-endian representation.
As an example, to extract the frame-control field from a captured frame so that it be used in subsequent arithmetic expressions, we would use:
uint16_t frame_control = le16_to_cpu( capture->h.fc );
RETURN VALUE
Each function returns a 16, 32, or 64 bit integer in the requested byte-ordering.
As all 16, 32, and 64 bit patterns are valid integers in each representation, no errors are possible.
NAME
Functions to manipulate the byte-ordering (the endianness) of captured data
SYNOPSIS
#include <uwasp.h>
uint16_t le16_to_cpu( uint16_t value );
uint16_t cpu_to_le16( uint16_t value );
uint32_t le32_to_cpu( uint32_t value );
uint32_t cpu_to_le32( uint32_t value );
uint64_t le64_to_cpu( uint64_t value );
uint64_t cpu_to_le64( uint64_t value );
uint16_t be16_to_cpu( uint16_t value );
uint16_t cpu_to_be16( uint16_t value );
uint32_t be32_to_cpu( uint32_t value );
uint32_t cpu_to_be32( uint32_t value );
uint64_t be64_to_cpu( uint64_t value );
uint64_t cpu_to_be64( uint64_t value );
DESCRIPTION
To maintain platform independence of captured data, both when it is transmitted through networks and when stored on disk, all 16-, 32-, and 64-bit integer values are stored in little-endian order.
Little-endian is chosen because the data is most likely to be accessed on little-endian machines, such as the Intel x86 architecture. These functions provide conversions between little-endian, big-endian, and the byte ordering of the CPU on which the data is being processed.
le16_to_cpu(), for example, converts a 16-bit little-endian integer to its 16-bit representation on the current CPU. Similarly, cpu_to_be32() converts the current CPU's 32-bit representation of a integer, to its 32-bit big-endian representation.
As an example, to extract the frame-control field from a captured frame so that it be used in subsequent arithmetic expressions, we would use:
uint16_t frame_control = le16_to_cpu( capture->h.fc );
RETURN VALUE
Each function returns a 16, 32, or 64 bit integer in the requested byte-ordering.
As all 16, 32, and 64 bit patterns are valid integers in each representation, no errors are possible.