Use -finet option to netstat(1), and don't discard anything.

Don't truncate the protocol field.
These two changes conspire to make sockstat(1) show divert sockets.

Submitted by:	ru
This commit is contained in:
Dag-Erling Smørgrav 1999-07-06 19:12:31 +00:00
parent 8898c75d55
commit 14802b6092
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=48644
2 changed files with 10 additions and 11 deletions

View File

@ -25,7 +25,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $Id: lsock.1,v 1.1 1999/04/14 16:17:34 des Exp $
.\" $Id: sockstat.1,v 1.1 1999/04/15 13:40:43 des Exp $
.\"
.Dd April 13, 1999
.Dt LSOCK 1
@ -39,7 +39,7 @@ The
.Nm
command lists open Internet sockets. The information listed for each
socket is:
.Bl -tag -width FOREIGN_ADDRESS
.Bl -tag -width "FOREIGN ADDRESS"
.It Li USER
The user who owns the socket.
.It Li COMMAND
@ -49,7 +49,7 @@ The process ID of the command which holds the socket.
.It Li FD
The file descriptor number of the socket.
.It Li PROTO
The transport protocol (udp or tcp) associated with the socket.
The transport protocol associated with the socket.
.It Li LOCAL ADDRESS
The address the local end of the socket is bound to (see
.Xr getsockname 2 ).
@ -59,8 +59,8 @@ The address the foreign end of the socket is bound to (see
.El
.Sh SEE ALSO
.Xr fstat 1 ,
.Xr inet 4 ,
.Xr netstat 1 .
.Xr netstat 1 ,
.Xr inet 4 .
.Sh HISTORY
The
.Nm

View File

@ -26,25 +26,24 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $Id: sockstat.pl,v 1.1 1999/04/15 13:40:43 des Exp $
# $Id: sockstat.pl,v 1.2 1999/05/01 11:31:19 des Exp $
#
my (%myaddr, %hisaddr);
my ($user, $cmd, $pid, $fd, $inet, $type, $proto, $sock, $laddr, $faddr);
print <<EOH;
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
EOH
format STDOUT =
@<<<<<<< @<<<<<<<<< @>>>> @>>> @<< @<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<
$user, $cmd, $pid, $fd, $proto,$laddr, $faddr
@<<<<<<< @<<<<<<< @>>>> @>>> @<<<<< @<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<
$user, $cmd, $pid, $fd, $proto,$laddr, $faddr
.
open NETSTAT, "netstat -Aan |" or die "'netstat -Aan' failed: $!";
open NETSTAT, "netstat -Aan -finet | tail +3 |" or die "'netstat' failed: $!";
while (<NETSTAT>) {
my ($sock, $proto, $recvq, $sendq, $laddr, $faddr, $state) = split;
next unless ($proto =~ m/tcp|udp/);
($myaddr{$sock}, $hisaddr{$sock}) = ($laddr, $faddr);
}