summaryrefslogtreecommitdiff
path: root/libmisc
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-21 21:31:22 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-21 21:31:22 -0600
commit26c61695dd785c2a434b4c02a406a683c8386fcc (patch)
tree816615159d5abd7382a57a8ede20e5387d4d39cc /libmisc
parentbc70ded6e8535f004b2c9f5f7a471fa548c33fab (diff)
wip dhcp
Diffstat (limited to 'libmisc')
-rw-r--r--libmisc/include/libmisc/endian.h12
-rw-r--r--libmisc/include/libmisc/net.h3
2 files changed, 10 insertions, 5 deletions
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];