| 199 | } |
| 200 | |
| 201 | int |
| 202 | in6_mask2len(struct in6_addr *mask, u_char *lim0) |
| 203 | { |
| 204 | int x = 0, y; |
| 205 | u_char *lim = lim0, *p; |
| 206 | |
| 207 | /* ignore the scope_id part */ |
| 208 | if (lim0 == NULL || lim0 - (u_char *)mask > sizeof(*mask)) |
| 209 | lim = (u_char *)mask + sizeof(*mask); |
| 210 | for (p = (u_char *)mask; p < lim; x++, p++) { |
| 211 | if (*p != 0xff) |
| 212 | break; |
| 213 | } |
| 214 | y = 0; |
| 215 | if (p < lim) { |
| 216 | for (y = 0; y < 8; y++) { |
| 217 | if ((*p & (0x80 >> y)) == 0) |
| 218 | break; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * when the limit pointer is given, do a stricter check on the |
| 224 | * remaining bits. |
| 225 | */ |
| 226 | if (p < lim) { |
| 227 | if (y != 0 && (*p & (0x00ff >> y)) != 0) |
| 228 | return (-1); |
| 229 | for (p = p + 1; p < lim; p++) |
| 230 | if (*p != 0) |
| 231 | return (-1); |
| 232 | } |
| 233 | |
| 234 | return x * 8 + y; |
| 235 | } |
| 236 | |
| 237 | #ifdef COMPAT_FREEBSD32 |
| 238 | struct in6_ndifreq32 { |
no outgoing calls
no test coverage detected