Click here to Skip to main content
Click here to Skip to main content

CTraceRoute v1.0

, 7 Apr 2000
Rate this:
Please Sign up or sign in to vote.
A freeware MFC class to implement traceroute functionality.
  • Download source files - 13 Kb
  • Welcome to CTraceRoute, a freeware MFC class to implement trace route functionality.


    Features
    Usage
    History
    API Reference
    Planned Enhancements
    Contacting the Author


    Features

    • 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.


    Usage

    • 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.


    History

    V1.0 (18th November 1998)
    • Initial public release.


    API Reference

    The API consists of the the 2 classes:

    CTraceRouteReply
    CTraceRoute


    CTraceRouteReply

    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.


    CTraceRoute

    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.



    Planned Enhancements

    • If you have any other suggested improvements, please let me know so that I can incorporate them into the next release.


    Contacting the Author

    PJ Naughter
    Email: pjn@indigo.ie
    Web: http://www.naughter.com
    18th November 1998


    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    Share

    About the Author

    PJ Naughter

    United States United States
    No Biography provided

    Comments and Discussions

     
    Generalerroneous results PinmemberNicolasCh3-Jul-07 0:33 
    Hi. I have such results:
     
    Tracing route to codeproject.com
    over a maximum of 30 hops:
     
    1 * * * Error:11013
    2 * * * Error:11013
    3 * * * Error:11013
    4 * * * Error:11013
    5 * * * Error:11013
    6 * * * Error:11013
    7 * * * Error:11013
    8 * * * Error:11013
    9 * * * Error:11013
    10 * * * Error:11013
    11 * * * Error:11013
    12 * * * Error:11013
    13 * * * Error:11013
    14 * * * Error:11013
    15 * * * Error:11013
    16 * * * Error:11013
    17 * * * Error:11013
    18 * * * Error:11013
    19 * * * Error:11013
    20 * * * Error:11013
    21 * * * Error:11013
    22 * * * Error:11013
    23 * * * Error:11013
    24 * * * Error:11013
    25 * * * Error:11013
    26 1092 ms 1191 ms 1264 ms www.codeproject.com [69.10.233.10]
     
    Trace complete.
     
    Why?
     
    happynomm

    GeneralPreventing deadlock Pinmembersapero_19-Apr-07 13:25 
    GeneralGreat Job.. PinmemberRobJones7-Apr-03 7:06 
    GeneralHost's Name PinmemberEric Hansen27-Mar-03 5:58 
    GeneralRe: Host's Name Pinmemberpjnaughter27-Mar-03 7:07 
    GeneralRe: Host's Name PinmemberEric Hansen27-Mar-03 8:35 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web02 | 2.8.141223.1 | Last Updated 8 Apr 2000
    Article Copyright 2000 by PJ Naughter
    Everything else Copyright © CodeProject, 1999-2014
    Layout: fixed | fluid