FreeBSD Bugzilla – Attachment 158798 Details for
Bug 201585
[patch] sockstat(1): add STATE field
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch
sockstat-tcp-state.diff (text/plain), 4.07 KB, created by
Vladimir Laskov
on 2015-07-15 14:19:13 UTC
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Vladimir Laskov
Created:
2015-07-15 14:19:13 UTC
Size:
4.07 KB
patch
obsolete
>Index: usr.bin/sockstat/sockstat.1 >=================================================================== >--- usr.bin/sockstat/sockstat.1 (revision 283872) >+++ usr.bin/sockstat/sockstat.1 (working copy) >@@ -27,7 +27,7 @@ > .\" > .\" $FreeBSD$ > .\" >-.Dd April 7, 2015 >+.Dd July 14, 2015 > .Dt SOCKSTAT 1 > .Os > .Sh NAME >@@ -35,7 +35,7 @@ > .Nd list open sockets > .Sh SYNOPSIS > .Nm >-.Op Fl 46cLlu >+.Op Fl 46cLlsu > .Op Fl j Ar jid > .Op Fl p Ar ports > .Op Fl P Ar protocols >@@ -83,6 +83,9 @@ > argument is a comma-separated list of protocol names, > as they are defined in > .Xr protocols 5 . >+.It Fl s >+Display the protocol state, if applicable. >+This is currently only implemented for TCP. > .It Fl u > Show > .Dv AF_LOCAL >Index: usr.bin/sockstat/sockstat.c >=================================================================== >--- usr.bin/sockstat/sockstat.c (revision 283872) >+++ usr.bin/sockstat/sockstat.c (working copy) >@@ -44,6 +44,8 @@ > #include <netinet/in.h> > #include <netinet/in_pcb.h> > #include <netinet/tcp.h> >+#define TCPSTATES /* load state names */ >+#include <netinet/tcp_fsm.h> > #include <netinet/tcp_seq.h> > #include <netinet/tcp_var.h> > #include <arpa/inet.h> >@@ -65,6 +67,7 @@ > 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_s; /* Show protocol state if applicable */ > static int opt_u; /* Show Unix domain sockets */ > static int opt_v; /* Verbose mode */ > >@@ -91,6 +94,7 @@ > int vflag; > int family; > int proto; >+ int state; > const char *protoname; > struct sockaddr_storage laddr; > struct sockaddr_storage faddr; >@@ -260,9 +264,9 @@ > const char *varname, *protoname; > size_t len, bufsize; > void *buf; >- int hash, retry, vflag; >+ int hash, retry, state, vflag; > >- vflag = 0; >+ state = vflag = 0; > if (opt_4) > vflag |= INP_IPV4; > if (opt_6) >@@ -326,6 +330,7 @@ > inp = &xtp->xt_inp; > so = &xtp->xt_socket; > protoname = xtp->xt_tp.t_flags & TF_TOE ? "toe" : "tcp"; >+ state = xtp->xt_tp.t_state; > break; > case IPPROTO_UDP: > case IPPROTO_DIVERT: >@@ -384,6 +389,8 @@ > &inp->in6p_faddr, inp->inp_fport); > } > sock->vflag = inp->inp_vflag; >+ if (proto == IPPROTO_TCP) >+ sock->state = xtp->xt_tp.t_state; > sock->protoname = protoname; > hash = (int)((uintptr_t)sock->socket % HASHSIZE); > sock->next = sockhash[hash]; >@@ -648,7 +655,14 @@ > default: > abort(); > } >- xprintf("\n"); >+ if (opt_s && s->proto == IPPROTO_TCP) { >+ while (pos < 80) >+ pos += xprintf(" "); >+ if (s->state >= 0 && s->state < TCP_NSTATES) >+ pos += xprintf("%s", tcpstates[s->state]); >+ else >+ pos += xprintf("?"); >+ } > } > > static void >@@ -659,9 +673,12 @@ > struct sock *s; > int hash, n, pos; > >- printf("%-8s %-10s %-5s %-2s %-6s %-21s %-21s\n", >+ printf("%-8s %-10s %-5s %-2s %-6s %-21s %-21s", > "USER", "COMMAND", "PID", "FD", "PROTO", > "LOCAL ADDRESS", "FOREIGN ADDRESS"); >+ if (opt_s) >+ printf(" %-12s", "STATE"); >+ printf("\n"); > setpassent(1); > for (xf = xfiles, n = 0; n < nxfiles; ++n, ++xf) { > if (xf->xf_data == NULL) >@@ -692,6 +709,7 @@ > pos += xprintf(" "); > pos += xprintf("%d ", xf->xf_fd); > displaysock(s, pos); >+ xprintf("\n"); > } > if (opt_j >= 0) > return; >@@ -705,6 +723,7 @@ > pos += xprintf("%-8s %-10s %-5s %-2s ", > "?", "?", "?", "?"); > displaysock(s, pos); >+ xprintf("\n"); > } > } > } >@@ -733,7 +752,7 @@ > usage(void) > { > fprintf(stderr, >- "Usage: sockstat [-46cLlu] [-j jid] [-p ports] [-P protocols]\n"); >+ "usage: sockstat [-46cLlsu] [-j jid] [-p ports] [-P protocols]\n"); > exit(1); > } > >@@ -744,7 +763,7 @@ > int o, i; > > opt_j = -1; >- while ((o = getopt(argc, argv, "46cj:Llp:P:uv")) != -1) >+ while ((o = getopt(argc, argv, "46cj:Llp:P:suv")) != -1) > switch (o) { > case '4': > opt_4 = 1; >@@ -770,6 +789,9 @@ > case 'P': > protos_defined = parse_protos(optarg); > break; >+ case 's': >+ opt_s = 1; >+ break; > case 'u': > opt_u = 1; > break;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 201585
: 158798