Exploring Trace Routes



Click here for a larger image.

Environment: VC6 SP4, NT4 SP3, winCE 2.0

Introduction

This project was undertaken because of the need to explore sockets and their different uses. I started by making a ping program that pinged the network addresses. The ping program was inspired by FAQs at http://tangentsoft.net/wskfaq/ and mostly used their functions!!!! The route program is an enhancement of the same program (ping program) that used raw sockets.

How to Run It

The standard Trace Route that comes with the Windows Operating System was basically an example for me to emulate. The shortcomings (which is my point of view) with the standard Trace Route was the delay it had, which takes three (and I presume ICMP Packet replies). My program takes one ICMP reply. As soon as I get an ICMP_ECHO(integer 0) reply, I know that the packet has reached the destination and the program exits.

Go to Command Prompt ... in the Dos Prompt. Type the Path or the EXE and with space, type the URL or ip Address such as C:\>TracesRoutes.exe x.x.x.x Remember to type a valid IP Address; otherwise, an error message "Destination Unreachable " would be given.

The Code

All of the code is the same except for a few changes here and there. The main function is Decode_Reply.

int decode_reply( IPHeader* reply, int bytes, sockaddr_in* from )
{
......
    // Make sure the reply is sane
    if (bytes < header_len + ICMP_MIN)
    {
        cerr << "too few bytes from " << inet_ntoa(from->sin_addr)
                                      << endl;
        return -1;
    }
    else if ( icmphdr->type != ICMP_ECHO_REPLY )
    {
        if ( icmphdr->type != ICMP_TTL_EXPIRE )
        {
            if ( icmphdr->type == ICMP_DEST_UNREACH )
            {
                cerr << "Destination unreachable" << endl;
            }
            else
            {
                cerr << "Unknown ICMP packet type "
                     << int(icmphdr->type) <<
                        " received" << endl;
            }
            return -1;
        }
        // If "TTL expired", fall through. Next test will fail
        // if we try it, so we need a way past it.
    }
    else if (icmphdr->id != (USHORT)GetCurrentProcessId())
    {
        // Must be a reply for another pinger running locally,
        // so just ignore it.
        return -2;
    }


    // Okay, we ran the gamut, so the packet must be legal --
    // dump it
    if (( icmphdr->type == ICMP_TTL_EXPIRE ) ||
        ( icmphdr->type == ICMP_ECHO_REPLY ) )
    {
        in_addr in;
        in.S_un.S_addr = reply->source_ip;
        cout << "\n Source IP " << inet_ntoa( in ) ;
        int nTime = GetTickCount () - ulTimestamp ;
        if ( nTime < 0 )
        {
            cout << "  Time: " << "<10 ms."
                 << endl;
        }
        else
        {
            cout << "  Time: " << ( GetTickCount() -
                 ulTimestamp ) << " ms." << endl;
        }
    }
.........
    return> 0;
}

Problems?

If you are facing problems, contact your system administrator. I have tested this software on both private and public IPs. Mostly, System Administrators disable this functionality. If you are on a network, you can trace another computer on same network to test it.

Comments?

Kindly send your comments to http://babarq.netfirms.com. Thanx.

Downloads

Download demo project - 36 Kb


Comments

  • TraceRoute

    Posted by Legacy on 07/31/2003 12:00am

    Originally posted by: Babar

    Updated .... but dont know how to Edit my Contribution here .... ask me for Src

    Reply
  • problem

    Posted by Legacy on 12/10/2002 12:00am

    Originally posted by: luru

    Maybe you haven't set proper wait timeout.So when it receives nothing,it will down.

    Reply
  • Source

    Posted by Legacy on 12/06/2002 12:00am

    Originally posted by: Richard

    Could you please post the source code?

    Thanks,
    Richard

    • Do you have the Java source code,please?

      Posted by fengyeqing on 04/15/2005 09:54pm

      My E_mail: sunzhiyang2003@yahoo.com.cn

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today make data protection a must-have, as we live in a data driven society. The digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join eVault Chief Technology …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds