Download source files - 13 Kb
Welcome to CTraceRoute
, a freeware MFC class to implement trace route functionality.
- Simple and clean C++ interface.
- The interface provided is synchronous which provides an easier programming model than using
asynchronous sockets.
- virtual functions are provided to support callback.
- A configurable timeout can be set through the class API.
- The classes are fully Unicode compliant and include Unicode built options in the workspace file.
- To use the class in your code simply include tracer.cpp in your project and
#include tracer.h
in which ever of your modules needs to make calls to the class.
- Your code will need to include MFC either statically or dynamically.
- You will need to have a functioning winsock stack installed as the code links to wsock32.dll.
- The code will work just aswell in a GUI or console app. The code should also work in a multithreaded
application, although it has not be explicitly tested in this scenario.
V1.0 (18th November 1998)
The API consists of the the 2 classes:
CTraceRouteReply
CTraceRoute
This is an encapsulation of all the information as returned from a trace route request. It is a typedef for
the following:
typedef CArray<CHostTraceMultiReply, CHostTraceMultiReply&> CTraceRouteReply
The members of CHostTraceMultiReply are as follows:
DWORD dwError | This is the error if any which occurred when doing a ping to this host. This corresponds
to the values as returned from GetLastError. 0 represents no error occurred. |
in_addr Address | The IP address of the host for this part of the trace route. |
DWORD minRTT | Minimum round trip time in milliseconds for this host. |
DWORD avgRTT | Average round trip time in milliseconds for this host. |
DWORD maxRTT | Maximum round trip time in milliseconds for this host. |
Trace
OnPingResult
OnSingleHostResult
- CTraceRoute::Trace
- BOOL CTraceRoute::Trace(LPCTSTR pszHostName, CTraceRouteReply& trr, UCHAR nHopCount = 30, DWORD dwTimeout = 30000, DWORD dwPingsPerHost = 3) const;
Return Value:
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE.
To get extended error information, call ::GetLastError()
.
Parameters:
- pszHostName -- The network address of the socket to connect to: a machine name such as
"ftp.yourisp.com", or a dotted number such as "128.56.22.8" will both work.
- trr -- Upon successful return, this will contain all the information related to the trace route
request. See
CTraceRouteReply
for further details.
- nHopCount -- This is the maximum TTL to use. This corresponds to the farthest router which the
ping request will reach.
- dwTimeout -- The timeout for each ping in milliseconds.
- dwPingsPerHost -- The number of pings to perform per host.
Remarks:
This function implements the trace route functionality.
- CTraceRoute::OnPingResult
- virtual BOOL CTraceRoute::OnPingResult(int nPingNum, const CHostTraceSingleReply& htsr);
Return Value:
TRUE to continue the trace route. Returning FALSE will cancel the operation.
Parameters:
- nPingNum -- The ping reply which this function is being called for.
- htsr -- Contains the actual results from the ping for this host.
Remarks:
This function is called just after each ping reply. You can derive your own class from CTraceRoute and
override this function so that your version is called at the appropriate times.
- CTraceRoute::OnSingleHostResult
- virtual BOOL CTraceRoute::OnSingleHostResult(int nHostNum, const CHostTraceMultiReply& htmr);
Return Value:
TRUE to continue the trace route. Returning FALSE will cancel the operation.
Parameters:
- nHostNum -- The current host which this function is being called for.
- htmr -- Contains the collective results from the ping for this host.
Remarks:
This function is called just after all the pings for each host is complete. You can derive your own
class from CTraceRoute and override this function so that your version is called at the appropriate
times. See the CMyTraceRoute class in main.cpp for a concrete implementation.
- If you have any other suggested improvements, please let me know so that I can incorporate them into
the next release.
PJ Naughter
Email:
pjn@indigo.ie
Web:
http://www.naughter.com
18th November 1998
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.