I found out about the implementation of ping.
I had one doubt about this. Confidence in how they calculate round-trip time.
They made some calculations to calculate round-trip time. I can not understand this calculation.
Here is the code for calculating round-trip time.
tsum += triptime; tsum2 += (long long)triptime * (long long)triptime; if (triptime < tmin) tmin = triptime; if (triptime > tmax) tmax = triptime; if (!rtt) rtt = triptime*8; else rtt += triptime-rtt/8;
The variables tsum, tsum2, triptime, tmax are initially equal to 0. The value of tmin contains the value as 2147483647 as originally. The triptime event is evaluated before sending a packet marked once. At the destination, the packet is received, before it sends a replay, it will notice one time, and it will fill it in the response packet and send the response. Subtracted two times and convert this subtracted time into microseconds. The triptime variable contains microseconds.
For example, take the bottom output to calculate rtt.
The shutdown time for the first packet is 42573, and the second packet 43707, the third packet 48047 and the fourth packet 42559.
Using this, how they calculate round-trip time. Why they are multiplied with 8 at the beginning and after that they are divided by 8 and subtracted with the first rtt. I can not find why they calculate rtt like this. Can someone explain to me why they multiply with 8 at the beginning, and after that they divide by 8 and subtract with the calculated rtt. The link below contains the full ping implementation code.
ping_common.c
ping.c
Thanks in advance.
user6274470
source share