Click here to Skip to main content
15,881,281 members
Articles / Desktop Programming / MFC
Article

CTraceRoute v1.0

Rate me:
Please Sign up or sign in to vote.
4.64/5 (4 votes)
7 Apr 2000 80.3K   2.3K   40   6
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


    Written By
    United States United States
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    Generalerroneous results Pin
    NicolasCh2-Jul-07 23:33
    NicolasCh2-Jul-07 23:33 
    GeneralPreventing deadlock Pin
    sapero_19-Apr-07 12:25
    sapero_19-Apr-07 12:25 
    GeneralGreat Job.. Pin
    RobJones7-Apr-03 6:06
    RobJones7-Apr-03 6:06 
    GeneralHost's Name Pin
    Eric Hansen27-Mar-03 4:58
    Eric Hansen27-Mar-03 4:58 
    GeneralRe: Host's Name Pin
    pjnaughter27-Mar-03 6:07
    pjnaughter27-Mar-03 6:07 
    GeneralRe: Host's Name Pin
    Eric Hansen27-Mar-03 7:35
    Eric Hansen27-Mar-03 7:35 

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

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