diff options
Diffstat (limited to 'lib/prefix.c')
| -rw-r--r-- | lib/prefix.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/prefix.c b/lib/prefix.c index 21c3af7d49..f3b707af3a 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -451,7 +451,7 @@ int is_zero_mac(struct ethaddr *mac) return 1; } -unsigned int prefix_bit(const uint8_t *prefix, const uint8_t prefixlen) +unsigned int prefix_bit(const uint8_t *prefix, const uint16_t prefixlen) { unsigned int offset = prefixlen / 8; unsigned int shift = 7 - (prefixlen % 8); @@ -459,7 +459,7 @@ unsigned int prefix_bit(const uint8_t *prefix, const uint8_t prefixlen) return (prefix[offset] >> shift) & 1; } -unsigned int prefix6_bit(const struct in6_addr *prefix, const uint8_t prefixlen) +unsigned int prefix6_bit(const struct in6_addr *prefix, const uint16_t prefixlen) { return prefix_bit((const uint8_t *)&prefix->s6_addr, prefixlen); } @@ -966,18 +966,12 @@ void masklen2ip(const int masklen, struct in_addr *netmask) } /* Convert IP address's netmask into integer. We assume netmask is - sequential one. Argument netmask should be network byte order. */ + * sequential one. Argument netmask should be network byte order. */ uint8_t ip_masklen(struct in_addr netmask) { uint32_t tmp = ~ntohl(netmask.s_addr); - if (tmp) - /* clz: count leading zeroes. sadly, the behaviour of this - * builtin - * is undefined for a 0 argument, even though most CPUs give 32 - */ - return __builtin_clz(tmp); - else - return 32; + + return tmp ? __builtin_clz(tmp) : 32; } /* Apply mask to IPv4 prefix (network byte order). */ |
