View | Details | Raw Unified | Return to bug 201585
Collapse All | Expand All

(-)usr.bin/sockstat/sockstat.1 (-2 / +5 lines)
Lines 27-33 Link Here
27
.\"
27
.\"
28
.\" $FreeBSD$
28
.\" $FreeBSD$
29
.\"
29
.\"
30
.Dd April 7, 2015
30
.Dd July 14, 2015
31
.Dt SOCKSTAT 1
31
.Dt SOCKSTAT 1
32
.Os
32
.Os
33
.Sh NAME
33
.Sh NAME
Lines 35-41 Link Here
35
.Nd list open sockets
35
.Nd list open sockets
36
.Sh SYNOPSIS
36
.Sh SYNOPSIS
37
.Nm
37
.Nm
38
.Op Fl 46cLlu
38
.Op Fl 46cLlsu
39
.Op Fl j Ar jid
39
.Op Fl j Ar jid
40
.Op Fl p Ar ports
40
.Op Fl p Ar ports
41
.Op Fl P Ar protocols
41
.Op Fl P Ar protocols
Lines 83-88 Link Here
83
argument is a comma-separated list of protocol names,
83
argument is a comma-separated list of protocol names,
84
as they are defined in
84
as they are defined in
85
.Xr protocols 5 .
85
.Xr protocols 5 .
86
.It Fl s
87
Display the protocol state, if applicable.
88
This is currently only implemented for TCP.
86
.It Fl u
89
.It Fl u
87
Show
90
Show
88
.Dv AF_LOCAL
91
.Dv AF_LOCAL
(-)usr.bin/sockstat/sockstat.c (-6 / +28 lines)
Lines 44-49 Link Here
44
#include <netinet/in.h>
44
#include <netinet/in.h>
45
#include <netinet/in_pcb.h>
45
#include <netinet/in_pcb.h>
46
#include <netinet/tcp.h>
46
#include <netinet/tcp.h>
47
#define TCPSTATES /* load state names */
48
#include <netinet/tcp_fsm.h>
47
#include <netinet/tcp_seq.h>
49
#include <netinet/tcp_seq.h>
48
#include <netinet/tcp_var.h>
50
#include <netinet/tcp_var.h>
49
#include <arpa/inet.h>
51
#include <arpa/inet.h>
Lines 65-70 Link Here
65
static int	 opt_j;		/* Show specified jail */
67
static int	 opt_j;		/* Show specified jail */
66
static int	 opt_L;		/* Don't show IPv4 or IPv6 loopback sockets */
68
static int	 opt_L;		/* Don't show IPv4 or IPv6 loopback sockets */
67
static int	 opt_l;		/* Show listening sockets */
69
static int	 opt_l;		/* Show listening sockets */
70
static int	 opt_s;		/* Show protocol state if applicable */
68
static int	 opt_u;		/* Show Unix domain sockets */
71
static int	 opt_u;		/* Show Unix domain sockets */
69
static int	 opt_v;		/* Verbose mode */
72
static int	 opt_v;		/* Verbose mode */
70
73
Lines 91-96 Link Here
91
	int vflag;
94
	int vflag;
92
	int family;
95
	int family;
93
	int proto;
96
	int proto;
97
	int state;
94
	const char *protoname;
98
	const char *protoname;
95
	struct sockaddr_storage laddr;
99
	struct sockaddr_storage laddr;
96
	struct sockaddr_storage faddr;
100
	struct sockaddr_storage faddr;
Lines 260-268 Link Here
260
	const char *varname, *protoname;
264
	const char *varname, *protoname;
261
	size_t len, bufsize;
265
	size_t len, bufsize;
262
	void *buf;
266
	void *buf;
263
	int hash, retry, vflag;
267
	int hash, retry, state, vflag;
264
268
265
	vflag = 0;
269
	state = vflag = 0;
266
	if (opt_4)
270
	if (opt_4)
267
		vflag |= INP_IPV4;
271
		vflag |= INP_IPV4;
268
	if (opt_6)
272
	if (opt_6)
Lines 326-331 Link Here
326
			inp = &xtp->xt_inp;
330
			inp = &xtp->xt_inp;
327
			so = &xtp->xt_socket;
331
			so = &xtp->xt_socket;
328
			protoname = xtp->xt_tp.t_flags & TF_TOE ? "toe" : "tcp";
332
			protoname = xtp->xt_tp.t_flags & TF_TOE ? "toe" : "tcp";
333
			state = xtp->xt_tp.t_state;
329
			break;
334
			break;
330
		case IPPROTO_UDP:
335
		case IPPROTO_UDP:
331
		case IPPROTO_DIVERT:
336
		case IPPROTO_DIVERT:
Lines 384-389 Link Here
384
			    &inp->in6p_faddr, inp->inp_fport);
389
			    &inp->in6p_faddr, inp->inp_fport);
385
		}
390
		}
386
		sock->vflag = inp->inp_vflag;
391
		sock->vflag = inp->inp_vflag;
392
		if (proto == IPPROTO_TCP)
393
			sock->state = xtp->xt_tp.t_state;
387
		sock->protoname = protoname;
394
		sock->protoname = protoname;
388
		hash = (int)((uintptr_t)sock->socket % HASHSIZE);
395
		hash = (int)((uintptr_t)sock->socket % HASHSIZE);
389
		sock->next = sockhash[hash];
396
		sock->next = sockhash[hash];
Lines 648-654 Link Here
648
	default:
655
	default:
649
		abort();
656
		abort();
650
	}
657
	}
651
	xprintf("\n");
658
	if (opt_s && s->proto == IPPROTO_TCP) {
659
		while (pos < 80)
660
			pos += xprintf(" ");
661
		if (s->state >= 0 && s->state < TCP_NSTATES)
662
			pos += xprintf("%s", tcpstates[s->state]);
663
		else
664
			pos += xprintf("?");
665
	}
652
}
666
}
653
667
654
static void
668
static void
Lines 659-667 Link Here
659
	struct sock *s;
673
	struct sock *s;
660
	int hash, n, pos;
674
	int hash, n, pos;
661
675
662
	printf("%-8s %-10s %-5s %-2s %-6s %-21s %-21s\n",
676
	printf("%-8s %-10s %-5s %-2s %-6s %-21s %-21s",
663
	    "USER", "COMMAND", "PID", "FD", "PROTO",
677
	    "USER", "COMMAND", "PID", "FD", "PROTO",
664
	    "LOCAL ADDRESS", "FOREIGN ADDRESS");
678
	    "LOCAL ADDRESS", "FOREIGN ADDRESS");
679
	if (opt_s)
680
		printf(" %-12s", "STATE");
681
	printf("\n");
665
	setpassent(1);
682
	setpassent(1);
666
	for (xf = xfiles, n = 0; n < nxfiles; ++n, ++xf) {
683
	for (xf = xfiles, n = 0; n < nxfiles; ++n, ++xf) {
667
		if (xf->xf_data == NULL)
684
		if (xf->xf_data == NULL)
Lines 692-697 Link Here
692
			pos += xprintf(" ");
709
			pos += xprintf(" ");
693
		pos += xprintf("%d ", xf->xf_fd);
710
		pos += xprintf("%d ", xf->xf_fd);
694
		displaysock(s, pos);
711
		displaysock(s, pos);
712
		xprintf("\n");
695
	}
713
	}
696
	if (opt_j >= 0)
714
	if (opt_j >= 0)
697
		return;
715
		return;
Lines 705-710 Link Here
705
			pos += xprintf("%-8s %-10s %-5s %-2s ",
723
			pos += xprintf("%-8s %-10s %-5s %-2s ",
706
			    "?", "?", "?", "?");
724
			    "?", "?", "?", "?");
707
			displaysock(s, pos);
725
			displaysock(s, pos);
726
			xprintf("\n");
708
		}
727
		}
709
	}
728
	}
710
}
729
}
Lines 733-739 Link Here
733
usage(void)
752
usage(void)
734
{
753
{
735
	fprintf(stderr,
754
	fprintf(stderr,
736
	    "Usage: sockstat [-46cLlu] [-j jid] [-p ports] [-P protocols]\n");
755
	    "usage: sockstat [-46cLlsu] [-j jid] [-p ports] [-P protocols]\n");
737
	exit(1);
756
	exit(1);
738
}
757
}
739
758
Lines 744-750 Link Here
744
	int o, i;
763
	int o, i;
745
764
746
	opt_j = -1;
765
	opt_j = -1;
747
	while ((o = getopt(argc, argv, "46cj:Llp:P:uv")) != -1)
766
	while ((o = getopt(argc, argv, "46cj:Llp:P:suv")) != -1)
748
		switch (o) {
767
		switch (o) {
749
		case '4':
768
		case '4':
750
			opt_4 = 1;
769
			opt_4 = 1;
Lines 770-775 Link Here
770
		case 'P':
789
		case 'P':
771
			protos_defined = parse_protos(optarg);
790
			protos_defined = parse_protos(optarg);
772
			break;
791
			break;
792
		case 's':
793
			opt_s = 1;
794
			break;
773
		case 'u':
795
		case 'u':
774
			opt_u = 1;
796
			opt_u = 1;
775
			break;
797
			break;

Return to bug 201585