I need to set or get RTT in socket(AF_INET, SOCK_RAW, IPPROTO_TCP) way.
What do I need to do next to control such RTT in socket programming? In other words, how to find such RTT parameter?
I need to set or get RTT in socket(AF_INET, SOCK_RAW, IPPROTO_TCP) way.
What do I need to do next to control such RTT in socket programming? In other words, how to find such RTT parameter?
On Linux you can get the RTT by calling getsockopt() with TCP_INFO:
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
/* ... */
tcp_info info;
socklen_t tcp_info_length = sizeof info;
ret = getsockopt(sock, SOL_TCP, TCP_INFO, &info, &tcp_info_length);
printf("rtt: %u microseconds\n", info.tcpi_rtt);
getsockopt() is it after the call to accept() or after the call to read(..)read() will have any effect on the value.To measure the Round Trip Time (RTT) write a simple client-server application where one node:
clock_gettime()write() on the (already opened) socketread()clock_gettime()RTT is the difference between the two times.
gettimeofday(2) as obsolescent. clock_gettime(2) should be used instead (or time(2)).