xref: /freebsd/usr.bin/sockstat/sockstat.1 (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1.\"-
2.\" Copyright (c) 1999 Dag-Erling Coïdan Smørgrav
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer
10.\"    in this position and unchanged.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. The name of the author may not be used to endorse or promote products
15.\"    derived from this software without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27.\"
28.\" $FreeBSD$
29.\"
30.Dd June 6, 2022
31.Dt SOCKSTAT 1
32.Os
33.Sh NAME
34.Nm sockstat
35.Nd list open sockets
36.Sh SYNOPSIS
37.Nm
38.Op Fl 46CciLlnqSsUuvw
39.Op Fl j Ar jail
40.Op Fl p Ar ports
41.Op Fl P Ar protocols
42.Sh DESCRIPTION
43The
44.Nm
45command lists open Internet or
46.Ux
47domain sockets.
48.Pp
49The following options are available:
50.Bl -tag -width Fl
51.It Fl 4
52Show
53.Dv AF_INET
54(IPv4) sockets.
55.It Fl 6
56Show
57.Dv AF_INET6
58(IPv6) sockets.
59.It Fl C
60Display the congestion control module, if applicable.
61This is currently only implemented for TCP.
62.It Fl c
63Show connected sockets.
64.It Fl i
65Display the
66.Dv inp_gencnt .
67.It Fl j Ar jail
68Show only sockets belonging to the specified jail ID or name.
69.It Fl L
70Only show Internet sockets if the local and foreign addresses are not
71in the loopback network prefix
72.Li 127.0.0.0/8 ,
73or do not contain the IPv6 loopback address
74.Li ::1 .
75.It Fl l
76Show listening sockets.
77.It Fl n
78Do not resolve numeric UIDs to user names.
79.It Fl p Ar ports
80Only show Internet sockets if the local or foreign port number
81is on the specified list.
82The
83.Ar ports
84argument is a comma-separated list of port numbers and ranges
85specified as first and last port separated by a dash.
86.It Fl P Ar protocols
87Only show sockets of the specified
88.Ar protocols .
89The
90.Ar protocols
91argument is a comma-separated list of protocol names,
92as they are defined in
93.Xr protocols 5 .
94.It Fl q
95Quiet mode, do not print the header line.
96.It Fl S
97Display the protocol stack, if applicable.
98This is currently only implemented for TCP.
99.It Fl s
100Display the protocol state, if applicable.
101This is currently only implemented for SCTP and TCP.
102.It Fl U
103Display the remote UDP encapsulation port number, if applicable.
104This is currently only implemented for SCTP and TCP.
105.It Fl u
106Show
107.Dv AF_LOCAL
108.Pq Ux
109sockets.
110.It Fl v
111Verbose mode.
112.It Fl w
113Use wider field size for displaying addresses.
114.El
115.Pp
116If neither
117.Fl 4 , 6
118or
119.Fl u
120is specified,
121.Nm
122will list sockets in all three domains.
123.Pp
124If neither
125.Fl c
126or
127.Fl l
128is specified,
129.Nm
130will list both listening and connected sockets.
131.Pp
132The information listed for each
133socket is:
134.Bl -tag -width "FOREIGN ADDRESS"
135.It Li USER
136The user who owns the socket.
137.It Li COMMAND
138The command which holds the socket.
139.It Li PID
140The process ID of the command which holds the socket.
141.It Li FD
142The file descriptor number of the socket.
143.It Li PROTO
144The transport protocol associated with the socket for Internet
145sockets, or the type of socket
146.Pq stream, datagram, or seqpacket
147for
148.Ux
149sockets.
150.It Li LOCAL ADDRESS
151For Internet sockets, this is the address the local end of the socket
152is bound to (see
153.Xr getsockname 2 ) .
154.Pp
155For bound
156.Ux
157sockets, socket's filename is printed.
158For not bound
159.Ux
160sockets, the field is empty.
161.It Li FOREIGN ADDRESS
162For Internet sockets, this is the address the foreign end of the socket
163is bound to (see
164.Xr getpeername 2 ) .
165.Pp
166For bound
167.Ux
168sockets a left arrow followed by the peer list is printed.
169For
170.Ux
171sockets that went through
172.Xr connect 2
173system call a right arrow followed by the peer is printed.
174Peers are printed in square brackets as [PID FD].
175.It Li ID
176The inp_gencnt if
177.Fl i
178is specified (only for TCP or UDP).
179.It Li ENCAPS
180The remote UDP encapsulation port number if
181.Fl U
182is specified (only for SCTP or TCP).
183.It Li PATH STATE
184The path state if
185.Fl s
186is specified (only for SCTP).
187.It Li CONN STATE
188The connection state if
189.Fl s
190is specified (only for SCTP or TCP).
191.It Li STACK
192The protocol stack if
193.Fl S
194is specified (only for TCP).
195.It Li CC
196The congestion control if
197.Fl C
198is specified (only for TCP).
199.El
200.Pp
201If a socket is associated with more than one file descriptor,
202it is shown multiple times.
203If a socket is not associated with any file descriptor,
204the first four columns have no meaning.
205.Sh EXAMPLES
206Show information for IPv4 sockets listening on port 22 using protocol
207TCP:
208.Bd -literal -offset indent
209$ sockstat -4 -l -P tcp -p 22
210.Ed
211.Pp
212Show information for sockets using either TCP or UDP, if neither, the local nor
213the foreign addresses are in the loopback network:
214.Bd -literal -offset indent
215$ sockstat -L -P tcp,udp
216.Ed
217.Pp
218Show TCP IPv6 sockets which are listening and connected (default):
219.Bd -literal -offset indent
220$ sockstat -6 -P tcp
221.Ed
222.Sh SEE ALSO
223.Xr fstat 1 ,
224.Xr netstat 1 ,
225.Xr procstat 1 ,
226.Xr inet 4 ,
227.Xr inet6 4 ,
228.Xr protocols 5
229.Sh HISTORY
230The
231.Nm
232command appeared in
233.Fx 3.1 .
234.Sh AUTHORS
235The
236.Nm
237command and this manual page were written by
238.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
239