20 #ifndef FIRMWARE_SRC_UTILS_H_
21 #define FIRMWARE_SRC_UTILS_H_
34 #include <machine/endian.h>
37 #ifdef HAVE_ARPA_INET_H
38 #include <arpa/inet.h>
69 static inline uint16_t
JoinShort(uint8_t upper, uint8_t lower) {
70 return (upper << 8) + lower;
115 return (ptr[0] << 8) + ptr[1];
124 return (ptr[0] << 24) + (ptr[1] << 16) + (ptr[2] << 8) + ptr[3];
133 static inline uint8_t*
PushUInt16(uint8_t *ptr, uint16_t value) {
134 *ptr++ = (value >> 8);
135 *ptr++ = value & 0xff;
145 static inline uint8_t*
PushUInt32(uint8_t *ptr, uint32_t value) {
146 *ptr++ = (value >> 24);
147 *ptr++ = (value >> 16);
148 *ptr++ = (value >> 8);
149 *ptr++ = value & 0xff;
157 #endif // FIRMWARE_SRC_UTILS_H_
static uint8_t * PushUInt16(uint8_t *ptr, uint16_t value)
Copy a 16-bit value to a memory location in network-byte order.
Definition: utils.h:133
static uint8_t UInt32Byte2(uint32_t s)
Return the second-lowest byte from a 32bit value.
Definition: utils.h:96
static uint8_t UInt32Byte3(uint32_t s)
Return the lowest byte from a 32bit value.
Definition: utils.h:105
static uint32_t ExtractUInt32(const uint8_t *ptr)
Extract a uint32_t in network-byte order from a memory location.
Definition: utils.h:123
static uint16_t JoinShort(uint8_t upper, uint8_t lower)
Combine two 8-bit values to a 16-bit value.
Definition: utils.h:69
static uint8_t ShortLSB(uint16_t s)
Return the LSB from a 16bit value.
Definition: utils.h:50
static uint32_t ExtractUInt16(const uint8_t *ptr)
Extract a uint16_t in network-byte order from a memory location.
Definition: utils.h:114
static uint8_t * PushUInt32(uint8_t *ptr, uint32_t value)
Copy a 32-bit value to a memory location in network-byte order.
Definition: utils.h:145
static uint8_t UInt32Byte0(uint32_t s)
Return the MSB from a 32bit value.
Definition: utils.h:78
static uint8_t UInt32Byte1(uint32_t s)
Return the second-highest byte from a 32bit value.
Definition: utils.h:87
static uint8_t ShortMSB(uint16_t s)
Return the MSB from a 16bit value.
Definition: utils.h:59