summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>2009-05-17 00:05:29 +0200
committerGuy Harris <gharris@steve.local>2009-05-21 10:29:24 -0700
commit127b352b40cbbc12b6da8f300557596c385dfc8c (patch)
treecc19efbf4bc4f1dcfa0c2ed59e76e1602ebdb13c /util.c
parent72553e343da66ecfb6e7826a2fce121b9015cffd (diff)
downloadtcpdump-127b352b40cbbc12b6da8f300557596c385dfc8c.tar.gz
util.c: Add the `mask62plen' utility function.
The function does the same as `mask2plen' but for IPv6. Signed-off-by: Florian Forster <octo@leeloo.lan.home.verplant.org>
Diffstat (limited to 'util.c')
-rw-r--r--util.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/util.c b/util.c
index 784b09b7..526a0611 100644
--- a/util.c
+++ b/util.c
@@ -439,6 +439,35 @@ mask2plen (u_int32_t mask)
return (prefix_len);
}
+#ifdef INET6
+int mask62plen(const u_char *mask)
+{
+ u_char bitmasks[] =
+ {
+ 0x00, 0x80, 0xc0, 0xe0,
+ 0xf0, 0xf8, 0xfc, 0xfe, 0xff
+ };
+ int cidr_len = 0;
+ int byte;
+
+ for (byte = 0; byte < 16; byte++)
+ {
+ int bits;
+
+ for (bits = 0; bits < (sizeof (bitmasks) / sizeof (bitmasks[0])); bits++)
+ if (mask[byte] == bitmasks[bits])
+ {
+ cidr_len += bits;
+ break;
+ }
+
+ if (mask[byte] != 0xff)
+ break;
+ }
+ return (cidr_len);
+}
+#endif /* INET6 */
+
/* VARARGS */
void
error(const char *fmt, ...)