xref: /freebsd/usr.bin/sockstat/sockstat.1 (revision 24e4dcf4ba5e9dedcf89efd358ea3e1fe5867020)
1.\"-
2.\" Copyright (c) 1999 Dag-Erling 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.Dd July 17, 2025
29.Dt SOCKSTAT 1
30.Os
31.Sh NAME
32.Nm sockstat
33.Nd list open sockets
34.Sh SYNOPSIS
35.Nm
36.Op Fl -libxo
37.Op Fl 46ACcfIiLlnqSsUuvw
38.Op Fl j Ar jail
39.Op Fl p Ar ports
40.Op Fl P Ar protocols
41.Sh DESCRIPTION
42The
43.Nm
44command lists open Internet or
45.Ux
46domain sockets.
47.Pp
48The following options are available:
49.Bl -tag -width Fl
50.It Fl -libxo
51Generate output via
52.Xr libxo 3
53in a selection of different human and machine readable formats.
54See
55.Xr xo_options 7
56for details on command line arguments.
57.It Fl 4
58Show
59.Dv AF_INET
60(IPv4) sockets.
61.It Fl 6
62Show
63.Dv AF_INET6
64(IPv6) sockets.
65.It Fl A
66Show the address of a protocol control block (PCB) associated with a socket;
67used for debugging.
68.It Fl C
69Display the congestion control module, if applicable.
70This is currently only implemented for TCP.
71.It Fl c
72Show connected sockets.
73.It Fl f
74Show the FIB number of each socket.
75.It Fl I
76Show the local address of the socket to which the current socket is spliced, if
77any.
78See the
79.Xr setsockopt 2
80.Dv SO_SPLICE
81option for more information.
82.It Fl i
83Display the
84.Dv inp_gencnt .
85.It Fl j Ar jail
86Show only sockets belonging to the specified jail ID or name.
87.It Fl L
88Only show Internet sockets if the local and foreign addresses are not
89in the loopback network prefix
90.Li 127.0.0.0/8 ,
91or do not contain the IPv6 loopback address
92.Li ::1 .
93.It Fl l
94Show listening sockets.
95.It Fl n
96Do not resolve numeric UIDs to user names.
97.It Fl p Ar ports
98Only show Internet sockets if the local or foreign port number
99is on the specified list.
100The
101.Ar ports
102argument is a comma-separated list of port numbers and ranges
103specified as first and last port separated by a dash.
104.It Fl P Ar protocols
105Only show sockets of the specified
106.Ar protocols .
107The
108.Ar protocols
109argument is a comma-separated list of protocol names,
110as they are defined in
111.Xr protocols 5 .
112.It Fl q
113Quiet mode, do not print the header line.
114.It Fl S
115Display the protocol stack, if applicable.
116This is currently only implemented for TCP.
117.It Fl s
118Display the protocol state, if applicable.
119This is currently only implemented for SCTP and TCP.
120.It Fl U
121Display the remote UDP encapsulation port number, if applicable.
122This is currently only implemented for SCTP and TCP.
123.It Fl u
124Show
125.Dv AF_LOCAL
126.Pq Ux
127sockets.
128.It Fl v
129Verbose mode.
130.It Fl w
131Automatically size the columns.
132.El
133.Pp
134If neither
135.Fl 4 , 6
136or
137.Fl u
138is specified,
139.Nm
140will list sockets in all three domains.
141.Pp
142If neither
143.Fl c
144or
145.Fl l
146is specified,
147.Nm
148will list both listening and connected sockets.
149.Pp
150The information listed for each
151socket is:
152.Bl -tag -width "FOREIGN ADDRESS"
153.It Li USER
154The user who owns the socket.
155.It Li COMMAND
156The command which holds the socket.
157.It Li PID
158The process ID of the command which holds the socket.
159.It Li FD
160The file descriptor number of the socket.
161.It Li PROTO
162The transport protocol associated with the socket for Internet
163sockets, or the type of socket
164.Pq stream, datagram, or seqpacket
165for
166.Ux
167sockets.
168.It Li LOCAL ADDRESS
169For Internet sockets, this is the address the local end of the socket
170is bound to (see
171.Xr getsockname 2 ) .
172.Pp
173For bound
174.Ux
175sockets, socket's filename is printed.
176For not bound
177.Ux
178sockets, the field is empty.
179.It Li FOREIGN ADDRESS
180For Internet sockets, this is the address the foreign end of the socket
181is bound to (see
182.Xr getpeername 2 ) .
183.Pp
184For bound
185.Ux
186sockets a left arrow followed by the peer list is printed.
187For
188.Ux
189sockets that went through
190.Xr connect 2
191system call a right arrow followed by the peer is printed.
192Peers are printed in square brackets as [PID FD].
193.It Li ID
194The inp_gencnt if
195.Fl i
196is specified (only for TCP or UDP).
197.It Li ENCAPS
198The remote UDP encapsulation port number if
199.Fl U
200is specified (only for SCTP or TCP).
201.It Li PATH STATE
202The path state if
203.Fl s
204is specified (only for SCTP).
205.It Li CONN STATE
206The connection state if
207.Fl s
208is specified (only for SCTP or TCP).
209.It Li STACK
210The protocol stack if
211.Fl S
212is specified (only for TCP).
213.It Li CC
214The congestion control if
215.Fl C
216is specified (only for TCP).
217.El
218.Pp
219If a socket is associated with more than one file descriptor,
220it is shown multiple times.
221If a socket is not associated with any file descriptor,
222the first four columns have no meaning.
223.Sh EXAMPLES
224Show information for IPv4 sockets listening on port 22 using protocol
225TCP:
226.Bd -literal -offset indent
227$ sockstat -4 -l -P tcp -p 22
228.Ed
229.Pp
230Show information for sockets using either TCP or UDP, if neither, the local nor
231the foreign addresses are in the loopback network:
232.Bd -literal -offset indent
233$ sockstat -L -P tcp,udp
234.Ed
235.Pp
236Show TCP IPv6 sockets which are listening and connected (default):
237.Bd -literal -offset indent
238$ sockstat -6 -P tcp
239.Ed
240.Pp
241Show all sockets in JSON format with neat alignment:
242.Bd -literal -offset indent
243$ sockstat --libxo json,pretty
244.Ed
245.Sh SEE ALSO
246.Xr fstat 1 ,
247.Xr netstat 1 ,
248.Xr procstat 1 ,
249.Xr setfib 1 ,
250.Xr inet 4 ,
251.Xr inet6 4 ,
252.Xr protocols 5
253.Xr libxo 3 ,
254.Xr xo_options 7
255.Sh HISTORY
256The
257.Nm
258command appeared in
259.Fx 3.1 .
260.Sh AUTHORS
261The
262.Nm
263command and this manual page were written by
264.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
265