summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-08-11 22:44:51 +0200
committerLennart Poettering <lennart@poettering.net>2014-08-11 22:46:42 +0200
commit44e7b9492617408130d11ffa451c2660942974f6 (patch)
tree3f92bbd49b5c08ba427eb0add72322d0b4f9fe80 /src/shared
parentcedc8c44d43c8b6689ae5f5ebe1aabb7ad9755ba (diff)
networkd: monopolize in_addr utility functions in shared/in-addr-util.h
Primarily, this means we get rid of net_parse_inaddr(), and replace it everywhere with in_addr_from_string() and in_addr_from_string_auto(). These functions do not clobber the callers arguments on failure, which is more close to our usual coding style.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/in-addr-util.c6
-rw-r--r--src/shared/in-addr-util.h1
2 files changed, 7 insertions, 0 deletions
diff --git a/src/shared/in-addr-util.c b/src/shared/in-addr-util.c
index 459f846173..457eedd6d8 100644
--- a/src/shared/in-addr-util.c
+++ b/src/shared/in-addr-util.c
@@ -242,3 +242,9 @@ int in_addr_from_string_auto(const char *s, int *family, union in_addr_union *re
return -EINVAL;
}
+
+unsigned in_addr_netmask_to_prefixlen(const struct in_addr *addr) {
+ assert(addr);
+
+ return 32 - u32ctz(be32toh(addr->s_addr));
+}
diff --git a/src/shared/in-addr-util.h b/src/shared/in-addr-util.h
index 7d1d6baa27..0036acee22 100644
--- a/src/shared/in-addr-util.h
+++ b/src/shared/in-addr-util.h
@@ -39,6 +39,7 @@ int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen);
int in_addr_to_string(int family, const union in_addr_union *u, char **ret);
int in_addr_from_string(int family, const char *s, union in_addr_union *ret);
int in_addr_from_string_auto(const char *s, int *family, union in_addr_union *ret);
+unsigned in_addr_netmask_to_prefixlen(const struct in_addr *addr);
static inline size_t FAMILY_ADDRESS_SIZE(int family) {
assert(family == AF_INET || family == AF_INET6);