Add function that zeros bits after prefix_len'th bit in an address. Put it in net.h so it can be use by both netconfig.c and icmp6.c, potentially others. --- ell/net.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ell/net.h b/ell/net.h index 0521d75..e193eef 100644 --- a/ell/net.h +++ b/ell/net.h @@ -61,6 +61,19 @@ static inline bool l_net_prefix_matches(const void *a, const void *b, return !bits || ((left ^ right) & (0xff00u >> bits)) == 0; } +static inline void l_net_clear_host_bits(uint8_t *address, uint8_t prefix_len, + uint8_t bytes) +{ + uint8_t last_byte = prefix_len / 8; + + if (prefix_len & 7) { + address[last_byte] &= 0xff00 >> (prefix_len & 7); + last_byte++; + } + + memset(address + last_byte, 0, bytes - last_byte); +} + #ifdef __cplusplus } #endif -- 2.32.0