25 RCSIDH(nbo_h,
"$Id: f19bb2c0ade062a04d9cc666286dcc534ca3fa3b $")
31 #include <freeradius-devel/util/misc.h>
40 out[0] = (num >> 8) & 0xff;
51 out[0] = (num >> 16) & 0xff;
52 out[1] = (num >> 8) & 0xff;
85 out[0] = (num >> 8) & 0xff;
121 uint8_t swapped[
sizeof(uint64_t)];
129 if (ret > 8)
return 0;
133 memcpy(
out, (swapped + (
sizeof(uint64_t) - ret)), ret);
183 #define fr_nbo_to_int16(_x) ((int16_t) fr_nbo_to_uint16(_x))
184 #define fr_nbo_to_int32(_x) ((int32_t) fr_nbo_to_uint32(_x))
185 #define fr_nbo_to_int64(_x) ((int64_t) fr_nbo_to_uint64(_x))
199 if (
unlikely(data_len >
sizeof(uint64_t)))
return 0;
205 memcpy(((
uint8_t *)&num) + (
sizeof(uint64_t) - data_len),
data, data_len);
216 if (
unlikely(data_len >
sizeof(uint64_t)))
return 0;
222 memcpy(((
uint8_t *)&num) + (
sizeof(uint64_t) - data_len),
data, data_len);
223 if (*
data & 0x80) memset(((
uint8_t *)&num) + data_len, 0xff,
sizeof(num) - data_len);
237 return (bits + 7) >> 3;
#define ROUND_UP_DIV(_x, _y)
Get the ceiling value of integer division.
static uint8_t fr_high_bit_pos(uint64_t num)
Find the highest order high bit in an unsigned 64 bit integer.
static unsigned int fr_bytes_from_bits(unsigned int bits)
Convert bits (as in prefix length) to bytes, rounding up.
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)
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)
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.
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.
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)
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)
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)
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)
static uint32_t fr_nbo_to_uint24(uint8_t const data[static 3])
Read an unsigned 24bit integer from wire format (big endian)
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)
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)
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)
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)
static size_t char ** out