From 3651c7dbc9551d6fba1f454343393889d013c553 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Wed, 20 Jun 2001 21:18:54 +0000 Subject: [PATCH] added patch to check_tcp() to allow amount of data read to be specified --- src/spong-network.pl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/spong-network.pl b/src/spong-network.pl index e93d595..5993db0 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -17,7 +17,7 @@ # (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@@"; @@ -330,7 +330,7 @@ sub check_simple { # --------------------------------------------------------------------------- -# &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 @@ -338,7 +338,7 @@ sub check_simple { # --------------------------------------------------------------------------- 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*$/ ) { @@ -350,10 +350,12 @@ sub check_tcp { $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 ); @@ -370,7 +372,11 @@ sub check_tcp { 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: $!"; }; @@ -379,7 +385,7 @@ sub check_tcp { if ( $@ =~ /timed out/ ) { $err = "check_tcp timed out"; } if ( $@ =~ /connect:(.*) at/ ) { $err = $1; } - return ($err,$line); + return ($err,$msg); } -- 2.30.2