From baa60a539c55dbde3a91c9d1ca12f75899954606 Mon Sep 17 00:00:00 2001 From: Stephane Bortzmeyer Date: Mon, 12 Mar 2007 20:35:01 +0000 Subject: [PATCH] echoping does not connect or handle the TCP socket, the plugin has to do it. --- SRC/PLUGINS | 5 ++++- SRC/plugins/whois/whois.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/SRC/PLUGINS b/SRC/PLUGINS index 2b8e8d1..4287702 100644 --- a/SRC/PLUGINS +++ b/SRC/PLUGINS @@ -6,11 +6,14 @@ echoping a struct addrinfo. All the DNS stuff, including IDN, is performed by echoping. You can immediately start using the struct addrinfo. -But some libraries (typically, the one used by the DBMS) do not work +But some libraries (typically, the one used by the DBMSs) do not work on struct addrinfo but on strings such as "dbname=test hostname=foo.bar". Plugins using these libraries will have to use the raw interface. The host name given as argument is ignored. +[Do note there is *no* interface where the TCP connection and shutdown +are done by echoping. They are always performed by the plugin.] + You indicate to echoping wether you use the raw interface or the cooked one by returning a port name or NULL from the init() function. diff --git a/SRC/plugins/whois/whois.c b/SRC/plugins/whois/whois.c index bfe6404..fa12e49 100644 --- a/SRC/plugins/whois/whois.c +++ b/SRC/plugins/whois/whois.c @@ -21,6 +21,7 @@ int n; int sockfd; FILE *files = NULL; poptContext whois_poptcon; +echoping_options general_options; void whois_usage(const char *msg) @@ -46,6 +47,7 @@ init(const int argc, const char **argv, echoping_options global_options) ""}, POPT_AUTOHELP POPT_TABLEEND }; + general_options = global_options; if (global_options.udp) err_quit("UDP is incompatible with this whois plugin"); /* Will probably be catched before because /etc/services have no entry for @@ -88,6 +90,10 @@ execute() int nr = 0; char recvline[MAX_LINE + 1]; char complete_request[MAX_REQUEST]; +#ifdef HAVE_TCP_INFO + struct tcp_info tcpinfo; + socklen_t socket_length = sizeof(tcpinfo); +#endif if ((sockfd = socket(whois_server.ai_family, whois_server.ai_socktype, whois_server.ai_protocol)) < 0) @@ -106,6 +112,17 @@ execute() printf("%s", recvline); if (dump) printf("\n"); +#ifdef HAVE_TCP_INFO + /* Thanks to Perry Lorier for the tip */ + if (general_options.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 close(sockfd); return 1; }