diff --git a/usr.bin/sockstat/sockstat.1 b/usr.bin/sockstat/sockstat.1 index 571b3e7041bb..8521c50348c9 100644 --- a/usr.bin/sockstat/sockstat.1 +++ b/usr.bin/sockstat/sockstat.1 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 13, 2020 +.Dd December 30, 2020 .Dt SOCKSTAT 1 .Os .Sh NAME @@ -35,7 +35,7 @@ .Nd list open sockets .Sh SYNOPSIS .Nm -.Op Fl 46CcLlSsUuvw +.Op Fl 46CcLlnSsUuvw .Op Fl j Ar jid .Op Fl p Ar ports .Op Fl P Ar protocols @@ -71,6 +71,8 @@ or do not contain the IPv6 loopback address .Li ::1 . .It Fl l Show listening sockets. +.It Fl n +Do not resolve numeric UIDs to user names. .It Fl p Ar ports Only show Internet sockets if the local or foreign port number is on the specified list. diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c index 5ddbf0775507..26f31d96b8e0 100644 --- a/usr.bin/sockstat/sockstat.c +++ b/usr.bin/sockstat/sockstat.c @@ -79,6 +79,7 @@ static int opt_c; /* Show connected sockets */ static int opt_j; /* Show specified jail */ static int opt_L; /* Don't show IPv4 or IPv6 loopback sockets */ static int opt_l; /* Show listening sockets */ +static int opt_n; /* Don't resolve UIDs to user names */ static int opt_q; /* Don't show header */ static int opt_S; /* Show protocol stack if applicable */ static int opt_s; /* Show protocol state if applicable */ @@ -1205,7 +1206,7 @@ display(void) continue; s->shown = 1; pos = 0; - if ((pwd = getpwuid(xf->xf_uid)) == NULL) + if (opt_n || (pwd = getpwuid(xf->xf_uid)) == NULL) pos += xprintf("%lu ", (u_long)xf->xf_uid); else pos += xprintf("%s ", pwd->pw_name); @@ -1304,7 +1305,7 @@ main(int argc, char *argv[]) int o, i; opt_j = -1; - while ((o = getopt(argc, argv, "46Ccj:Llp:P:qSsUuvw")) != -1) + while ((o = getopt(argc, argv, "46Ccj:Llnp:P:qSsUuvw")) != -1) switch (o) { case '4': opt_4 = 1; @@ -1329,6 +1330,9 @@ main(int argc, char *argv[]) case 'l': opt_l = 1; break; + case 'n': + opt_n = 1; + break; case 'p': parse_ports(optarg); break;