tcpdump mailing list archives
util.c
From: alex medvedev <alexm () pycckue org>
Date: Tue, 29 Jul 2003 18:23:51 -0500 (CDT)
hallo, shouldn't prefix_len be initialized to 32 instead of 33? otherwise first bitmask[prefix_len] in the while loop becomes bitmask[33], which corresponds to the 34th element of a 33 element array. see below. -alexm ------------- in util.c: /* * Convert a 32-bit netmask to prefixlen if possible * the function returns the prefix-len; if plen == -1 * then conversion was not possible; */ int mask2plen (u_int32_t mask) { u_int32_t bitmasks[33] = { 0x00000000, 0x80000000, 0xc0000000, 0xe0000000, 0xf0000000, 0xf8000000, 0xfc000000, 0xfe000000, 0xff000000, 0xff800000, 0xffc00000, 0xffe00000, 0xfff00000, 0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000, 0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000, 0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00, 0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0, 0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff }; int prefix_len = 33; /* lets see if we can transform the mask into a prefixlen */ while (prefix_len >= 0) { if (bitmasks[prefix_len] == mask) break; prefix_len--; } return (prefix_len); } - This is the TCPDUMP workers list. It is archived at http://www.tcpdump.org/lists/workers/index.html To unsubscribe use mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe
Current thread:
- util.c alex medvedev (Jul 29)
- Re: util.c Guy Harris (Jul 29)