diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-09-04 13:40:31 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-09-04 20:05:58 +0900 |
commit | 355e884dede875bc187802620b7e9ec29bdf7b9d (patch) | |
tree | db1b2043ec4a01bafbe30daa67fec04d8579157d /src | |
parent | 4650582657aa86770ca3a6b6a8ac14664bd49eac (diff) | |
download | systemd-355e884dede875bc187802620b7e9ec29bdf7b9d.tar.gz |
util: introduce in_addr_port_from_string_auto()
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/socket-netlink.c | 30 | ||||
-rw-r--r-- | src/shared/socket-netlink.h | 1 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/shared/socket-netlink.c b/src/shared/socket-netlink.c index 32e45985b4..dc1b27f165 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 143fc8d41a..7fa831a880 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; |