summaryrefslogtreecommitdiff
path: root/lib/prefix.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@openbsd.org>2019-01-15 00:39:39 -0200
committerGitHub <noreply@github.com>2019-01-15 00:39:39 -0200
commitd8e331eb0e66991b9c280c6f004eb2f8da4c2e28 (patch)
treedf71b84b36f90e985ba34b4a159f350c93d598e9 /lib/prefix.c
parent31107203da7ee52b1b289c2c387f9039a0053f9a (diff)
parent61be6e94ab21b6883884e3a6cbbfc5e4e1808bab (diff)
Merge pull request #3180 from qlyoung/prefixlen-u8-to-u16
lib: convert prefixlen to 16-bit integer
Diffstat (limited to 'lib/prefix.c')
-rw-r--r--lib/prefix.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/prefix.c b/lib/prefix.c
index 858f860ee8..0203301562 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,16 @@ 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;
+
+ /*
+ * clz: count leading zeroes. sadly, the behaviour of this builtin is
+ * undefined for a 0 argument, even though most CPUs give 32
+ */
+ return tmp ? __builtin_clz(tmp) : 32;
}
/* Apply mask to IPv4 prefix (network byte order). */