Back to the WFC main page

CPing : CSimpleSocket

$Revision: 27 $

Description

This class makes it easy for you to ping another TCP/IP host.

Data Members

None.

Methods

void ConvertErrorToString( DWORD error_code, CString& meaning ) const
If Ping() should fail, this will translate the error code into something humanly readable.
DWORD Ping( const CString& name_or_address, CPingResults * results_p, short desired_time_to_live )
Sends the ping request and received the results. Results are put into a CPingResults object. It returns the number of replies received.

Example

#include <wfc.h>
#pragma hdrstop

int _tmain( int number_of_command_line_arguments, TCHAR *command_line_arguments[] )
{
   WFCTRACEINIT( TEXT( "_tmain()" ) );

   CSimpleSocket::StartWindowsSockets();

   CPing ping;

   DWORD return_value = 0;

   CPingResults results;

   return_value = ping.Ping( TEXT( "20.2.1.3" ), &results );

   if ( return_value == 0 )
   {
      DWORD error_code = ping.GetErrorCode();

      CString error_message;

      ping.ConvertErrorToString( error_code, error_message );

      _tprintf( TEXT( "Ping Error: %s\n" ) ), (LPCTSTR) error_message );
   }
   else
   {
      _tprintf( TEXT( "Ping: %s Round Trip %lums TTL: %d\n" ), 
              (LPCTSTR) results.Address,
              results.RoundTripTimeInMilliseconds,
              (int) results.TimeToLive );
   }

   CSimpleSocket::StopWindowsSockets();

   return( EXIT_SUCCESS );
}

API's Used

CPing uses the following API's:
Copyright, 2000, Samuel R. Blackburn
$Workfile: cping.cpp $
$Modtime: 1/17/00 9:10a $