Go to the documentation of this file.
26 # include "clang_compat.h"
41 typedef union __attribute__((packed)) {
51 typedef union __attribute__((packed)) {
63 typedef union __attribute__((packed)) {
77 typedef union __attribute__((packed)) {
87 typedef union __attribute__((packed)) {
99 typedef union __attribute__((packed)) {
309 static inline uint16_t
htons(uint16_t v);
317 static inline uint32_t
htonl(uint32_t v);
325 static inline uint64_t
htonll(uint64_t v);
333 static inline uint16_t
ntohs(uint16_t v);
341 static inline uint32_t
ntohl(uint32_t v);
349 static inline uint64_t
ntohll(uint64_t v);
354 #ifdef HAVE_NO_BUILTIN_BSWAP16
355 static inline unsigned short __builtin_bswap16(
unsigned short a)
357 return (a << 8) | (a >> 8);
363 #ifndef MODULE_MSP430_COMMON
364 return __builtin_bswap16(v);
367 uint8_t tmp = result.
u8[0];
368 result.
u8[0] = result.
u8[1];
376 return __builtin_bswap32(v);
381 return __builtin_bswap64(v);
429 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
430 # define _byteorder_swap(V, T) (byteorder_swap ## T((V)))
431 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
432 # define _byteorder_swap(V, T) (V)
434 # error "Byte order is neither little nor big!"
473 static inline uint16_t
htons(uint16_t v)
478 static inline uint32_t
htonl(uint32_t v)
483 static inline uint64_t
htonll(uint64_t v)
488 static inline uint16_t
ntohs(uint16_t v)
495 static inline uint32_t
ntohl(uint32_t v)
502 static inline uint64_t
ntohll(uint64_t v)
511 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
512 return (uint16_t)((buf[0] << 8) | (buf[1] << 0));
513 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
522 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
523 return (((uint32_t) buf[0] << 24)
524 | ((uint32_t) buf[1] << 16)
525 | ((uint32_t) buf[2] << 8)
526 | ((uint32_t) buf[3] << 0));
527 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
536 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
537 return (((uint64_t) buf[0] << 56)
538 | ((uint64_t) buf[1] << 48)
539 | ((uint64_t) buf[2] << 40)
540 | ((uint64_t) buf[3] << 32)
541 | ((uint64_t) buf[4] << 24)
542 | ((uint64_t) buf[5] << 16)
543 | ((uint64_t) buf[6] << 8)
544 | ((uint64_t) buf[7] << 0));
545 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
554 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
555 buf[0] = (uint8_t)(val >> 8);
556 buf[1] = (uint8_t)(val >> 0);
557 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
560 memcpy(buf, &val,
sizeof(val));
566 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
567 buf[0] = (uint8_t)(val >> 24);
568 buf[1] = (uint8_t)(val >> 16);
569 buf[2] = (uint8_t)(val >> 8);
570 buf[3] = (uint8_t)(val >> 0);
571 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
574 memcpy(buf, &val,
sizeof(val));
580 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
581 buf[0] = (uint8_t)(val >> 56);
582 buf[1] = (uint8_t)(val >> 48);
583 buf[2] = (uint8_t)(val >> 40);
584 buf[3] = (uint8_t)(val >> 32);
585 buf[4] = (uint8_t)(val >> 24);
586 buf[5] = (uint8_t)(val >> 16);
587 buf[6] = (uint8_t)(val >> 8);
588 buf[7] = (uint8_t)(val >> 0);
589 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
592 memcpy(buf, &val,
sizeof(val));
A 32 bit integer in little endian.
static uint16_t byteorder_swaps(uint16_t v)
Swap byte order, 16 bit.
static uint32_t byteorder_bebuftohl(const uint8_t *buf)
Read a big endian encoded unsigned integer from a buffer into host byte order encoded variable,...
A 32 bit integer in big endian aka network byte order.
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,...
A 16 bit integer in little endian.
static uint64_t ntohll(uint64_t v)
Convert from network byte order to host byte order, 64 bit.
A 16 bit integer in big endian aka network byte order.
static uint16_t ntohs(uint16_t v)
Convert from network byte order to host byte order, 16 bit.
static uint64_t unaligned_get_u64(const void *ptr)
Get uint64_t from possibly unaligned pointer.
uint8_t u8[2]
8 bit representation
static be_uint32_t byteorder_ltobl(le_uint32_t v)
Convert from little endian to big endian, 32 bit.
be_uint32_t network_uint32_t
A 32 bit integer in network byte order.
static uint64_t htonll(uint64_t v)
Convert from host byte order to network byte order, 64 bit.
uint64_t u64
64 bit representation
static uint16_t unaligned_get_u16(const void *ptr)
Get uint16_t from possibly unaligned pointer.
static le_uint16_t byteorder_btols(be_uint16_t v)
Convert from big endian to little endian, 16 bit.
uint32_t u32
32 bit representation
static uint32_t byteorder_ntohl(network_uint32_t v)
Convert from network byte order to host byte order, 32 bit.
#define _byteorder_swap(V, T)
Swaps the byteorder according to the endianness.
static uint64_t byteorder_bebuftohll(const uint8_t *buf)
Read a big endian encoded unsigned integer from a buffer into host byte order encoded variable,...
static network_uint16_t byteorder_htons(uint16_t v)
Convert from host byte order to network byte order, 16 bit.
static uint64_t byteorder_swapll(uint64_t v)
Swap byte order, 64 bit.
static uint64_t byteorder_ntohll(network_uint64_t v)
Convert from network byte order to host byte order, 64 bit.
static network_uint32_t byteorder_htonl(uint32_t v)
Convert from host byte order to network byte order, 32 bit.
static uint32_t byteorder_swapl(uint32_t v)
Swap byte order, 32 bit.
static void byteorder_htobebufl(uint8_t *buf, uint32_t val)
Write a host byte order encoded unsigned integer as big endian encoded value into a buffer,...
static be_uint64_t byteorder_ltobll(le_uint64_t v)
Convert from little endian to big endian, 64 bit.
Unaligned but safe memory access functions.
static uint32_t htonl(uint32_t v)
Convert from host byte order to network byte order, 32 bit.
static le_uint32_t byteorder_btoll(be_uint32_t v)
Convert from big endian to little endian, 32 bit.
static uint32_t ntohl(uint32_t v)
Convert from network byte order to host byte order, 32 bit.
static uint32_t unaligned_get_u32(const void *ptr)
Get uint32_t from possibly unaligned pointer.
static void byteorder_htobebufll(uint8_t *buf, uint64_t val)
Write a host byte order encoded unsigned integer as big endian encoded value into a buffer,...
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,...
static uint16_t htons(uint16_t v)
Convert from host byte order to network byte order, 16 bit.
static uint16_t byteorder_ntohs(network_uint16_t v)
Convert from network byte order to host byte order, 16 bit.
be_uint16_t network_uint16_t
A 16 bit integer in network byte order.
A 64 bit integer in little endian.
uint16_t u16
16 bit representation
uint64_t u64
64 bit representation
static le_uint64_t byteorder_btolll(be_uint64_t v)
Convert from big endian to little endian, 64 bit.
uint32_t u32
32 bit representation
A 64 bit integer in big endian aka network byte order.
static be_uint16_t byteorder_ltobs(le_uint16_t v)
Convert from little endian to big endian, 16 bit.
be_uint64_t network_uint64_t
A 64 bit integer in network byte order.
uint16_t u16
16 bit representation
static network_uint64_t byteorder_htonll(uint64_t v)
Convert from host byte order to network byte order, 64 bit.