#
# Kapil Chowksey <kchowksey@hss.hns.com>
###################################################################
-
+use strict;
use Socket;
-require 'getopts.pl';
+use Getopt::Long;
# Set path to lsof.
-if (($LSOF = &isexec("../lsof")) eq "") { # Try .. first
+my $LSOF;
+if (($LSOF = &isexec("/usr/bin/lsof")) eq "") { # Try .. first
if (($LSOF = &isexec("lsof")) eq "") { # Then try . and $PATH
print "can't execute $LSOF\n"; exit 1
}
close(STDERR);
open(STDERR, ">/dev/null");
-$Timeout = "120";
+my $Timeout = "120";
-&Getopts('t:');
-if ($opt_t) {
- $Timeout = $opt_t;
-}
+GetOptions('timeout=i'=>\$Timeout);
-($port, $iaddr) = sockaddr_in(getpeername(STDIN));
-$peer_addr = inet_ntoa($iaddr);
+my ($port, $iaddr) = sockaddr_in(getpeername(STDIN));
+my $peer_addr = inet_ntoa($iaddr);
+my $query;
# read ident-query from socket (STDIN) with a timeout.
-$timeout = int($Timeout);
+my $timeout = int($Timeout);
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $timeout;
# remove all white-spaces from query
$query =~ s/\s//g;
-$serv_port = "";
-$cli_port = "";
+my $serv_port = "";
+my $cli_port = "";
($serv_port,$cli_port) = split(/,/,$query);
if ($serv_port =~ /^[0-9]+$/) {
open(LSOFP,"$LSOF -nPDi -T -FLn -iTCP@".$peer_addr.":".$cli_port."|");
-$user = "UNKNOWN";
-while ($a_line = <LSOFP>) {
+my $user = "UNKNOWN";
+while (my $a_line = <LSOFP>) {
# extract user name.
if ($a_line =~ /^L.*/) {
($user) = ($a_line =~ /^L(.*)/);