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__
This commit is contained in:
10
glorytun.c
10
glorytun.c
@@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
|
||||||
#ifndef CLOCK_MONOTONIC_COARSE
|
#if !defined(CLOCK_MONOTONIC_COARSE) && defined(CLOCK_MONOTONIC)
|
||||||
#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
|
# define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GT_BUFFER_SIZE (4*1024*1024)
|
#define GT_BUFFER_SIZE (4*1024*1024)
|
||||||
@@ -199,6 +199,7 @@ static char *sk_get_name (int fd)
|
|||||||
return str_cat(strs, COUNT(strs));
|
return str_cat(strs, COUNT(strs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TCP_INFO
|
||||||
static socklen_t sk_get_info (int fd, struct tcp_info *ti)
|
static socklen_t sk_get_info (int fd, struct tcp_info *ti)
|
||||||
{
|
{
|
||||||
socklen_t len = sizeof(struct tcp_info);
|
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_rttvar, ti->tcpi_snd_ssthresh, ti->tcpi_snd_cwnd,
|
||||||
ti->tcpi_advmss, ti->tcpi_reordering);
|
ti->tcpi_advmss, ti->tcpi_reordering);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static struct addrinfo *ai_create (const char *host, const char *port, int listener)
|
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;
|
char *congestion = NULL;
|
||||||
int version = 0;
|
int version = 0;
|
||||||
|
|
||||||
|
#ifdef TCP_INFO
|
||||||
struct {
|
struct {
|
||||||
struct timespec time;
|
struct timespec time;
|
||||||
struct tcp_info info;
|
struct tcp_info info;
|
||||||
} tcpinfo = {0};
|
} tcpinfo = {0};
|
||||||
|
#endif
|
||||||
|
|
||||||
struct option opts[] = {
|
struct option opts[] = {
|
||||||
{ "dev", &dev, option_str },
|
{ "dev", &dev, option_str },
|
||||||
@@ -738,6 +742,7 @@ int main (int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(CLOCK_MONOTONIC_COARSE) && defined(TCP_INFO)
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC_COARSE, &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))
|
if (sk_get_info(sock.fd, &tcpinfo.info))
|
||||||
print_tcp_info(&tcpinfo.info);
|
print_tcp_info(&tcpinfo.info);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
buffer_shift(&sock.write.buf);
|
buffer_shift(&sock.write.buf);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user