The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions
nbo.h File Reference

Structures and functions for converting integers to/from network byte order. More...

#include <freeradius-devel/util/misc.h>
+ Include dependency graph for nbo.h:

Go to the source code of this file.

Macros

#define fr_nbo_to_int16(_x)   ((int16_t) fr_nbo_to_uint16(_x))
 
#define fr_nbo_to_int32(_x)   ((int32_t) fr_nbo_to_uint32(_x))
 
#define fr_nbo_to_int64(_x)   ((int64_t) fr_nbo_to_uint64(_x))
 

Functions

static unsigned int fr_bytes_from_bits (unsigned int bits)
 Convert bits (as in prefix length) to bytes, rounding up. More...
 
static void fr_nbo_from_int16 (uint8_t out[static sizeof(int16_t)], int16_t num)
 Write out an signed 16bit integer in wire format (big endian) More...
 
static void fr_nbo_from_int32 (uint8_t out[static sizeof(int32_t)], int32_t num)
 Write out an signed 32bit integer in wire format (big endian) More...
 
static void fr_nbo_from_int64 (uint8_t out[static sizeof(uint64_t)], uint64_t num)
 Write out an signed 64bit integer in wire format (big endian) More...
 
static void fr_nbo_from_uint16 (uint8_t out[static sizeof(uint16_t)], uint16_t num)
 Write out an unsigned 16bit integer in wire format (big endian) More...
 
static void fr_nbo_from_uint24 (uint8_t out[static 3], uint32_t num)
 Write out an unsigned 24bit integer in wire format (big endian) More...
 
static void fr_nbo_from_uint32 (uint8_t out[static sizeof(uint32_t)], uint32_t num)
 Write out an unsigned 32bit integer in wire format (big endian) More...
 
static void fr_nbo_from_uint64 (uint8_t out[static sizeof(uint64_t)], uint64_t num)
 Write out an unsigned 64bit integer in wire format (big endian) More...
 
static size_t fr_nbo_from_uint64v (uint8_t out[static sizeof(uint64_t)], uint64_t num)
 Write out an unsigned 64bit integer in wire format using the fewest bytes possible. More...
 
static uint64_t fr_nbo_to_int64v (uint8_t const *data, size_t data_len)
 
static uint16_t fr_nbo_to_uint16 (uint8_t const data[static sizeof(uint16_t)])
 Read an unsigned 16bit integer from wire format (big endian) More...
 
static uint32_t fr_nbo_to_uint24 (uint8_t const data[static 3])
 Read an unsigned 24bit integer from wire format (big endian) More...
 
static uint32_t fr_nbo_to_uint32 (uint8_t const data[static sizeof(uint32_t)])
 Read an unsigned 32bit integer from wire format (big endian) More...
 
static uint64_t fr_nbo_to_uint64 (uint8_t const data[static sizeof(uint64_t)])
 Read an unsigned 64bit integer from wire format (big endian) More...
 
static uint64_t fr_nbo_to_uint64v (uint8_t const *data, size_t data_len)
 Read an unsigned 64bit integer from wire format (big endian) with a variable length encoding. More...
 

Detailed Description

Structures and functions for converting integers to/from network byte order.

Author
Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)

Definition in file nbo.h.

Macro Definition Documentation

◆ fr_nbo_to_int16

#define fr_nbo_to_int16 (   _x)    ((int16_t) fr_nbo_to_uint16(_x))

Definition at line 176 of file nbo.h.

◆ fr_nbo_to_int32

#define fr_nbo_to_int32 (   _x)    ((int32_t) fr_nbo_to_uint32(_x))

Definition at line 177 of file nbo.h.

◆ fr_nbo_to_int64

#define fr_nbo_to_int64 (   _x)    ((int64_t) fr_nbo_to_uint64(_x))

Definition at line 178 of file nbo.h.

Function Documentation

◆ fr_bytes_from_bits()

static unsigned int fr_bytes_from_bits ( unsigned int  bits)
inlinestatic

Convert bits (as in prefix length) to bytes, rounding up.

Parameters
bitsnumber of bits in the prefix
Returns
number of bytes taken to store the prefix

Definition at line 228 of file nbo.h.

+ Here is the caller graph for this function:

◆ fr_nbo_from_int16()

static void fr_nbo_from_int16 ( uint8_t  out[static sizeof(int16_t)],
int16_t  num 
)
inlinestatic

Write out an signed 16bit integer in wire format (big endian)

Parameters
[out]outWhere to write the integer.
[in]numto encode.

Definition at line 83 of file nbo.h.

◆ fr_nbo_from_int32()

static void fr_nbo_from_int32 ( uint8_t  out[static sizeof(int32_t)],
int32_t  num 
)
inlinestatic

Write out an signed 32bit integer in wire format (big endian)

Parameters
[out]outWhere to write the integer.
[in]numto encode.

Definition at line 94 of file nbo.h.

+ Here is the call graph for this function:

◆ fr_nbo_from_int64()

static void fr_nbo_from_int64 ( uint8_t  out[static sizeof(uint64_t)],
uint64_t  num 
)
inlinestatic

Write out an signed 64bit integer in wire format (big endian)

Parameters
[out]outWhere to write the integer.
[in]numto encode.

Definition at line 105 of file nbo.h.

+ Here is the call graph for this function:

◆ fr_nbo_from_uint16()

static void fr_nbo_from_uint16 ( uint8_t  out[static sizeof(uint16_t)],
uint16_t  num 
)
inlinestatic

Write out an unsigned 16bit integer in wire format (big endian)

Parameters
[out]outWhere to write the integer.
[in]numto encode.

Definition at line 38 of file nbo.h.

+ Here is the caller graph for this function:

◆ fr_nbo_from_uint24()

static void fr_nbo_from_uint24 ( uint8_t  out[static 3],
uint32_t  num 
)
inlinestatic

Write out an unsigned 24bit integer in wire format (big endian)

Parameters
[out]outWhere to write the integer.
[in]numto encode.

Definition at line 49 of file nbo.h.

+ Here is the caller graph for this function:

◆ fr_nbo_from_uint32()

static void fr_nbo_from_uint32 ( uint8_t  out[static sizeof(uint32_t)],
uint32_t  num 
)
inlinestatic

Write out an unsigned 32bit integer in wire format (big endian)

Parameters
[out]outWhere to write the integer.
[in]numto encode.

Definition at line 61 of file nbo.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_nbo_from_uint64()

static void fr_nbo_from_uint64 ( uint8_t  out[static sizeof(uint64_t)],
uint64_t  num 
)
inlinestatic

Write out an unsigned 64bit integer in wire format (big endian)

Parameters
[out]outWhere to write the integer.
[in]numto encode.

Definition at line 72 of file nbo.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_nbo_from_uint64v()

static size_t fr_nbo_from_uint64v ( uint8_t  out[static sizeof(uint64_t)],
uint64_t  num 
)
inlinestatic

Write out an unsigned 64bit integer in wire format using the fewest bytes possible.

Parameters
[out]outWhere to write big endian encoding of num. Should be at least 8 bytes.
[in]numNumber to encode.
Returns
the number of bytes written to out.

Definition at line 118 of file nbo.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_nbo_to_int64v()

static uint64_t fr_nbo_to_int64v ( uint8_t const *  data,
size_t  data_len 
)
inlinestatic

Definition at line 204 of file nbo.h.

+ Here is the call graph for this function:

◆ fr_nbo_to_uint16()

static uint16_t fr_nbo_to_uint16 ( uint8_t const  data[static sizeof(uint16_t)])
inlinestatic

Read an unsigned 16bit integer from wire format (big endian)

Parameters
[in]dataTo convert to a 16bit unsigned integer of native endianness.
Returns
a 16 bit unsigned integer of native endianness.

Definition at line 137 of file nbo.h.

+ Here is the caller graph for this function:

◆ fr_nbo_to_uint24()

static uint32_t fr_nbo_to_uint24 ( uint8_t const  data[static 3])
inlinestatic

Read an unsigned 24bit integer from wire format (big endian)

Parameters
[in]dataTo convert to a 24bit unsigned integer of native endianness.
Returns
a 24 bit unsigned integer of native endianness.

Definition at line 148 of file nbo.h.

+ Here is the caller graph for this function:

◆ fr_nbo_to_uint32()

static uint32_t fr_nbo_to_uint32 ( uint8_t const  data[static sizeof(uint32_t)])
inlinestatic

Read an unsigned 32bit integer from wire format (big endian)

Parameters
[in]dataTo convert to a 32bit unsigned integer of native endianness.
Returns
a 32 bit unsigned integer of native endianness.

Definition at line 158 of file nbo.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_nbo_to_uint64()

static uint64_t fr_nbo_to_uint64 ( uint8_t const  data[static sizeof(uint64_t)])
inlinestatic

Read an unsigned 64bit integer from wire format (big endian)

Parameters
[in]dataTo convert to a 64bit unsigned integer of native endianness.
Returns
a 64 bit unsigned integer of native endianness.

Definition at line 168 of file nbo.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_nbo_to_uint64v()

static uint64_t fr_nbo_to_uint64v ( uint8_t const *  data,
size_t  data_len 
)
inlinestatic

Read an unsigned 64bit integer from wire format (big endian) with a variable length encoding.

Parameters
[in]dataBuffer containing the number.
[in]data_lenLength of number.
Returns
a 64 bit unsigned integer of native endianness.

Definition at line 187 of file nbo.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: