File: 1.01.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: $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 ""; 54: echo ""; 59: echo "
"; 55: echo "UDP Port :"; 56: echo ""; 57: echo ""; 58: echo "
";
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: ?>