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