]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: make in_addr_ifindex_to_string() an alias of in_addr_port_ifindex_name_to_string()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 4 Sep 2020 07:14:14 +0000 (16:14 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 4 Sep 2020 11:05:58 +0000 (20:05 +0900)
src/basic/in-addr-util.c
src/basic/in-addr-util.h

index ea50e26197f48a7253dcb4cfcbaeb1f2de4bbd63..f0ce6900ef11d2a45b19be39238f8343492f9ceb 100644 (file)
@@ -402,46 +402,6 @@ int in_addr_prefix_to_string(int family, const union in_addr_union *u, unsigned
         return 0;
 }
 
-int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifindex, char **ret) {
-        _cleanup_free_ char *x = NULL;
-        size_t l;
-        int r;
-
-        assert(u);
-        assert(ret);
-
-        /* Much like in_addr_to_string(), but optionally appends the zone interface index to the address, to properly
-         * handle IPv6 link-local addresses. */
-
-        if (family != AF_INET6)
-                goto fallback;
-        if (ifindex <= 0)
-                goto fallback;
-
-        r = in_addr_is_link_local(family, u);
-        if (r < 0)
-                return r;
-        if (r == 0)
-                goto fallback;
-
-        l = INET6_ADDRSTRLEN + 1 + DECIMAL_STR_MAX(ifindex) + 1;
-        x = new(char, l);
-        if (!x)
-                return -ENOMEM;
-
-        errno = 0;
-        if (!inet_ntop(family, u, x, l))
-                return errno_or_else(EINVAL);
-
-        sprintf(strchr(x, 0), "%%%i", ifindex);
-
-        *ret = TAKE_PTR(x);
-        return 0;
-
-fallback:
-        return in_addr_to_string(family, u, ret);
-}
-
 int in_addr_port_ifindex_name_to_string(int family, const union in_addr_union *u, uint16_t port, int ifindex, const char *server_name, char **ret) {
         _cleanup_free_ char *ip_str = NULL, *x = NULL;
         int r;
index 03583f25661bc44e742b037a1909470d181000e4..e0ef972952f88dcf2e30f08630b686ee4ec0dcec 100644 (file)
@@ -41,8 +41,10 @@ int in_addr_prefix_nth(int family, union in_addr_union *u, unsigned prefixlen, u
 int in_addr_random_prefix(int family, union in_addr_union *u, unsigned prefixlen_fixed_part, unsigned prefixlen);
 int in_addr_to_string(int family, const union in_addr_union *u, char **ret);
 int in_addr_prefix_to_string(int family, const union in_addr_union *u, unsigned prefixlen, char **ret);
-int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifindex, char **ret);
 int in_addr_port_ifindex_name_to_string(int family, const union in_addr_union *u, uint16_t port, int ifindex, const char *server_name, char **ret);
+static inline int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifindex, char **ret) {
+        return in_addr_port_ifindex_name_to_string(family, u, 0, ifindex, NULL, ret);
+}
 int in_addr_from_string(int family, const char *s, union in_addr_union *ret);
 int in_addr_from_string_auto(const char *s, int *ret_family, union in_addr_union *ret);