From 26c61695dd785c2a434b4c02a406a683c8386fcc Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Mon, 21 Oct 2024 21:31:22 -0600 Subject: wip dhcp --- libmisc/include/libmisc/endian.h | 12 ++++++++---- libmisc/include/libmisc/net.h | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'libmisc') diff --git a/libmisc/include/libmisc/endian.h b/libmisc/include/libmisc/endian.h index eaf9bae..9d172ba 100644 --- a/libmisc/include/libmisc/endian.h +++ b/libmisc/include/libmisc/endian.h @@ -17,9 +17,10 @@ typedef struct { } uint16be_t; static_assert(sizeof(uint16be_t) == 2); -static inline void uint16be_encode(uint8_t *out, uint16_t in) { +static inline size_t uint16be_encode(uint8_t *out, uint16_t in) { out[0] = (uint8_t)((in >> 8) & 0xFF); out[1] = (uint8_t)((in >> 0) & 0xFF); + return 2; } static inline uint16_t uint16be_decode(uint8_t *in) { @@ -43,11 +44,12 @@ typedef struct { } uint32be_t; static_assert(sizeof(uint32be_t) == 4); -static inline void uint32be_encode(uint8_t *out, uint32_t in) { +static inline size_t uint32be_encode(uint8_t *out, uint32_t in) { out[0] = (uint8_t)((in >> 24) & 0xFF); out[1] = (uint8_t)((in >> 16) & 0xFF); out[2] = (uint8_t)((in >> 8) & 0xFF); out[3] = (uint8_t)((in >> 0) & 0xFF); + return 4; } static inline uint32_t uint32be_decode(uint8_t *in) { @@ -75,9 +77,10 @@ typedef struct { } uint16le_t; static_assert(sizeof(uint16le_t) == 2); -static inline void uint16le_encode(uint8_t *out, uint16_t in) { +static inline size_t uint16le_encode(uint8_t *out, uint16_t in) { out[0] = (uint8_t)((in >> 0) & 0xFF); out[1] = (uint8_t)((in >> 8) & 0xFF); + return 2; } static inline uint16_t uint16le_decode(uint8_t *in) { @@ -101,11 +104,12 @@ typedef struct { } uint32le_t; static_assert(sizeof(uint32le_t) == 4); -static inline void uint32le_encode(uint8_t *out, uint32_t in) { +static inline size_t uint32le_encode(uint8_t *out, uint32_t in) { out[0] = (uint8_t)((in >> 0) & 0xFF); out[1] = (uint8_t)((in >> 8) & 0xFF); out[2] = (uint8_t)((in >> 16) & 0xFF); out[3] = (uint8_t)((in >> 24) & 0xFF); + return 4; } static inline uint32_t uint32le_decode(uint8_t *in) { diff --git a/libmisc/include/libmisc/net.h b/libmisc/include/libmisc/net.h index a733cce..e5648f5 100644 --- a/libmisc/include/libmisc/net.h +++ b/libmisc/include/libmisc/net.h @@ -15,7 +15,8 @@ struct net_ip4_addr { unsigned char octets[4]; }; -static const struct net_ip4_addr net_ip4_broadcast_addr = {{255, 255, 255, 255}}; +static const struct net_ip4_addr net_ip4_addr_broadcast = {{255, 255, 255, 255}}; +static const struct net_ip4_addr net_ip4_addr_zero = {{0, 0, 0, 0}}; struct net_eth_addr { unsigned char octets[6]; -- cgit v1.2.3-2-g168b