diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-05 08:18:17 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-05 08:46:26 +0100 |
commit | a4798d4e6d88c2be2625ce62d8326eaa9b80f2ee (patch) | |
tree | d5f1f6594f37fdcd1f28d61b03c03c0194b7ad75 /src/basic/in-addr-util.c | |
parent | util: use strndup() instead of strndupa() (diff) | |
download | systemd-a4798d4e6d88c2be2625ce62d8326eaa9b80f2ee.tar.xz systemd-a4798d4e6d88c2be2625ce62d8326eaa9b80f2ee.zip |
util: introduce in_addr_default_prefix_from_string() and friends
It is similar to in_addr_prefix_from_string() but it determines
the prefix length from address if it is not specified.
Diffstat (limited to 'src/basic/in-addr-util.c')
-rw-r--r-- | src/basic/in-addr-util.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c index 9a6b1b3d61..4cf6ab6974 100644 --- a/src/basic/in-addr-util.c +++ b/src/basic/in-addr-util.c @@ -495,8 +495,9 @@ int in_addr_parse_prefixlen(int family, const char *p, unsigned char *ret) { return 0; } -int in_addr_prefix_from_string( +int in_addr_prefix_from_string_internal( const char *p, + bool use_default_prefixlen, int family, union in_addr_union *ret_prefix, unsigned char *ret_prefixlen) { @@ -530,6 +531,10 @@ int in_addr_prefix_from_string( r = in_addr_parse_prefixlen(family, e+1, &k); if (r < 0) return r; + } else if (family == AF_INET && use_default_prefixlen) { + r = in4_addr_default_prefixlen(&buffer.in, &k); + if (r < 0) + return r; } else k = FAMILY_ADDRESS_SIZE(family) * 8; @@ -541,8 +546,9 @@ int in_addr_prefix_from_string( return 0; } -int in_addr_prefix_from_string_auto( +int in_addr_prefix_from_string_auto_internal( const char *p, + bool use_default_prefixlen, int *ret_family, union in_addr_union *ret_prefix, unsigned char *ret_prefixlen) { @@ -573,6 +579,10 @@ int in_addr_prefix_from_string_auto( r = in_addr_parse_prefixlen(family, e+1, &k); if (r < 0) return r; + } else if (family == AF_INET && use_default_prefixlen) { + r = in4_addr_default_prefixlen(&buffer.in, &k); + if (r < 0) + return r; } else k = FAMILY_ADDRESS_SIZE(family) * 8; |