Search code examples
clinuxtcpposix

How do you get the current RTT estimation for a tcp socket?


Specifically in C, for *nix systems.


Solution

  • You can use the linux-specific socket option TCP_INFO for that (defined in linux/tcp.h)

    struct tcp_info ti;
    socklen_t tisize = sizeof(ti);
    getsockopt(fd, IPPROTO_TCP, TCP_INFO, &ti, &tisize);
    

    Now the rtt-estimation is in ti.tcpi_rtt (unit is milliseconds). There are several more interesting values, just look into the structure tcp_info.