diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2024-07-30 13:12:52 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2024-07-30 13:12:52 +0000 |
commit | 92d5c03ef86fbd21a84d9425c456f01e6c513817 (patch) | |
tree | c9409cd5fbe78a7d2d1d9e2468aed4cfeb402ae0 /src/libstddjb/ip6_netmask.c | |
parent | cc57ca6ab355784f4901009184ea95a9f915ef21 (diff) | |
download | skalibs-92d5c03ef86fbd21a84d9425c456f01e6c513817.tar.xz |
Fix small bugs, add autodelegation for IOPAUSE_EXCEPT
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb/ip6_netmask.c')
-rw-r--r-- | src/libstddjb/ip6_netmask.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libstddjb/ip6_netmask.c b/src/libstddjb/ip6_netmask.c new file mode 100644 index 0000000..5d8b13e --- /dev/null +++ b/src/libstddjb/ip6_netmask.c @@ -0,0 +1,26 @@ +/* ISC license. */ + +#include <string.h> + +#include <skalibs/uint64.h> +#include <skalibs/fmtscan.h> + +static void apply (char *half, uint8_t netmask) +{ + uint64_t u ; + uint64_unpack_big(half, &u) ; + u &= netmask ? ~((1ull << 64 - netmask) - 1) : 0 ; + uint64_pack_big(half, u) ; +} + +int ip6_netmask (char *ip, uint8_t netmask) +{ + if (netmask > 128) return 0 ; + if (netmask <= 64) + { + apply(ip, netmask) ; + memset(ip + 8, 0, 8) ; + } + else apply(ip + 8, netmask - 64) ; + return 1 ; +} |