CIcmpClient::TraceRoute Method  
 
BOOL TraceRoute(
  LPCTSTR lpszHostName,  
  UINT nMaxHops,  
  DWORD dwTimeout  
);

The TraceRoute method sends a series of ICMP echo datagrams to trace the route taken from the local system to the remote host.

Parameters

lpszHostName
A pointer to a string which specifies the fully qualified domain name of the remote host, or the IP address in dotted notation.
nMaxHops
An unsigned integer which specifies the maximum number of routers the datagram will be forwarded through (the number of hops) to the remote host. The minimum value is 1 and the maximum value is 255. It is recommended that most applications specify a value of at least 30.
dwTimeout
An unsigned integer which specifies the number of milliseconds the method will wait for a response to an echo datagram.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The TraceRoute method sends a series of ICMP echo datagrams to the specified host, adjusting the time-to-live value to determine the intermediate hosts that route the packet. Use the GetFirstHost and GetNextHost methods to enumerate the hosts returned by the method.

It is important to note that the failure of an intermediate host to respond to an ICMP echo datagram may not indicate a problem with the remote system. Systems can be configured to specifically ignore ICMP echo datagrams and not respond to them; this is often a security measure to prevent certain kinds of Denial of Service attacks.

The ability to send ICMP datagrams may be restricted to users with administrative privileges, depending on the policies and configuration of the local system. If you are unable to send or receive any ICMP datagrams, it is recommended that you check the firewall settings and any third-party security software that could impact the normal operation of this component.

Example

BOOL bResult = pClient->TraceRoute(strAddress);
if (bResult)
{
    ICMPTRACE icmpTrace;

    bResult = pClient->GetFirstHost(icmpTrace);
    while (bResult)
    {
        // The icmpTrace structure contains information about the
        // intermediate host in the traceroute
        CString strHostName;
        pClient->ResolveAddress(icmpTrace.dwHostAddress, strHostName);

        bResult = pClient->GetNextHost(icmpTrace);
    }
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: csicmv11.lib

See Also

Echo, GetFirstHost, GetNextHost, ResolveAddress