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