summaryrefslogtreecommitdiff
path: root/src/libstddjb/ip4_netmask.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-07-30 13:12:52 +0000
committerLaurent Bercot <ska@appnovation.com>2024-07-30 13:12:52 +0000
commit92d5c03ef86fbd21a84d9425c456f01e6c513817 (patch)
treec9409cd5fbe78a7d2d1d9e2468aed4cfeb402ae0 /src/libstddjb/ip4_netmask.c
parentcc57ca6ab355784f4901009184ea95a9f915ef21 (diff)
downloadskalibs-92d5c03ef86fbd21a84d9425c456f01e6c513817.tar.xz
Fix small bugs, add autodelegation for IOPAUSE_EXCEPT
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb/ip4_netmask.c')
-rw-r--r--src/libstddjb/ip4_netmask.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libstddjb/ip4_netmask.c b/src/libstddjb/ip4_netmask.c
new file mode 100644
index 0000000..19f485f
--- /dev/null
+++ b/src/libstddjb/ip4_netmask.c
@@ -0,0 +1,14 @@
+/* ISC license. */
+
+#include <skalibs/uint32.h>
+#include <skalibs/fmtscan.h>
+
+int ip4_netmask (char *ip, uint8_t netmask)
+{
+ uint32_t u ;
+ if (netmask > 32) return 0 ;
+ uint32_unpack_big(ip, &u) ;
+ u &= netmask ? ~((1u << 32 - netmask) - 1) : 0 ;
+ uint32_pack_big(ip, u) ;
+ return 1 ;
+}