diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-03 15:20:31 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-10 00:46:44 +0200 |
commit | b16d17a68ae8b44111b08c2689b3dee1d1f90169 (patch) | |
tree | f7a59ea5ad4e043c498ae17cbdd2aead9b3d5fe6 /src/basic/socket-util.c | |
parent | basic: convert ifname_valid_full() to take flags and allow numeric interfaces (diff) | |
download | systemd-b16d17a68ae8b44111b08c2689b3dee1d1f90169.tar.xz systemd-b16d17a68ae8b44111b08c2689b3dee1d1f90169.zip |
basic: show interface scope in sockaddr_pretty()
If the interface scope is specified, this changes the meaning of the address
quite significantly. Let's show the IPv6 scope_id if present.
Sadly we don't even have a test for sockaddr_pretty() output :(
This will be implicitly tested through socket_address_parse() later on.
Diffstat (limited to '')
-rw-r--r-- | src/basic/socket-util.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index 1f65015347..fa51997581 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -399,19 +399,23 @@ int sockaddr_pretty( if (r < 0) return -ENOMEM; } else { - char a[INET6_ADDRSTRLEN]; + char a[INET6_ADDRSTRLEN], ifname[IF_NAMESIZE + 1]; inet_ntop(AF_INET6, &sa->in6.sin6_addr, a, sizeof(a)); + if (sa->in6.sin6_scope_id != 0) + format_ifname_full(sa->in6.sin6_scope_id, ifname, FORMAT_IFNAME_IFINDEX); if (include_port) { r = asprintf(&p, - "[%s]:%u", + "[%s]:%u%s%s", a, - be16toh(sa->in6.sin6_port)); + be16toh(sa->in6.sin6_port), + sa->in6.sin6_scope_id != 0 ? "%" : "", + sa->in6.sin6_scope_id != 0 ? ifname : ""); if (r < 0) return -ENOMEM; } else { - p = strdup(a); + p = sa->in6.sin6_scope_id != 0 ? strjoin(a, "%", ifname) : strdup(a); if (!p) return -ENOMEM; } |