sockstat: Add -q option to suppress the header line

MFC after:	1 week
Sponsored by:	Gandi.net
This commit is contained in:
Emmanuel Vadot 2018-01-23 13:03:47 +00:00
parent a81a290f34
commit ee0afaa9d7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=328279
2 changed files with 21 additions and 14 deletions

View File

@ -27,7 +27,7 @@
.\" .\"
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd September 12, 2017 .Dd January 23, 2018
.Dt SOCKSTAT 1 .Dt SOCKSTAT 1
.Os .Os
.Sh NAME .Sh NAME
@ -83,6 +83,8 @@ The
argument is a comma-separated list of protocol names, argument is a comma-separated list of protocol names,
as they are defined in as they are defined in
.Xr protocols 5 . .Xr protocols 5 .
.It Fl q
Quiet mode, do not print the header line.
.It Fl S .It Fl S
Display the protocol stack, if applicable. Display the protocol stack, if applicable.
This is currently only implemented for TCP. This is currently only implemented for TCP.

View File

@ -76,6 +76,7 @@ static int opt_c; /* Show connected sockets */
static int opt_j; /* Show specified jail */ static int opt_j; /* Show specified jail */
static int opt_L; /* Don't show IPv4 or IPv6 loopback sockets */ static int opt_L; /* Don't show IPv4 or IPv6 loopback sockets */
static int opt_l; /* Show listening sockets */ static int opt_l; /* Show listening sockets */
static int opt_q; /* Don't show header */
static int opt_S; /* Show protocol stack if applicable */ static int opt_S; /* Show protocol stack if applicable */
static int opt_s; /* Show protocol state if applicable */ static int opt_s; /* Show protocol state if applicable */
static int opt_U; /* Show remote UDP encapsulation port number */ static int opt_U; /* Show remote UDP encapsulation port number */
@ -1155,19 +1156,21 @@ display(void)
struct sock *s; struct sock *s;
int hash, n, pos; int hash, n, pos;
printf("%-8s %-10s %-5s %-2s %-6s %-*s %-*s", if (opt_q != 1) {
"USER", "COMMAND", "PID", "FD", "PROTO", printf("%-8s %-10s %-5s %-2s %-6s %-*s %-*s",
opt_w ? 45 : 21, "LOCAL ADDRESS", "USER", "COMMAND", "PID", "FD", "PROTO",
opt_w ? 45 : 21, "FOREIGN ADDRESS"); opt_w ? 45 : 21, "LOCAL ADDRESS",
if (opt_U) opt_w ? 45 : 21, "FOREIGN ADDRESS");
printf(" %-6s", "ENCAPS"); if (opt_U)
if (opt_s) { printf(" %-6s", "ENCAPS");
printf(" %-12s", "PATH STATE"); if (opt_s) {
printf(" %-12s", "CONN STATE"); printf(" %-12s", "PATH STATE");
printf(" %-12s", "CONN STATE");
}
if (opt_S)
printf(" %.*s", TCP_FUNCTION_NAME_LEN_MAX, "STACK");
printf("\n");
} }
if (opt_S)
printf(" %.*s", TCP_FUNCTION_NAME_LEN_MAX, "STACK");
printf("\n");
setpassent(1); setpassent(1);
for (xf = xfiles, n = 0; n < nxfiles; ++n, ++xf) { for (xf = xfiles, n = 0; n < nxfiles; ++n, ++xf) {
if (xf->xf_data == NULL) if (xf->xf_data == NULL)
@ -1248,7 +1251,7 @@ main(int argc, char *argv[])
int o, i; int o, i;
opt_j = -1; opt_j = -1;
while ((o = getopt(argc, argv, "46cj:Llp:P:SsUuvw")) != -1) while ((o = getopt(argc, argv, "46cj:Llp:P:qSsUuvw")) != -1)
switch (o) { switch (o) {
case '4': case '4':
opt_4 = 1; opt_4 = 1;
@ -1274,6 +1277,8 @@ main(int argc, char *argv[])
case 'P': case 'P':
protos_defined = parse_protos(optarg); protos_defined = parse_protos(optarg);
break; break;
case 'q':
opt_q = 1;
case 'S': case 'S':
opt_S = 1; opt_S = 1;
break; break;