From 69366ab99695826fe341544acbaf037e74e8aaad Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 7 Nov 2015 23:05:37 +0100 Subject: [PATCH] Don't expect TCP_INFO and clock_gettime() to be portable Sadly, TCP_INFO is only available on Linux and FreeBSD. Other systems make it easy to retrieve interface-specific parameters, but not the parameters for a given socket, except by inspecting PF states. clock_gettime() is available on all BSD systems, but not on OSX. mach_absolute_time() can be used there, but since it was only used to display the TCP socket info, and TCP_INFO doesn't exist on OSX, let's just ignore that altogether for now. That's pretty sad but at least, it makes glorytun usable on !__linux__ --- glorytun.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/glorytun.c b/glorytun.c index 1c64062..fbe3800 100644 --- a/glorytun.c +++ b/glorytun.c @@ -19,8 +19,8 @@ #include -#ifndef CLOCK_MONOTONIC_COARSE -#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC +#if !defined(CLOCK_MONOTONIC_COARSE) && defined(CLOCK_MONOTONIC) +# define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC #endif #define GT_BUFFER_SIZE (4*1024*1024) @@ -199,6 +199,7 @@ static char *sk_get_name (int fd) return str_cat(strs, COUNT(strs)); } +#ifdef TCP_INFO static socklen_t sk_get_info (int fd, struct tcp_info *ti) { socklen_t len = sizeof(struct tcp_info); @@ -227,6 +228,7 @@ static void print_tcp_info (struct tcp_info *ti) ti->tcpi_rttvar, ti->tcpi_snd_ssthresh, ti->tcpi_snd_cwnd, ti->tcpi_advmss, ti->tcpi_reordering); } +#endif static struct addrinfo *ai_create (const char *host, const char *port, int listener) { @@ -637,10 +639,12 @@ int main (int argc, char **argv) char *congestion = NULL; int version = 0; +#ifdef TCP_INFO struct { struct timespec time; struct tcp_info info; } tcpinfo = {0}; +#endif struct option opts[] = { { "dev", &dev, option_str }, @@ -738,6 +742,7 @@ int main (int argc, char **argv) return 1; } +#if defined(CLOCK_MONOTONIC_COARSE) && defined(TCP_INFO) struct timespec now; clock_gettime(CLOCK_MONOTONIC_COARSE, &now); @@ -746,6 +751,7 @@ int main (int argc, char **argv) if (sk_get_info(sock.fd, &tcpinfo.info)) print_tcp_info(&tcpinfo.info); } +#endif buffer_shift(&sock.write.buf);