Introduction
This Project was undertaken on the needs to explore Sockets and its different Uses . I started by making a Ping program which 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 same program (Ping program ) which used Raw Sockets.
What and Why?
Ping program basically sends ICMP Packets to Remote Host and asks it to send back an reply and calculates the Time to get the reply back. Trace Route traces the Route of our packets via network , identifying the IP Address of every host .
How To Run it ?
The standard Trace Route (tracert.exe) which comes with Windows Operating System was basically an example for me to emulate. The short comings ( 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 1 ICMP reply. As soon as I get 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 of the EXE and with space type the URL or ip Address like C:\>TracesRoutes.exe x.x.x.x timeout(Optional). 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 a few changes here and there. The main function is
Decode_Reply
int decode_reply( IPHeader* reply, int bytes, sockaddr_in* from )
{
......
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;
}
}
else if (icmphdr->id != (USHORT)GetCurrentProcessId())
{
return -2;
}
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 some other Computer on same network to test it.
Changes
I have added Destination Unreachable Case. The code is messy so if you find anything which can make it better do send in a line at my Web Site or my Email.
Comments?
Kindly Send ur Comments through http://babarq.netfirms.com/. Thanks.