]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: introduce in_addr_port_from_string_auto()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 4 Sep 2020 04:40:31 +0000 (13:40 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 4 Sep 2020 11:05:58 +0000 (20:05 +0900)
src/shared/socket-netlink.c
src/shared/socket-netlink.h

index 32e45985b42559fcb9c539a4fede99579fc5d932..dc1b27f1655246b485f04d8b67e6f40d626fcf7a 100644 (file)
@@ -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;
index 143fc8d41a8fa36157ca59291ac54b8f3c2e5df3..7fa831a8804a9e1a83ec2b38ad39e4d3f8a620e3 100644 (file)
@@ -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;