aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMichael Tuexen <tuexen@FreeBSD.org>2017-09-13 06:57:52 +0000
committerMichael Tuexen <tuexen@FreeBSD.org>2017-09-13 06:57:52 +0000
commit83f60cb20252feabf9c47c4f7599f8c144b9159d (patch)
tree27f01a054dbe8f80e560ac938a3f860daf786c03 /usr.bin
parentefeb46889fe0a9606b5bea1e666c0058802d7d66 (diff)
downloadsrc-83f60cb20252feabf9c47c4f7599f8c144b9159d.tar.gz
src-83f60cb20252feabf9c47c4f7599f8c144b9159d.zip
Add a command line option for using a wider field for displaying
addresses. This allows the table to be consistent when IPv6 addresses have to be printed. While there, document the -v option in the man page. Sponsored by: Netflix, Inc.
Notes
Notes: svn path=/head/; revision=323521
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sockstat/sockstat.16
-rw-r--r--usr.bin/sockstat/sockstat.c23
2 files changed, 21 insertions, 8 deletions
diff --git a/usr.bin/sockstat/sockstat.1 b/usr.bin/sockstat/sockstat.1
index 55fc3beab4ba..a5819ba39142 100644
--- a/usr.bin/sockstat/sockstat.1
+++ b/usr.bin/sockstat/sockstat.1
@@ -35,7 +35,7 @@
.Nd list open sockets
.Sh SYNOPSIS
.Nm
-.Op Fl 46cLlSsUu
+.Op Fl 46cLlSsUuvw
.Op Fl j Ar jid
.Op Fl p Ar ports
.Op Fl P Ar protocols
@@ -97,6 +97,10 @@ Show
.Dv AF_LOCAL
.Pq Ux
sockets.
+.It Fl v
+Verbose mode.
+.It Fl w
+Use wider field size for displaying addresses.
.El
.Pp
If neither
diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c
index 555c5e5c35a0..a4de5d18a05b 100644
--- a/usr.bin/sockstat/sockstat.c
+++ b/usr.bin/sockstat/sockstat.c
@@ -78,6 +78,7 @@ static int opt_s; /* Show protocol state if applicable */
static int opt_U; /* Show remote UDP encapsulation port number */
static int opt_u; /* Show Unix domain sockets */
static int opt_v; /* Verbose mode */
+static int opt_w; /* Wide print area for addresses */
/*
* Default protocols to use if no -P was defined.
@@ -1020,7 +1021,8 @@ displaysock(struct sock *s, int pos)
faddr = s->faddr;
first = 1;
while (laddr != NULL || faddr != NULL) {
- while (pos < 36)
+ offset = 36;
+ while (pos < offset)
pos += xprintf(" ");
switch (s->family) {
case AF_INET:
@@ -1030,10 +1032,12 @@ displaysock(struct sock *s, int pos)
if (s->family == AF_INET6 && pos >= 58)
pos += xprintf(" ");
}
- while (pos < 58)
+ offset += opt_w ? 46 : 22;
+ while (pos < offset)
pos += xprintf(" ");
if (faddr != NULL)
pos += printaddr(&faddr->address);
+ offset += opt_w ? 46 : 22;
break;
case AF_UNIX:
if ((laddr == NULL) || (faddr == NULL))
@@ -1048,6 +1052,7 @@ displaysock(struct sock *s, int pos)
p = *(void **)&(faddr->address);
if (p == NULL) {
pos += xprintf("(not connected)");
+ offset += opt_w ? 92 : 44;
break;
}
pos += xprintf("-> ");
@@ -1065,11 +1070,11 @@ displaysock(struct sock *s, int pos)
pos += xprintf("??");
else
pos += printaddr(&s_tmp->laddr->address);
+ offset += opt_w ? 92 : 44;
break;
default:
abort();
}
- offset = 80;
if (opt_U) {
if (faddr != NULL &&
s->proto == IPPROTO_SCTP &&
@@ -1147,9 +1152,10 @@ display(void)
struct sock *s;
int hash, n, pos;
- printf("%-8s %-10s %-5s %-2s %-6s %-21s %-21s",
+ printf("%-8s %-10s %-5s %-2s %-6s %-*s %-*s",
"USER", "COMMAND", "PID", "FD", "PROTO",
- "LOCAL ADDRESS", "FOREIGN ADDRESS");
+ opt_w ? 45 : 21, "LOCAL ADDRESS",
+ opt_w ? 45 : 21, "FOREIGN ADDRESS");
if (opt_U)
printf(" %-6s", "ENCAPS");
if (opt_s) {
@@ -1228,7 +1234,7 @@ static void
usage(void)
{
fprintf(stderr,
- "usage: sockstat [-46cLlSsu] [-j jid] [-p ports] [-P protocols]\n");
+ "usage: sockstat [-46cLlSsUuvw] [-j jid] [-p ports] [-P protocols]\n");
exit(1);
}
@@ -1239,7 +1245,7 @@ main(int argc, char *argv[])
int o, i;
opt_j = -1;
- while ((o = getopt(argc, argv, "46cj:Llp:P:SsUuv")) != -1)
+ while ((o = getopt(argc, argv, "46cj:Llp:P:SsUuvw")) != -1)
switch (o) {
case '4':
opt_4 = 1;
@@ -1280,6 +1286,9 @@ main(int argc, char *argv[])
case 'v':
++opt_v;
break;
+ case 'w':
+ opt_w = 1;
+ break;
default:
usage();
}