* 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
| 1151 | * len is the max length in bits. |
| 1152 | */ |
| 1153 | int |
| 1154 | contigmask(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. |
no outgoing calls
no test coverage detected