File: 1.02.4b/server/base/tests/udp.inc.php (View as Code)

1: 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: global $NATS; 32: if ($timeout<=0) $timeout=$NATS->Cfg->Get("test.udp.timeout",0); // if no test-specific param use sys default 33: if ($timeout<=0) $timeout=60; // if sys default is <=0 then default to 60 seconds 34: $timer=new TFNTimer(); 35: $ip=ip_lookup($hostname); 36: if ($ip=="0") return -2; // lookup failed 37: $connstr="udp://".$ip; 38: $errno=0; 39: $errstr=""; 40: $timer->Start(); 41: $fp=@fsockopen($connstr,$param,$errno,$errstr,$timeout); 42: $elapsed=$timer->Stop(); 43: if ($fp===false) return -1; // open failed 44: @fclose($fp); 45: return $elapsed; 46: } 47: 48: function Evaluate($result) 49: { 50: if ($result<0) return 2; // failure 51: return 0; // else success 52: } 53: 54: function DisplayForm(&$row) 55: { 56: echo ""; 57: echo ""; 62: echo "
"; 58: echo "UDP Port :"; 59: echo ""; 60: echo ""; 61: echo "
";
63: } 64: 65: } 66: 67: $params=array(); 68: $NATS->Tests->Register("udp","FreeNATS_UDP_Test",$params,"UDP Connect",1,"FreeNATS UDP Tester"); 69: $NATS->Tests->SetUnits("udp","Seconds","s"); 70: } 71: 72: 73: ?>