Tor  0.4.7.0-alpha-dev
Functions
bytes.h File Reference

Inline functions for reading and writing multibyte values from the middle of strings, and for manipulating byte order. More...

#include <string.h>
#include "lib/cc/torint.h"

Go to the source code of this file.

Functions

static uint8_t get_uint8 (const void *cp)
 
static void set_uint8 (void *cp, uint8_t v)
 
static uint16_t get_uint16 (const void *cp)
 
static uint32_t get_uint32 (const void *cp)
 
static uint64_t get_uint64 (const void *cp)
 
static void set_uint16 (void *cp, uint16_t v)
 
static void set_uint32 (void *cp, uint32_t v)
 
static void set_uint64 (void *cp, uint64_t v)
 
static uint16_t tor_htons (uint16_t a)
 
static uint16_t tor_ntohs (uint16_t a)
 
static uint32_t tor_htonl (uint32_t a)
 
static uint32_t tor_ntohl (uint32_t a)
 
static uint64_t tor_htonll (uint64_t a)
 
static uint64_t tor_ntohll (uint64_t a)
 

Detailed Description

Inline functions for reading and writing multibyte values from the middle of strings, and for manipulating byte order.

Definition in file bytes.h.

Function Documentation

◆ get_uint16()

static uint16_t get_uint16 ( const void *  cp)
inlinestatic

Read a 16-bit value beginning at cp. Equivalent to *(uint16_t*)(cp), but will not cause segfaults on platforms that forbid unaligned memory access.

Definition at line 42 of file bytes.h.

Referenced by cell_unpack(), fetch_ext_or_command_from_buf(), packed_cell_get_circid(), parse_create2_payload(), peek_buf_has_control0_command(), and relay_header_unpack().

◆ get_uint32()

static uint32_t get_uint32 ( const void *  cp)
inlinestatic

Read a 32-bit value beginning at cp. Equivalent to *(uint32_t*)(cp), but will not cause segfaults on platforms that forbid unaligned memory access.

Definition at line 54 of file bytes.h.

Referenced by cell_unpack(), connected_cell_parse(), get_random_virtual_addr(), and packed_cell_get_circid().

◆ get_uint64()

static uint64_t get_uint64 ( const void *  cp)
inlinestatic

Read a 64-bit value beginning at cp. Equivalent to *(uint64_t*)(cp), but will not cause segfaults on platforms that forbid unaligned memory access.

Definition at line 66 of file bytes.h.

◆ get_uint8()

static uint8_t get_uint8 ( const void *  cp)
inlinestatic

◆ set_uint16()

static void set_uint16 ( void *  cp,
uint16_t  v 
)
inlinestatic

Set a 16-bit value beginning at cp to v. Equivalent to *(uint16_t*)(cp) = v, but will not cause segfaults on platforms that forbid unaligned memory access.

Definition at line 78 of file bytes.h.

Referenced by cell_pack(), connection_write_ext_or_command(), control_send_v0_reject(), relay_header_pack(), and var_cell_pack_header().

◆ set_uint32()

static void set_uint32 ( void *  cp,
uint32_t  v 
)
inlinestatic

Set a 32-bit value beginning at cp to v. Equivalent to *(uint32_t*)(cp) = v, but will not cause segfaults on platforms that forbid unaligned memory access.

Definition at line 87 of file bytes.h.

Referenced by cell_pack(), connected_cell_format_payload(), generate_srv(), get_random_virtual_addr(), and var_cell_pack_header().

◆ set_uint64()

static void set_uint64 ( void *  cp,
uint64_t  v 
)
inlinestatic

Set a 64-bit value beginning at cp to v. Equivalent to *(uint64_t*)(cp) = v, but will not cause segfaults on platforms that forbid unaligned memory access.

Definition at line 96 of file bytes.h.

Referenced by commit_encode(), generate_srv(), and reveal_encode().

◆ set_uint8()

static void set_uint8 ( void *  cp,
uint8_t  v 
)
inlinestatic

Store an 8-bit value from v to cp.

Definition at line 31 of file bytes.h.

Referenced by build_hs_address(), build_hs_checksum(), cell_pack(), connected_cell_format_payload(), relay_header_pack(), and var_cell_pack_header().

◆ tor_htonl()

static uint32_t tor_htonl ( uint32_t  a)
inlinestatic

Convert a 32-bit value from host order to network order (big-endian).

Definition at line 163 of file bytes.h.

Referenced by ope_get_cipher(), tor_htonll(), and tor_ntohl().

◆ tor_htonll()

static uint64_t tor_htonll ( uint64_t  a)
inlinestatic

Return a uint64_t value from a in network byte order.

Definition at line 184 of file bytes.h.

Referenced by build_mac(), commit_encode(), crypto_mac_sha3_256(), generate_srv(), reveal_encode(), and tor_ntohll().

◆ tor_htons()

static uint16_t tor_htons ( uint16_t  a)
inlinestatic

Convert a 16-bit value from host order to network order (big-endian).

Definition at line 142 of file bytes.h.

Referenced by tor_ntohs().

◆ tor_ntohl()

static uint32_t tor_ntohl ( uint32_t  a)
inlinestatic

Convert a 32-bit value from network order (big-endian) to host order.

Definition at line 177 of file bytes.h.

◆ tor_ntohll()

static uint64_t tor_ntohll ( uint64_t  a)
inlinestatic

Return a uint64_t value from a in host byte order.

Definition at line 193 of file bytes.h.

◆ tor_ntohs()

static uint16_t tor_ntohs ( uint16_t  a)
inlinestatic

Convert a 16-bit value from network order (big-endian) to host order.

Definition at line 154 of file bytes.h.