From owner-freebsd-hackers Sun Apr 18 12:10:59 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from cheddar.netmonger.net (cheddar.netmonger.net [209.54.21.140]) by hub.freebsd.org (Postfix) with ESMTP id 01E5614DEA for ; Sun, 18 Apr 1999 12:10:54 -0700 (PDT) (envelope-from chris@cheddar.netmonger.net) Received: (from chris@localhost) by cheddar.netmonger.net (8.8.8/8.8.8) id PAA11441; Sun, 18 Apr 1999 15:08:29 -0400 (EDT) Message-ID: <19990418150829.B7676@netmonger.net> Date: Sun, 18 Apr 1999 15:08:29 -0400 From: Christopher Masto To: hackers@freebsd.org Subject: Re: lsock(1) References: <15879.924101022@axl.noc.iafrica.com> <3714C4F0.579FDDEE@newsguy.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=cWoXeonUoKmBZSoM Content-Transfer-Encoding: 8bit X-Mailer: Mutt 0.91.1i In-Reply-To: <3714C4F0.579FDDEE@newsguy.com>; from Daniel C. Sobral on Thu, Apr 15, 1999 at 01:40:16AM +0900 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --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 () { 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 () { 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 <>>> @>>> @<< @<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<< $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