summaryrefslogtreecommitdiff
path: root/lib/prefix.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/prefix.c')
-rw-r--r--lib/prefix.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/prefix.c b/lib/prefix.c
index 21c3af7d49..07eb1785b7 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);
}
@@ -820,7 +820,7 @@ const char *prefix_family_str(const struct prefix *p)
}
/* Allocate new prefix_ipv4 structure. */
-struct prefix_ipv4 *prefix_ipv4_new()
+struct prefix_ipv4 *prefix_ipv4_new(void)
{
struct prefix_ipv4 *p;
@@ -853,7 +853,7 @@ int str2prefix_ipv4(const char *str, struct prefix_ipv4 *p)
/* String doesn't contail slash. */
if (pnt == NULL) {
/* Convert string to prefix. */
- ret = inet_aton(str, &p->prefix);
+ ret = inet_pton(AF_INET, str, &p->prefix);
if (ret == 0)
return 0;
@@ -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). */
@@ -1361,7 +1359,7 @@ const char *prefix2str(union prefixconstptr pu, char *str, int size)
return str;
}
-struct prefix *prefix_new()
+struct prefix *prefix_new(void)
{
struct prefix *p;