File: 1.01.4b/server/base/tests/udp.inc.php (View as HTML)

  1: <?php // udp.inc.php -- UDP test module
  2: /* -------------------------------------------------------------
  3: This file is part of FreeNATS
  4: 
  5: FreeNATS is (C) Copyright 2008 PurplePixie Systems
  6: 
  7: FreeNATS is free software: you can redistribute it and/or modify
  8: it under the terms of the GNU General Public License as published by
  9: the Free Software Foundation, either version 3 of the License, or
 10: (at your option) any later version.
 11: 
 12: FreeNATS is distributed in the hope that it will be useful,
 13: but WITHOUT ANY WARRANTY; without even the implied warranty of
 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15: GNU General Public License for more details.
 16: 
 17: You should have received a copy of the GNU General Public License
 18: along with FreeNATS.  If not, see www.gnu.org/licenses
 19: 
 20: For more information see www.purplepixie.org/freenats
 21: -------------------------------------------------------------- */
 22: 
 23: 
 24: if (isset($NATS))
 25: {
 26: class FreeNATS_UDP_Test extends FreeNATS_Local_Test
 27: 	{
 28: 		
 29: 	function DoTest($testname,$param,$hostname,$timeout,$params)
 30: 		{ 
 31: 		$timer=new TFNTimer();
 32: 		$ip=ip_lookup($hostname);
 33: 		if ($ip=="0") return -2; // lookup failed
 34: 		$connstr="udp://".$ip;
 35: 		$errno=0;
 36: 		$errstr="";
 37: 		$timer->Start();
 38: 		$fp=@fsockopen($connstr,$param,$errno,$errstr,$timeout);
 39: 		$elapsed=$timer->Stop();
 40: 		if ($fp===false) return -1; // open failed
 41: 		@fclose($fp);
 42: 		return $elapsed;
 43: 		}
 44: 		
 45: 	function Evaluate($result) 
 46: 		{
 47: 		if ($result<0) return 2; // failure
 48: 		return 0; // else success
 49: 		}
 50: 	
 51: 	function DisplayForm(&$row)
 52: 		{
 53: 		echo "<table border=0>";
 54: 		echo "<tr><td align=left>";
 55: 		echo "UDP Port :";
 56: 		echo "</td><td align=left>";
 57: 		echo "<input type=text name=testparam size=30 maxlength=128 value=\"".$row['testparam']."\">";
 58: 		echo "</td></tr>";
 59: 		echo "</table>";
 60: 		}
 61: 		
 62: 	}
 63: 	
 64: $params=array();
 65: $NATS->Tests->Register("udp","FreeNATS_UDP_Test",$params,"UDP Connect",1,"FreeNATS UDP Tester");
 66: $NATS->Tests->SetUnits("udp","Seconds","s");
 67: }
 68: 
 69: 
 70: ?>