Trace Utility to Trace IP Packet Path
User Level: Advanced
Source Code: Trace.zip
Overview: Trace utility traces the path of an IP packet. To understand theprocess, its important to understand ICMP protocol we are going to use for thispurpose.
ICMP Protocol: The Internet Protocol (IP) is used forhost-to-host datagram service in a system of interconnected networks.Occasionally a destination host will communicate with a source host, forexample, to report an error in datagram processing. For such purposes the Internet Control Message Protocol (ICMP), is used. ICMP, uses the basic supportof IP as if it were a higher level protocol, however, ICMP is actually anintegral part of IP, and must be implemented by every IP module.
ICMP messages are sent in several situations: for example, when a datagramcannot reach its destination, when the gateway does not have the bufferingcapacity to forward a datagram, and when the gateway can direct the host to sendtraffic on a shorter route.
The Internet Protocol is not designed to be absolutely reliable. The purposeof these control messages is to provide feedback about problems in thecommunication environment, not to make IP reliable. There are still noguarantees that a datagram will be delivered or a control message will bereturned. Some datagrams may still be undelivered without any report of theirloss. The higher level protocols that use IP must implement their ownreliability procedures if reliable communication is required.
The ICMP messages typically report errors in the processing of datagrams. Toavoid the infinite regress of messages about messages etc., no ICMP messages aresent about ICMP messages. Also ICMP messages are only sent about errors inhandling fragment zero of fragemented datagrams. (Fragment zero has the fragmentoffeset equal zero).
Basics of Trace utility: Apart from other fields eachICMP header consists of a field called Time to Live (TTL). TTL field is decremented at each machine in which the datagram isprocessed. Thus if my packet routes through Machine A-> Machine B->Machine C, and if I set initial TTL to 3 then TTL at B would be 2 and at C wouldbe 1. If the gateway processing a datagram finds TTL field is zero it discardsthe datagram. The gateway also notifies the source host via the time exceededmessage.
Thus to get our utility working we send apacket containing echo request to the destination machine with increasing numberof TTL starting from 1. Each time TTL goes to zero the machine that wascurrently processing datagram returns the packet with time exceeded message. Weremeber the ip of this machine and send the packet back with incremented TTL. Werepeat this till we successfully receive an echo reply.
You can compile the .cs file on command line by command
csc Trace.cs
and run it
Trace www.csharphelp.com
Questions? Send them to me at lparam@hotmail.com
About the Author: Sanjay Ahuja is a Bachelor of Engineer and has done his CDAC fromPune,India. He is currently working as a consultant for Verizon




16. Sep, 2006 by 







No comments yet... Be the first to leave a reply!