xref: /freebsd/usr.bin/sockstat/sockstat.1 (revision aa0a1e58)
1.\"-
2.\" Copyright (c) 1999 Dag-Erling Co�dan 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.\" $FreeBSD$
29.\"
30.Dd July 9, 2009
31.Dt SOCKSTAT 1
32.Os
33.Sh NAME
34.Nm sockstat
35.Nd list open sockets
36.Sh SYNOPSIS
37.Nm
38.Op Fl 46cLlu
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 4
51Show
52.Dv AF_INET
53(IPv4) sockets.
54.It Fl 6
55Show
56.Dv AF_INET6
57(IPv6) sockets.
58.It Fl c
59Show connected sockets.
60.It Fl L
61Only show Internet sockets if the local or foreign addresses are not
62in the loopback network prefix
63.Li 127.0.0.0/8 ,
64or do not contain the IPv6 loopback address
65.Li ::1 .
66.It Fl l
67Show listening sockets.
68.It Fl p Ar ports
69Only show Internet sockets if either the local or foreign port number
70is on the specified list.
71The
72.Ar ports
73argument is a comma-separated list of port numbers and ranges
74specified as first and last port separated by a dash.
75.It Fl P Ar protocols
76Only show sockets of the specified
77.Ar protocols .
78The
79.Ar protocols
80argument is a comma-separated list of protocol names,
81as they are defined in
82.Xr protocols 5 .
83.It Fl u
84Show
85.Dv AF_LOCAL
86.Pq Ux
87sockets.
88.El
89.Pp
90If neither
91.Fl 4 , 6
92or
93.Fl u
94is specified,
95.Nm
96will list sockets in all three domains.
97.Pp
98If neither
99.Fl c
100or
101.Fl l
102is specified,
103.Nm
104will list both listening and connected sockets.
105.Pp
106The information listed for each
107socket is:
108.Bl -tag -width "FOREIGN ADDRESS"
109.It Li USER
110The user who owns the socket.
111.It Li COMMAND
112The command which holds the socket.
113.It Li PID
114The process ID of the command which holds the socket.
115.It Li FD
116The file descriptor number of the socket.
117.It Li PROTO
118The transport protocol associated with the socket for Internet
119sockets, or the type of socket (stream or datagram) for
120.Ux
121sockets.
122.It Li LOCAL ADDRESS
123For Internet sockets, this is the address the local end of the socket
124is bound to (see
125.Xr getsockname 2 ) .
126For bound
127.Ux
128sockets, it is the socket's filename.
129For other
130.Ux
131sockets, it is a right arrow followed by the endpoint's filename, or
132.Dq Li ??
133if the endpoint could not be determined.
134.It Li FOREIGN ADDRESS
135(Internet sockets only)
136The address the foreign end of the socket is bound to (see
137.Xr getpeername 2 ) .
138.El
139.Pp
140Note that TCP sockets in the
141.Dv AF_INET
142or
143.Dv AF_INET6
144domains that are not in one of the
145.Dv LISTEN , SYN_SENT ,
146or
147.Dv ESTABLISHED
148states may not be shown by
149.Nm ;
150use
151.Xr netstat 1
152to examine them instead.
153.Sh SEE ALSO
154.Xr fstat 1 ,
155.Xr netstat 1 ,
156.Xr procstat 1 ,
157.Xr inet 4 ,
158.Xr inet6 4 ,
159.Xr protocols 5
160.Sh HISTORY
161The
162.Nm
163command appeared in
164.Fx 3.1 .
165.Sh AUTHORS
166The
167.Nm
168command and this manual page were written by
169.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
170.Sh BUGS
171Unlike
172.Xr netstat 1 ,
173.Nm
174lists sockets by walking file descriptor tables and will not output
175the ones owned by the kernel, e.g. NLM sockets created by
176.Xr rpc.lockd 8 .
177