Lines Matching refs:prefixlen

227 int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen) {  in in_addr_prefix_next()  argument
233 return in_addr_prefix_nth(family, u, prefixlen, 1); in in_addr_prefix_next()
251 int in_addr_prefix_nth(int family, union in_addr_union *u, unsigned prefixlen, uint64_t nth) { in in_addr_prefix_nth() argument
254 if (prefixlen <= 0) in in_addr_prefix_nth()
260 if (prefixlen > 32) in in_addr_prefix_nth()
265 t = nth << (32 - prefixlen); in in_addr_prefix_nth()
273 n &= UINT32_C(0xFFFFFFFF) << (32 - prefixlen); in in_addr_prefix_nth()
281 if (prefixlen > 128) in in_addr_prefix_nth()
287 if (p >= prefixlen) { in in_addr_prefix_nth()
292 if (prefixlen - p < 8) { in in_addr_prefix_nth()
293 u->in6.s6_addr[j] &= 0xff << (8 - (prefixlen - p)); in in_addr_prefix_nth()
294 t = u->in6.s6_addr[j] + ((nth & 0xff) << (8 - (prefixlen - p))); in in_addr_prefix_nth()
295 nth >>= prefixlen - p; in in_addr_prefix_nth()
318 unsigned prefixlen) { in in_addr_random_prefix() argument
324 if (prefixlen <= 0) in in_addr_random_prefix()
332 if (prefixlen > 32) in in_addr_random_prefix()
333 prefixlen = 32; in in_addr_random_prefix()
334 if (prefixlen_fixed_part >= prefixlen) in in_addr_random_prefix()
341 n &= ((UINT32_C(1) << (prefixlen - prefixlen_fixed_part)) - 1) << (32 - prefixlen); in in_addr_random_prefix()
353 if (prefixlen > 128) in in_addr_random_prefix()
354 prefixlen = 128; in in_addr_random_prefix()
355 if (prefixlen_fixed_part >= prefixlen) in in_addr_random_prefix()
372 if (i < (prefixlen + 7) / 8) { in in_addr_random_prefix()
373 if (i < prefixlen / 8) in in_addr_random_prefix()
376 j = prefixlen % 8; in in_addr_random_prefix()
394 unsigned prefixlen, in in_addr_prefix_range() argument
408 r = in_addr_prefix_nth(family, &start, prefixlen, 0); in in_addr_prefix_range()
415 r = in_addr_prefix_nth(family, &end, prefixlen, 1); in in_addr_prefix_range()
454 int in_addr_prefix_to_string(int family, const union in_addr_union *u, unsigned prefixlen, char **r… in in_addr_prefix_to_string() argument
469 if (prefixlen > FAMILY_ADDRESS_SIZE(family) * 8) in in_addr_prefix_to_string()
482 (void) strpcpyf(&p, l, "/%u", prefixlen); in in_addr_prefix_to_string()
585 struct in_addr* in4_addr_prefixlen_to_netmask(struct in_addr *addr, unsigned char prefixlen) { in in4_addr_prefixlen_to_netmask() argument
587 assert(prefixlen <= 32); in in4_addr_prefixlen_to_netmask()
590 if (prefixlen == 0) in in4_addr_prefixlen_to_netmask()
593 addr->s_addr = htobe32((0xffffffff << (32 - prefixlen)) & 0xffffffff); in in4_addr_prefixlen_to_netmask()
598 int in4_addr_default_prefixlen(const struct in_addr *addr, unsigned char *prefixlen) { in in4_addr_default_prefixlen() argument
604 assert(prefixlen); in in4_addr_default_prefixlen()
608 *prefixlen = 8; in in4_addr_default_prefixlen()
611 *prefixlen = 16; in in4_addr_default_prefixlen()
614 *prefixlen = 24; in in4_addr_default_prefixlen()
623 unsigned char prefixlen; in in4_addr_default_subnet_mask() local
629 r = in4_addr_default_prefixlen(addr, &prefixlen); in in4_addr_default_subnet_mask()
633 in4_addr_prefixlen_to_netmask(mask, prefixlen); in in4_addr_default_subnet_mask()
637 int in4_addr_mask(struct in_addr *addr, unsigned char prefixlen) { in in4_addr_mask() argument
642 if (!in4_addr_prefixlen_to_netmask(&mask, prefixlen)) in in4_addr_mask()
649 int in6_addr_mask(struct in6_addr *addr, unsigned char prefixlen) { in in6_addr_mask() argument
655 if (prefixlen >= 8) { in in6_addr_mask()
657 prefixlen -= 8; in in6_addr_mask()
658 } else if (prefixlen > 0) { in in6_addr_mask()
659 mask = 0xFF << (8 - prefixlen); in in6_addr_mask()
660 prefixlen = 0; in in6_addr_mask()
662 assert(prefixlen == 0); in in6_addr_mask()
672 int in_addr_mask(int family, union in_addr_union *addr, unsigned char prefixlen) { in in_addr_mask() argument
677 return in4_addr_mask(&addr->in, prefixlen); in in_addr_mask()
679 return in6_addr_mask(&addr->in6, prefixlen); in in_addr_mask()
687 unsigned char prefixlen, in in4_addr_prefix_covers() argument
697 r = in4_addr_mask(&masked_prefix, prefixlen); in in4_addr_prefix_covers()
702 r = in4_addr_mask(&masked_address, prefixlen); in in4_addr_prefix_covers()
711 unsigned char prefixlen, in in6_addr_prefix_covers() argument
721 r = in6_addr_mask(&masked_prefix, prefixlen); in in6_addr_prefix_covers()
726 r = in6_addr_mask(&masked_address, prefixlen); in in6_addr_prefix_covers()
736 unsigned char prefixlen, in in_addr_prefix_covers() argument
744 return in4_addr_prefix_covers(&prefix->in, prefixlen, &address->in); in in_addr_prefix_covers()
746 return in6_addr_prefix_covers(&prefix->in6, prefixlen, &address->in6); in in_addr_prefix_covers()