Glossary Item Box
A trace route operation identifies all of the intermediate hosts which forward a packet to a destination host. This operation works by first sending an ICMP packet to a host with a time-to-live of 1. At the first host the packet reaches (or hop), the time-to-live will be 0 and an ICMP packet will be returned to the sending host. An ICMP packet is then sent with a time-to-live of 2. This will cause the second host the packet reaches to send an ICMP packet to the sending host. This continues, incrementing time-to-live each time, until the host is reached or until MaxHops is reached.
Example 1: Performing a trace route with default settings.
This is the most standard usage example of the Trace component. Simply call Send, passing in the host name or IP address to which you would like to trace a route. When data arrives from each new hop, the Hop event will be raised, providing data about the hop. A single hop consists of 3 separate echoes to the same host. Upon completion of the method, a TraceResult is returned, which describes the entire trace operation.
[C#] private void TraceTest() { // Set all hops and echoes to be synchronous trace1.HopType = HopType.SynchHops; // Begin the trace operation TraceResult tr = trace1.Send("www.dart.com"); // Trace operation is complete, display info. Debug.WriteLine("Total hops: " + tr.Hops.Length); } private void trace1_Hop(object sender, Dart.PowerTCP.SslSockets.HopEventArgs e) { //Check for any exceptions. if(e.Exception == null) { //Display information about the hop Debug.WriteLine("Time-to-live for the hop: " + e.Result.TTL); Debug.WriteLine("Remote address: " + e.Result.RemoteAddress); //Now display info about each of the three echoes Debug.WriteLine("Response times for this hop"); foreach(EchoResult er in e.Result.Echoes) Debug.WriteLine(er.ResponseTime); } } [Visual Basic] Private Sub TraceTest() ' Set all hops and echoes to be synchronous Trace1.HopType = HopType.SynchHops ' Begin the trace operation Dim tr As TraceResult = Trace1.Send("www.dart.com") ' Trace operation is complete, display info. Debug.WriteLine("Total hops: " & tr.Hops.Length) End Sub Private Sub Trace1_Hop(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.HopEventArgs) Handles Trace1.Hop ' Check for any exceptions If Not e.Exception Is Nothing Then ' Display information about the hop Debug.WriteLine("Time-to-live for the hop: " & e.Result.TTL) Debug.WriteLine("Remote address: " & e.Result.RemoteAddress) ' Now display info about each of the three echoes Debug.WriteLine("Response times for this hop") Dim er As EchoResult For Each er In e.Result.Echoes Debug.WriteLine(er.ResponseTime) Next End If End Sub
Example 2: Changing the behavior of the hops.
Change the value of HopType property to change the behavior of the hops. Inserting the following line of code into the above examples will cause all hops and echoes to be sent asynchronously. NOTE! This does not cause the Send method to be asynchronous. This method will still block until complete. This simply causes all hops and echoes to be sent at once instead of sending them one at a time and waiting for the response from each.
[C#] // Set the hops to be sent asynchronously. trace1.HopType = HopType.AsynchHops; [Visual Basic] ' Set the hops to be sent asynchronously. Trace1.HopType = HopType.AsynchHops
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.