byteorder.h File Reference

Functions to work with different byte orders. More...

Detailed Description

Functions to work with different byte orders.

Author
René Kijewski rene..nosp@m.kije.nosp@m.wski@.nosp@m.fu-b.nosp@m.erlin.nosp@m..de

Definition in file byteorder.h.

#include <stdint.h>
+ Include dependency graph for byteorder.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  le_uint16_t
 A 16 bit integer in little endian. More...
 
union  le_uint32_t
 A 32 bit integer in little endian. More...
 
union  le_uint64_t
 A 64 bit integer in little endian. More...
 
union  be_uint16_t
 A 16 bit integer in big endian aka network byte order. More...
 
union  be_uint32_t
 A 32 bit integer in big endian aka network byte order. More...
 
union  be_uint64_t
 A 64 bit integer in big endian aka network byte order. More...
 
#define _byteorder_swap(V, T)   (byteorder_swap##T((V)))
 Swaps the byteorder according to the endianess.
 
typedef be_uint16_t network_uint16_t
 A 16 bit integer in network byte order.
 
typedef be_uint32_t network_uint32_t
 A 32 bit integer in network byte order.
 
typedef be_uint64_t network_uint64_t
 A 64 bit integer in network byte order.
 
static be_uint16_t byteorder_ltobs (le_uint16_t v)
 Convert from little endian to big endian, 16 bit. More...
 
static be_uint32_t byteorder_ltobl (le_uint32_t v)
 Convert from little endian to big endian, 32 bit. More...
 
static be_uint64_t byteorder_ltobll (le_uint64_t v)
 Convert from little endian to big endian, 64 bit. More...
 
static le_uint16_t byteorder_btols (be_uint16_t v)
 Convert from big endian to little endian, 16 bit. More...
 
static le_uint32_t byteorder_btoll (be_uint32_t v)
 Convert from big endian to little endian, 32 bit. More...
 
static le_uint64_t byteorder_btolll (be_uint64_t v)
 Convert from big endian to little endian, 64 bit. More...
 
static network_uint16_t byteorder_htons (uint16_t v)
 Convert from host byte order to network byte order, 16 bit. More...
 
static network_uint32_t byteorder_htonl (uint32_t v)
 Convert from host byte order to network byte order, 32 bit. More...
 
static network_uint64_t byteorder_htonll (uint64_t v)
 Convert from host byte order to network byte order, 64 bit. More...
 
static uint16_t byteorder_ntohs (network_uint16_t v)
 Convert from network byte order to host byte order, 16 bit. More...
 
static uint32_t byteorder_ntohl (network_uint32_t v)
 Convert from network byte order to host byte order, 32 bit. More...
 
static uint64_t byteorder_ntohll (network_uint64_t v)
 Convert from network byte order to host byte order, 64 bit. More...
 
static uint16_t byteorder_swaps (uint16_t v)
 Swap byte order, 16 bit. More...
 
static uint32_t byteorder_swapl (uint32_t v)
 Swap byte order, 32 bit. More...
 
static uint64_t byteorder_swapll (uint64_t v)
 Swap byte order, 64 bit. More...
 
static uint16_t byteorder_bebuftohs (const uint8_t *buf)
 Read a big endian encoded unsigned integer from a buffer into host byte order encoded variable, 16-bit. More...
 
static void byteorder_htobebufs (uint8_t *buf, uint16_t val)
 Write a host byte order encoded unsigned integer as big endian encoded value into a buffer, 16-bit. More...
 
static uint16_t htons (uint16_t v)
 Convert from host byte order to network byte order, 16 bit. More...
 
static uint32_t htonl (uint32_t v)
 Convert from host byte order to network byte order, 32 bit. More...
 
static uint64_t htonll (uint64_t v)
 Convert from host byte order to network byte order, 64 bit. More...
 
static uint16_t ntohs (uint16_t v)
 Convert from network byte order to host byte order, 16 bit. More...
 
static uint32_t ntohl (uint32_t v)
 Convert from network byte order to host byte order, 32 bit. More...
 
static uint64_t ntohll (uint64_t v)
 Convert from network byte order to host byte order, 64 bit. More...
 

Function Documentation

◆ byteorder_bebuftohs()

static uint16_t byteorder_bebuftohs ( const uint8_t *  buf)
inlinestatic

Read a big endian encoded unsigned integer from a buffer into host byte order encoded variable, 16-bit.

Note
This function is agnostic to the alignment of the target value in the given buffer
Parameters
[in]bufposition in a buffer holding the target value
Returns
16-bit unsigned integer in host byte order

Definition at line 446 of file byteorder.h.

◆ byteorder_btoll()

static le_uint32_t byteorder_btoll ( be_uint32_t  v)
inlinestatic

Convert from big endian to little endian, 32 bit.

Parameters
[in]vThe integer in big endian.
Returns
v converted to little endian.

Definition at line 357 of file byteorder.h.

◆ byteorder_btolll()

static le_uint64_t byteorder_btolll ( be_uint64_t  v)
inlinestatic

Convert from big endian to little endian, 64 bit.

Parameters
[in]vThe integer in big endian.
Returns
v converted to little endian.

Definition at line 363 of file byteorder.h.

◆ byteorder_btols()

static le_uint16_t byteorder_btols ( be_uint16_t  v)
inlinestatic

Convert from big endian to little endian, 16 bit.

Parameters
[in]vThe integer in big endian.
Returns
v converted to little endian.

Definition at line 351 of file byteorder.h.

◆ byteorder_htobebufs()

static void byteorder_htobebufs ( uint8_t *  buf,
uint16_t  val 
)
inlinestatic

Write a host byte order encoded unsigned integer as big endian encoded value into a buffer, 16-bit.

Note
This function is alignment agnostic and works with any given memory location of the buffer
Parameters
[out]buftarget buffer, must be able to accept 2 bytes
[in]valvalue written to the buffer, in host byte order

Definition at line 451 of file byteorder.h.

◆ byteorder_htonl()

static network_uint32_t byteorder_htonl ( uint32_t  v)
inlinestatic

Convert from host byte order to network byte order, 32 bit.

Parameters
[in]vThe integer in host byte order.
Returns
v converted to network byte order.

Definition at line 386 of file byteorder.h.

◆ byteorder_htonll()

static network_uint64_t byteorder_htonll ( uint64_t  v)
inlinestatic

Convert from host byte order to network byte order, 64 bit.

Parameters
[in]vThe integer in host byte order.
Returns
v converted to network byte order.

Definition at line 392 of file byteorder.h.

◆ byteorder_htons()

static network_uint16_t byteorder_htons ( uint16_t  v)
inlinestatic

Convert from host byte order to network byte order, 16 bit.

Parameters
[in]vThe integer in host byte order.
Returns
v converted to network byte order.

Definition at line 380 of file byteorder.h.

◆ byteorder_ltobl()

static be_uint32_t byteorder_ltobl ( le_uint32_t  v)
inlinestatic

Convert from little endian to big endian, 32 bit.

Parameters
[in]vThe integer in little endian.
Returns
v converted to big endian.

Definition at line 339 of file byteorder.h.

◆ byteorder_ltobll()

static be_uint64_t byteorder_ltobll ( le_uint64_t  v)
inlinestatic

Convert from little endian to big endian, 64 bit.

Parameters
[in]vThe integer in little endian.
Returns
v converted to big endian.

Definition at line 345 of file byteorder.h.

◆ byteorder_ltobs()

static be_uint16_t byteorder_ltobs ( le_uint16_t  v)
inlinestatic

Convert from little endian to big endian, 16 bit.

Parameters
[in]vThe integer in little endian.
Returns
v converted to big endian.

Definition at line 333 of file byteorder.h.

◆ byteorder_ntohl()

static uint32_t byteorder_ntohl ( network_uint32_t  v)
inlinestatic

Convert from network byte order to host byte order, 32 bit.

Parameters
[in]vThe integer in network byte order.
Returns
v converted to host byte order.

Definition at line 403 of file byteorder.h.

◆ byteorder_ntohll()

static uint64_t byteorder_ntohll ( network_uint64_t  v)
inlinestatic

Convert from network byte order to host byte order, 64 bit.

Parameters
[in]vThe integer in network byte order.
Returns
v converted to host byte order.

Definition at line 408 of file byteorder.h.

◆ byteorder_ntohs()

static uint16_t byteorder_ntohs ( network_uint16_t  v)
inlinestatic

Convert from network byte order to host byte order, 16 bit.

Parameters
[in]vThe integer in network byte order.
Returns
v converted to host byte order.

Definition at line 398 of file byteorder.h.

◆ byteorder_swapl()

static uint32_t byteorder_swapl ( uint32_t  v)
inlinestatic

Swap byte order, 32 bit.

Parameters
[in]vThe integer to swap.
Returns
The swapped integer.

Definition at line 323 of file byteorder.h.

◆ byteorder_swapll()

static uint64_t byteorder_swapll ( uint64_t  v)
inlinestatic

Swap byte order, 64 bit.

Parameters
[in]vThe integer to swap.
Returns
The swapped integer.

Definition at line 328 of file byteorder.h.

◆ byteorder_swaps()

static uint16_t byteorder_swaps ( uint16_t  v)
inlinestatic

Swap byte order, 16 bit.

Parameters
[in]vThe integer to swap.
Returns
The swapped integer.

Definition at line 310 of file byteorder.h.

◆ htonl()

static uint32_t htonl ( uint32_t  v)
inlinestatic

Convert from host byte order to network byte order, 32 bit.

See also
byteorder_htonl()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 418 of file byteorder.h.

◆ htonll()

static uint64_t htonll ( uint64_t  v)
inlinestatic

Convert from host byte order to network byte order, 64 bit.

See also
byteorder_htonll()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 423 of file byteorder.h.

◆ htons()

static uint16_t htons ( uint16_t  v)
inlinestatic

Convert from host byte order to network byte order, 16 bit.

See also
byteorder_htons()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 413 of file byteorder.h.

◆ ntohl()

static uint32_t ntohl ( uint32_t  v)
inlinestatic

Convert from network byte order to host byte order, 32 bit.

See also
byteorder_ntohl()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 434 of file byteorder.h.

◆ ntohll()

static uint64_t ntohll ( uint64_t  v)
inlinestatic

Convert from network byte order to host byte order, 64 bit.

See also
byteorder_ntohll()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 440 of file byteorder.h.

◆ ntohs()

static uint16_t ntohs ( uint16_t  v)
inlinestatic

Convert from network byte order to host byte order, 16 bit.

See also
byteorder_ntohs()
Parameters
[in]vThe integer to convert.
Returns
Converted integer.

Definition at line 428 of file byteorder.h.