RTT and Hop Count

IPHLPAPI provides an API to obtain RTT(Round Trip Time) and Hop Count. In this page, usage of GetRTTAndHopCount() is shown.

Sample code

The following sample code shows how to use GetRTTAndHopCount().

#include <stdio.h>

#include <winsock2.h>
#include <iphlpapi.h>

 IPAddr ipaddr = inet_addr("");
 ULONG hopCount = 0;
 ULONG maxHops = 64;
 ULONG rtt = 0;

 if (GetRTTAndHopCount(ipaddr, &hopCount, maxHops, &rtt) == TRUE) {
   printf("Hops: %ld\n", hopCount);
   printf("RTT:  %ld msec\n", rtt);
 } else {
	 printf("GetRTTAndHopCount failed : %d\n", GetLastError());

 return 0;

Sample code output

The sample will output an message like the following.

The destination host in this sample is (localhost). Therefore, the Hops is 1 in the sample result. The RTT value 0 is also because the sample destination is localhost. RTT is 0 because the round trip time to itself does not take any time.

Please note that, if you change the destination host to an other IP address, these values will change. The RTT and Hops will be a more higher value.

C:> a.exe
Hops: 1
RTT:  0


Copyright (C) GeekPage.JP. All rights reserved.