From: Yu Watanabe Date: Fri, 4 Sep 2020 04:40:31 +0000 (+0900) Subject: util: introduce in_addr_port_from_string_auto() X-Git-Tag: v247-rc1~292^2~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=355e884dede875bc187802620b7e9ec29bdf7b9d;p=thirdparty%2Fsystemd.git util: introduce in_addr_port_from_string_auto() --- diff --git a/src/shared/socket-netlink.c b/src/shared/socket-netlink.c index 32e45985b42..dc1b27f1655 100644 --- a/src/shared/socket-netlink.c +++ b/src/shared/socket-netlink.c @@ -482,6 +482,36 @@ int in_addr_port_ifindex_name_from_string_auto( return r; } +int in_addr_port_from_string_auto( + const char *s, + int *ret_family, + union in_addr_union *ret_address, + uint16_t *ret_port) { + + union in_addr_union addr; + int family, ifindex, r; + uint16_t port; + + assert(s); + + r = in_addr_port_ifindex_name_from_string_auto(s, &family, &addr, &port, &ifindex, NULL); + if (r < 0) + return r; + + /* This does not accept interface specified. */ + if (ifindex != 0) + return -EINVAL; + + if (ret_family) + *ret_family = family; + if (ret_address) + *ret_address = addr; + if (ret_port) + *ret_port = port; + + return r; +} + struct in_addr_full *in_addr_full_free(struct in_addr_full *a) { if (!a) return NULL; diff --git a/src/shared/socket-netlink.h b/src/shared/socket-netlink.h index 143fc8d41a8..7fa831a8804 100644 --- a/src/shared/socket-netlink.h +++ b/src/shared/socket-netlink.h @@ -34,6 +34,7 @@ static inline int in_addr_ifindex_name_from_string_auto(const char *s, int *fami static inline int in_addr_ifindex_from_string_auto(const char *s, int *family, union in_addr_union *ret, int *ifindex) { return in_addr_ifindex_name_from_string_auto(s, family, ret, ifindex, NULL); } +int in_addr_port_from_string_auto(const char *s, int *ret_family, union in_addr_union *ret_address, uint16_t *ret_port); struct in_addr_full { int family;