[Opentnl-cvs] tnl/tnlping tnlping.cpp,NONE,1.1 tnlping.vcproj,NONE,1.1
Brought to you by:
mark_frohnmayer,
s_alanet
From: Mark F. <mar...@us...> - 2005-02-23 20:53:46
|
Update of /cvsroot/opentnl/tnl/tnlping In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11043/tnlping Added Files: tnlping.cpp tnlping.vcproj Log Message: Added tnlping utility to check whether a TNL program is up on a remote address --- NEW FILE: tnlping.cpp --- //----------------------------------------------------------------------------------- // // Torque Network Library - TNL Network program reachability tester // Copyright (C) 2004 GarageGames.com, Inc. // For more information see http://www.opentnl.org // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // For use in products that are not compatible with the terms of the GNU // General Public License, alternative licensing options are available // from GarageGames.com. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //------------------------------------------------------------------------------------ #include "tnl.h" #include "tnlNetInterface.h" #include "tnlLog.h" #include "tnlNonce.h" #include "tnlRandom.h" #include <stdio.h> using namespace TNL; int main(int argc, const char **argv) { if(argc < 2) { printf("Usage: tnlping <remoteAddress> [sourceAddress]"); return 1; } U8 randData[sizeof(U32) + sizeof(S64)]; *((U32 *) randData) = Platform::getRealMilliseconds(); *((S64 *) (randData + sizeof(U32))) = Platform::getHighPrecisionTimerValue(); TNL::Random::addEntropy(randData, sizeof(randData)); Address remoteAddress(argv[1]); Address sourceAddress(argc > 2 ? argv[2] : "IP:Any:0"); Nonce clientNonce; clientNonce.getRandom(); Socket sourceSocket(sourceAddress); PacketStream out; out.write(U8(NetInterface::ConnectChallengeRequest)); clientNonce.write(&out); out.writeFlag(false); out.writeFlag(false); for(U32 tryCount = 0; tryCount < 5; tryCount++) { U32 time = Platform::getRealMilliseconds(); out.sendto(sourceSocket, remoteAddress); for(;;) { PacketStream incoming; Address incomingAddress; if(incoming.recvfrom(sourceSocket, &incomingAddress) == NoError) { U8 packetType; Nonce theNonce; incoming.read(&packetType); theNonce.read(&incoming); if(packetType == NetInterface::ConnectChallengeResponse && theNonce == clientNonce) { printf("TNL Service is UP (pingtime = %d)", Platform::getRealMilliseconds() - time); return 0; } } Platform::sleep(1); if(Platform::getRealMilliseconds() - time > 1000) break; } } printf("TNL Service is DOWN."); return 1; } --- NEW FILE: tnlping.vcproj --- <?xml version="1.0" encoding="Windows-1252"?> <VisualStudioProject ProjectType="Visual C++" Version="7.10" Name="tnlping" ProjectGUID="{1CBEC210-5C02-43D4-AFA1-8A3EC67A3239}" Keyword="Win32Proj"> <Platforms> <Platform Name="Win32"/> </Platforms> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory="../exe" IntermediateDirectory="Debug" ConfigurationType="1" CharacterSet="2"> <Tool Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../tnl" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="4"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" AdditionalDependencies="wsock32.lib" OutputFile="$(OutDir)/tnlping.exe" LinkIncremental="2" GenerateDebugInformation="TRUE" ProgramDatabaseFile="$(OutDir)/tnlping.pdb" SubSystem="1" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCXMLDataGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> </Configuration> <Configuration Name="Release|Win32" OutputDirectory="../exe" IntermediateDirectory="Release" ConfigurationType="1" CharacterSet="2"> <Tool Name="VCCLCompilerTool" AdditionalIncludeDirectories="../tnl" PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" RuntimeLibrary="4" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="3"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" AdditionalDependencies="wsock32.lib" OutputFile="$(OutDir)/tnlping.exe" LinkIncremental="1" GenerateDebugInformation="TRUE" SubSystem="1" OptimizeReferences="2" EnableCOMDATFolding="2" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCXMLDataGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> </Configuration> </Configurations> <References> </References> <Files> <File RelativePath=".\tnlping.cpp"> </File> </Files> <Globals> </Globals> </VisualStudioProject> |