From cf279b3abcdaf1bbee65d622f17229b8a0cd32d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timo=20Ter=C3=A4s?= Date: Wed, 29 Apr 2015 09:43:03 +0300 Subject: [PATCH] sockopt: add support for querying tcp round-trip-time MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Timo Teräs Signed-off-by: David Lamparter (cherry picked from commit 6b2672f3c9493aef3495192e113f95a7db4b65bc) --- lib/sockopt.c | 16 ++++++++++++++++ lib/sockopt.h | 1 + 2 files changed, 17 insertions(+) diff --git a/lib/sockopt.c b/lib/sockopt.c index be22827f6e..257271bc0b 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -518,6 +518,22 @@ sockopt_iphdrincl_swab_systoh (struct ip *iph) iph->ip_id = ntohs(iph->ip_id); } +int +sockopt_tcp_rtt (int sock) +{ +#ifdef TCP_INFO + struct tcp_info ti; + socklen_t len = sizeof(ti); + + if (getsockopt (sock, IPPROTO_TCP, TCP_INFO, &ti, &len) != 0) + return 0; + + return ti.tcpi_rtt / 1000; +#else + return 0; +#endif +} + int sockopt_tcp_signature (int sock, union sockunion *su, const char *password) { diff --git a/lib/sockopt.h b/lib/sockopt.h index aced6d489f..cb14efc7ba 100644 --- a/lib/sockopt.h +++ b/lib/sockopt.h @@ -100,6 +100,7 @@ extern int getsockopt_ifindex (int, struct msghdr *); extern void sockopt_iphdrincl_swab_htosys (struct ip *iph); extern void sockopt_iphdrincl_swab_systoh (struct ip *iph); +extern int sockopt_tcp_rtt (int); extern int sockopt_tcp_signature(int sock, union sockunion *su, const char *password); #endif /*_ZEBRA_SOCKOPT_H */ -- 2.39.5