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