git: 11b616d9de3f - releng/14.4 - sockstat: Surround explicit IPv6 addresses with brackets
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 09 Feb 2026 03:09:50 UTC
The branch releng/14.4 has been updated by cperciva:
URL: https://cgit.FreeBSD.org/src/commit/?id=11b616d9de3f1d106cd9f2bfe4c45013f3b1528f
commit 11b616d9de3f1d106cd9f2bfe4c45013f3b1528f
Author: Michael Osipov <michaelo@FreeBSD.org>
AuthorDate: 2025-12-26 17:27:12 +0000
Commit: Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-02-09 03:09:35 +0000
sockstat: Surround explicit IPv6 addresses with brackets
Approved by: re (cperciva)
PR: 254611
Approved by: otis, tuexen, des
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D54375
(cherry picked from commit fe81e3944c085e765c83c4f78941d7529ceb556e)
(cherry picked from commit 03c8e3e77114530f61e0dd9f2b1757eeea033d0e)
---
usr.bin/sockstat/sockstat.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c
index 805e48715529..58950c92cafb 100644
--- a/usr.bin/sockstat/sockstat.c
+++ b/usr.bin/sockstat/sockstat.c
@@ -64,6 +64,7 @@
#include <netdb.h>
#include <pwd.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -956,6 +957,7 @@ printaddr(struct sockaddr_storage *ss)
struct sockaddr_un *sun;
char addrstr[NI_MAXHOST] = "";
int error, off, port = 0;
+ bool needs_ipv6_brackets = false;
switch (ss->ss_family) {
case AF_INET:
@@ -966,6 +968,8 @@ printaddr(struct sockaddr_storage *ss)
case AF_INET6:
if (IN6_IS_ADDR_UNSPECIFIED(&sstosin6(ss)->sin6_addr))
addrstr[0] = '*';
+ else
+ needs_ipv6_brackets = true;
port = ntohs(sstosin6(ss)->sin6_port);
break;
case AF_UNIX:
@@ -979,6 +983,11 @@ printaddr(struct sockaddr_storage *ss)
if (error)
errx(1, "cap_getnameinfo()");
}
+ if (needs_ipv6_brackets) {
+ if (port == 0)
+ return (xprintf("[%s]:*", addrstr));
+ return (xprintf("[%s]:%d", addrstr, port));
+ }
if (port == 0)
return (xprintf("%s:*", addrstr));
else