diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-08-11 22:44:51 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-08-11 22:46:42 +0200 |
commit | 44e7b9492617408130d11ffa451c2660942974f6 (patch) | |
tree | 3f92bbd49b5c08ba427eb0add72322d0b4f9fe80 /src/libsystemd-network/network-internal.c | |
parent | cedc8c44d43c8b6689ae5f5ebe1aabb7ad9755ba (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/libsystemd-network/network-internal.c')
-rw-r--r-- | src/libsystemd-network/network-internal.c | 52 |
1 files changed, 5 insertions, 47 deletions
diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index 7f744215cc..208c314695 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -27,28 +27,27 @@ #include "strv.h" #include "siphash24.h" #include "libudev-private.h" -#include "network-internal.h" #include "dhcp-lease-internal.h" #include "log.h" #include "utf8.h" #include "util.h" #include "conf-parser.h" #include "condition.h" +#include "network-internal.h" const char *net_get_name(struct udev_device *device) { - const char *name = NULL, *field = NULL; + const char *name, *field; assert(device); /* fetch some persistent data unique (on this machine) to this device */ - FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", - "ID_NET_NAME_PATH", "ID_NET_NAME_MAC") { + FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", "ID_NET_NAME_PATH", "ID_NET_NAME_MAC") { name = udev_device_get_property_value(device, field); if (name) - break; + return name; } - return name; + return NULL; } #define HASH_KEY SD_ID128_MAKE(d3,1e,48,fa,90,fe,4b,4c,9d,af,d5,d7,a1,b1,2e,8a) @@ -133,12 +132,6 @@ bool net_match_config(const struct ether_addr *match_mac, return 1; } -unsigned net_netmask_to_prefixlen(const struct in_addr *addr) { - assert(addr); - - return 32 - u32ctz(be32toh(addr->s_addr)); -} - int config_parse_net_condition(const char *unit, const char *filename, unsigned line, @@ -304,41 +297,6 @@ int config_parse_hwaddr(const char *unit, return 0; } -int net_parse_inaddr(const char *address, int *family, void *dst) { - int r; - - assert(address); - assert(family); - assert(dst); - - /* IPv4 */ - r = inet_pton(AF_INET, address, dst); - if (r > 0) { - /* succsefully parsed IPv4 address */ - if (*family == AF_UNSPEC) - *family = AF_INET; - else if (*family != AF_INET) - return -EINVAL; - } else if (r < 0) - return -errno; - else { - /* not an IPv4 address, so let's try IPv6 */ - r = inet_pton(AF_INET6, address, dst); - if (r > 0) { - /* successfully parsed IPv6 address */ - if (*family == AF_UNSPEC) - *family = AF_INET6; - else if (*family != AF_INET6) - return -EINVAL; - } else if (r < 0) - return -errno; - else - return -EINVAL; - } - - return 0; -} - void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size) { unsigned i; |