git: e5cb813ac477 - stable/13 - sockstat: Surround explicit IPv6 addresses with brackets
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 07 Feb 2026 12:18:43 UTC
The branch stable/13 has been updated by michaelo:
URL: https://cgit.FreeBSD.org/src/commit/?id=e5cb813ac4779d46b2dd9a483d2983ae5d104bcb
commit e5cb813ac4779d46b2dd9a483d2983ae5d104bcb
Author: Michael Osipov <michaelo@FreeBSD.org>
AuthorDate: 2025-12-26 17:27:12 +0000
Commit: Michael Osipov <michaelo@FreeBSD.org>
CommitDate: 2026-02-07 12:18:27 +0000
sockstat: Surround explicit IPv6 addresses with brackets
PR: 254611
Approved by: otis, tuexen, des
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D54375
(cherry picked from commit fe81e3944c085e765c83c4f78941d7529ceb556e)
---
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 fed63d6031f3..0b874de2b0ab 100644
--- a/usr.bin/sockstat/sockstat.c
+++ b/usr.bin/sockstat/sockstat.c
@@ -61,6 +61,7 @@
#include <netdb.h>
#include <pwd.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -855,6 +856,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:
@@ -865,6 +867,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:
@@ -878,6 +882,11 @@ printaddr(struct sockaddr_storage *ss)
if (error)
errx(1, "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