Date: Sun, 18 Apr 1999 15:08:29 -0400 From: Christopher Masto <chris@netmonger.net> To: hackers@freebsd.org Subject: Re: lsock(1) Message-ID: <19990418150829.B7676@netmonger.net> In-Reply-To: <3714C4F0.579FDDEE@newsguy.com>; from Daniel C. Sobral on Thu, Apr 15, 1999 at 01:40:16AM %2B0900 References: <15879.924101022@axl.noc.iafrica.com> <3714C4F0.579FDDEE@newsguy.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--cWoXeonUoKmBZSoM Content-Type: text/plain; charset=us-ascii On Thu, Apr 15, 1999 at 01:40:16AM +0900, Daniel C. Sobral wrote: > Sheldon Hearn wrote: > > > > I didn't look at the code, but the functionality described in the > > manpage looks cool and froody. > > I did. The code is smaller than the man page, actually. :-) It's > just a matter of calling netstat and fstat, and correlating the > results. It's a heck of a lot cleaner than the piece of crap I threw together at my old job. My only excuse is that this file was dated 1996, and I'm three years smarter now: #!/usr/local/bin/perl #First learn all PCBs open FS, "fstat|"; while (<FS>) { chop; ($uname, $net, $pcb) = (split)[0,4,7]; if ($net eq "internet" and $pcb) { $name{$pcb} = $uname; } } close FS; #fancy netstat open NS, "netstat -nAa -f inet|"; while (<NS>) { if (/^(........)\s+(\S+)\s+(\S+)\s+(\S+)\s+([\d\.\*]+)\.(\d+)\s+(\S+)\s*(\S*)$/) { if ($name{$1} and ($2 eq "tcp" or $2 eq "udp")) { printf "%-8s %-15s %-7s %-15s %s\n", $name{$1}, $5, "($6)", $8, $7; } } } close NS; I do have a minor suggestion though. To be consistent with other utilities that have headers (such as ps), it should probably not use the _TOP format, which adds a formfeed and a repeated header periodically. It's a simple change (attached). -- Christopher Masto Senior Network Monkey NetMonger Communications chris@netmonger.net info@netmonger.net http://www.netmonger.net Free yourself, free your machine, free the daemon -- http://www.freebsd.org/ --cWoXeonUoKmBZSoM Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename=lsock-diff --- lsock.pl Tue Apr 13 17:41:09 1999 +++ lsock-notop.pl Sun Apr 18 15:03:34 1999 @@ -1,4 +1,4 @@ -#!/usr/bin/perl5 +#!/usr/bin/perl #- # Copyright (c) 1999 Dag-Erling Coïdan Smørgrav # All rights reserved. @@ -32,9 +32,9 @@ my %myaddr, %hisaddr; my $user, $cmd, $pid, $fd, $inet, $type, $proto, $sock, $laddr, $faddr; -format STDOUT_TOP = +print <<EOH; USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS -. +EOH format STDOUT = @<<<<<<< @<<<<<<<<< @>>>> @>>> @<< @<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<< $user, $cmd, $pid, $fd, $proto,$laddr, $faddr --cWoXeonUoKmBZSoM-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990418150829.B7676>