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