Specifically in C, for *nix systems.
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.