diff options
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | 2009-05-17 00:05:29 +0200 |
---|---|---|
committer | Guy Harris <gharris@steve.local> | 2009-05-21 10:29:24 -0700 |
commit | 127b352b40cbbc12b6da8f300557596c385dfc8c (patch) | |
tree | cc19efbf4bc4f1dcfa0c2ed59e76e1602ebdb13c /util.c | |
parent | 72553e343da66ecfb6e7826a2fce121b9015cffd (diff) | |
download | tcpdump-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.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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, ...) |