util-lib: move things that parse ifnames to shared/
In subsequent commits, calls to if_nametoindex() will be replaced by a wrapper that falls back to alternative name resolution over netlink. netlink support requires libsystemd (for sd-netlink), and we don't want to add any functions that require netlink in basic/. So stuff that calls if_nametoindex() for user supplied interface names, and everything that depends on that, needs to be moved.
This commit is contained in:
@@ -439,42 +439,6 @@ int in_addr_from_string_auto(const char *s, int *ret_family, union in_addr_union
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int in_addr_ifindex_from_string_auto(const char *s, int *family, union in_addr_union *ret_addr, int *ret_ifindex) {
|
||||
_cleanup_free_ char *buf = NULL;
|
||||
const char *suffix;
|
||||
int r, ifindex = 0;
|
||||
|
||||
assert(s);
|
||||
assert(family);
|
||||
assert(ret_addr);
|
||||
|
||||
/* Similar to in_addr_from_string_auto() but also parses an optionally appended IPv6 zone suffix ("scope id")
|
||||
* if one is found. */
|
||||
|
||||
suffix = strchr(s, '%');
|
||||
if (suffix) {
|
||||
if (ret_ifindex) {
|
||||
/* If we shall return the interface index, try to parse it */
|
||||
ifindex = parse_ifindex_or_ifname(suffix + 1);
|
||||
if (ifindex < 0)
|
||||
return ifindex;
|
||||
}
|
||||
|
||||
s = buf = strndup(s, suffix - s);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
r = in_addr_from_string_auto(s, family, ret_addr);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (ret_ifindex)
|
||||
*ret_ifindex = ifindex;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
unsigned char in4_addr_netmask_to_prefixlen(const struct in_addr *addr) {
|
||||
assert(addr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user