MCPcopy Create free account
hub / github.com/F-Stack/f-stack / contigmask

Function contigmask

tools/ipfw/ipfw2.c:1153–1165  ·  view source on GitHub ↗

* Returns the number of bits set (from left) in a contiguous bitmask, * or -1 if the mask is not contiguous. * XXX this needs a proper fix. * This effectively works on masks in big-endian (network) format. * when compiled on little endian architectures. * * First bit is bit 7 of the first byte -- note, for MAC addresses, * the first bit on the wire is bit 0 of the first byte. * len is the

Source from the content-addressed store, hash-verified

1151 * len is the max length in bits.
1152 */
1153int
1154contigmask(const uint8_t *p, int len)
1155{
1156 int i, n;
1157
1158 for (i=0; i<len ; i++)
1159 if ( (p[i/8] & (1 << (7 - (i%8)))) == 0) /* first bit unset */
1160 break;
1161 for (n=i+1; n < len; n++)
1162 if ( (p[n/8] & (1 << (7 - (n%8)))) != 0)
1163 return -1; /* mask not contiguous */
1164 return i;
1165}
1166
1167/*
1168 * print flags set/clear in the two bitmasks passed as parameters.

Callers 5

print_ip6Function · 0.85
fill_ip6Function · 0.85
print_ipFunction · 0.85
format_macFunction · 0.85
fill_ipFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected