summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-01-30 17:23:34 +0100
committerTom Gundersen <teg@jklm.no>2014-01-30 17:23:34 +0100
commitba91431154ad7bac82ddf0a540ec1b40db62d782 (patch)
treef62b3c96896aeb04d8110c86e219f7b76f61a470 /src
parent32216660c7f01bac69ee2ac924e53684a1f8d549 (diff)
shared: net - use u32ctz to compute prefixlen
Diffstat (limited to 'src')
-rw-r--r--src/shared/net-util.c11
1 files changed, 1 insertions, 10 deletions
diff --git a/src/shared/net-util.c b/src/shared/net-util.c
index 630be18e56..ba21ae437f 100644
--- a/src/shared/net-util.c
+++ b/src/shared/net-util.c
@@ -59,18 +59,9 @@ bool net_match_config(const struct ether_addr *match_mac,
}
unsigned net_netmask_to_prefixlen(const struct in_addr *addr) {
- unsigned len = 0;
- uint32_t mask;
-
assert(addr);
- mask = be32toh(addr->s_addr);
- while (mask) {
- len++;
- mask = mask << 1;
- }
-
- return len;
+ return 32 - u32ctz(be32toh(addr->s_addr));
}
int config_parse_ifname(const char *unit,