# (2) Converted checks to new plugin mechanism (Stephen Johnson May 28, 1999)
# Added user-configurable escalation mechanism
#
-# $Id: spong-network.pl,v 1.39 2001/06/20 17:10:22 supermathie Exp $
+# $Id: spong-network.pl,v 1.40 2001/06/20 21:18:54 sljohnson Exp $
use Carp;
use lib "@@LIBDIR@@";
# ---------------------------------------------------------------------------
-# &check_tcp( HOST, PORT, DATA, TIMEOUT )
+# &check_tcp( HOST, PORT, DATA, TIMEOUT, MAXLEN )
#
# This function will make a connection to a port at a given port, and send a
# message, it will then return what it gets back to the caller of this
# ---------------------------------------------------------------------------
sub check_tcp {
- my( $addr, $port, $data, $timeout ) = @_;
+ my( $addr, $port, $data, $timeout, $maxlen ) = @_;
my( $iaddr, $paddr, $proto, $line, $ip, $sock, $err );
if( $addr =~ /^\s*((\d+\.){3}\d+)\s*$/ ) {
$ip = "$a.$b.$c.$d";
}
- $timeout = 5 if ( ! defined $timeout || $timeout <= 0);
+ $timeout = 5 if ( ! defined $timeout || $timeout <= 0);
+ $maxlen = 256 if ( ! defined $maxlen || $maxlen <= 0);
$err = 0;
$line = "";
+ $msg = "";
$iaddr = inet_aton( $ip ) || return -1;
$paddr = sockaddr_in( $port, $iaddr );
connect( SOCK, $paddr ) || die "connect: $!";
select((select(SOCK), $| = 1)[0]);
print SOCK "$data";
- recv( SOCK, $line, 256, 0 ); # just grab a chunk from the service.
+ while (length($msg) < $maxlen) {
+ recv( SOCK, $line, 256, 0 );
+ $msg .= $line;
+ if (length($line) == 0) { return; } # If the socket is closed, return
+ }
alarm(0);
close( SOCK ) || die "close: $!";
};
if ( $@ =~ /timed out/ ) { $err = "check_tcp timed out"; }
if ( $@ =~ /connect:(.*) at/ ) { $err = $1; }
- return ($err,$line);
+ return ($err,$msg);
}