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