From 8bd7e3d58930cb62ee31419dc1a2e67df89045cd Mon Sep 17 00:00:00 2001
From: slerena <slerena@gmail.com>
Date: Thu, 7 Jun 2007 17:24:02 +0000
Subject: [PATCH] 2007-06-07  Sancho Lerena  <slerena@artica.es>

        * bin/pandora_network.pl: Net::Ping::External does not solve our
        odd problems. Fallback again to Net::Ping interface, not using a
        double check to be sure that data is good. I hope this works :(



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@493 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_server/ChangeLog              |  5 ++-
 pandora_server/bin/pandora_network.pl | 50 ++++++++++++++++-----------
 2 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog
index fe53fdf541..3348df59d2 100644
--- a/pandora_server/ChangeLog
+++ b/pandora_server/ChangeLog
@@ -21,7 +21,10 @@
 	* bin/PandoraFMS: Now contains all .PM files for PandoraFMS.
 
 	* bin/pandora_recon.pl: Now uses ping() from PingExternal.
-	
+
+	* bin/pandora_network.pl: Net::Ping::External does not solve our 
+	odd problems. Fallback again to Net::Ping interface, not using a 
+	double check to be sure that data is good. I hope this works :(
 
 2007-06-05  Sancho Lerena <slerena@gmail.com>
 
diff --git a/pandora_server/bin/pandora_network.pl b/pandora_server/bin/pandora_network.pl
index 56fe62d9f0..82bdd892a9 100755
--- a/pandora_server/bin/pandora_network.pl
+++ b/pandora_server/bin/pandora_network.pl
@@ -32,7 +32,6 @@ use threads;
 use PandoraFMS::Config;
 use PandoraFMS::Tools;
 use PandoraFMS::DB;
-use PandoraFMS::PingExternal;  # Use Net:Ping:External (renamed to pandora_ping_external)
 
 # FLUSH in each IO (only for debug, very slooow)
 # ENABLED in DEBUGMODE
@@ -326,26 +325,35 @@ sub pandora_network_subsystem {
 sub pandora_ping_icmp {
 	my $dest = $_[0];
 	my $l_timeout = $_[1];
-	# temporal vars.
-	my $result = 0;
+ 	# temporal vars.
+ 	my $result = 0;
+	my $result2 = 0;
+ 	my $p;
+ 
+ 	# Check for valid destination
+ 	if (!defined($dest)) {
+ 		return 0;
+ 	}
+ 	# Some hosts don't accept ICMP with too small payload. Use 16 Bytes
+ 	$p = Net::Ping->new("icmp",$l_timeout,16);
+	$p->source_verify(1);
 
-	# Check for valid destination
-	if (!defined($dest)) {
-		return 0;
-	}
-    $result = ping(hostname => $dest, timeout => $l_timeout, size => 32, count => 1);
-	
-	# Check for valid result
-	if (!defined($result)) {
-		return 0;
-	}
-
-	# Lets see the result
-	if ($result == 1) {
-		return 1;
-	} else {
-		return 0;
-	}
+ 	$result = $p->ping($dest);
+	$result2 = $p->ping($dest);
+ 
+ 	# Check for valid result
+ 	if ((!defined($result)) || (!defined($result2))) {
+ 		return 0;
+ 	}
+ 
+ 	# Lets see the result
+ 	if (($result == 1) && ($result2 == 1)) {
+ 		$p->close();
+ 		return 1;
+ 	} else {
+ 		$p->close();
+ 		return 0;
+ 	}
 }
 
 ##########################################################################
@@ -548,7 +556,7 @@ sub exec_network_module {
 			$nm->close();
 		} else {
 			$module_result = 0; # Done but, with zero value
-			$module_data = 0;
+			$module_data = 0; # This should don't happen
 		}
 	# SNMP Modules (Proc=18, inc, data, string)
 	# ------------