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