diff --git a/SRC/configure.ac b/SRC/configure.ac index ba9e094..d47622c 100644 --- a/SRC/configure.ac +++ b/SRC/configure.ac @@ -215,6 +215,33 @@ AC_ARG_ENABLE(ttcp, TTCP=1 fi) +AC_MSG_CHECKING([TCP info from socket]) +AC_TRY_COMPILE( + [#include + #include + #include + ], + [int foobar = SOL_TCP;], + [AC_DEFINE(TCP_INFO,,[TCP info from socket]) + ac_have_tcp_info="yes"], + ac_have_tcp_info=no) +AC_MSG_RESULT($ac_have_tcp_info) +AC_ARG_ENABLE(tcp_info, + [ --enable-tcp-info TCP info from socket], + [if test "$enableval" = "yes"; then + if test $ac_have_tcp_info = "yes"; then + AC_DEFINE(TCP_INFO,,[TCP info from socket]) + TCP_INFO=1 + else + AC_MSG_WARN([No TCP info support on this system, request ignored]) + fi + fi], + dnl Default: enable it if supported + if test $ac_have_tcp_info = "yes"; then + AC_DEFINE(TCP_INFO,,[TCP info]) + TCP_INFO=1 + fi) + dnl Type Of Service AC_MSG_CHECKING([Type Of Service]) AC_TRY_COMPILE( diff --git a/SRC/echoping.c b/SRC/echoping.c index bea6096..d8c0c34 100644 --- a/SRC/echoping.c +++ b/SRC/echoping.c @@ -143,6 +143,10 @@ main(argc, argv) int priority_requested = 0; int tos; int tos_requested = 0; +#ifdef TCP_INFO + struct tcp_info tcpinfo; + socklen_t socket_length = sizeof(tcpinfo); +#endif char *p; echoping_options global_options; @@ -617,13 +621,13 @@ main(argc, argv) strcpy(port_name, "80"); } else if (strcmp - (port_name, DEFAULT_HTTPS_TCP_PORT) - == 0) { + (port_name, + DEFAULT_HTTPS_TCP_PORT) == 0) { strcpy(port_name, "443"); } else if (strcmp - (port_name, DEFAULT_ICP_UDP_PORT) - == 0) { + (port_name, + DEFAULT_ICP_UDP_PORT) == 0) { strcpy(port_name, "3130"); } } @@ -947,8 +951,7 @@ main(argc, argv) if (tcp) { (void) gettimeofday(&connectedtv, (struct timezone - *) - NULL); + *) NULL); temp = connectedtv; tvsub(&temp, &conntv); if (verbose) { @@ -1338,6 +1341,17 @@ main(argc, argv) } } /* That's all, folks */ alarm(0); +#ifdef TCP_INFO + /* Thanks to Perry Lorier for the tip */ + if (tcp && verbose) { + if (getsockopt + (sockfd, SOL_TCP, TCP_INFO, &tcpinfo, &socket_length) + != -1) { + printf("Estimated TCP RTT: %.04f seconds\n", + tcpinfo.tcpi_rtt / 1000000.0); + } + } +#endif if (http) { #ifdef OPENSSL if (ssl) diff --git a/SRC/echoping.h b/SRC/echoping.h index 4cf8583..a644736 100644 --- a/SRC/echoping.h +++ b/SRC/echoping.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include