Skip to content

Commit

Permalink
Define NO_TFO on macOS < 10.11
Browse files Browse the repository at this point in the history
  • Loading branch information
barracuda156 committed Sep 26, 2024
1 parent ab747d3 commit 577d587
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
#define gettext(x) (x)
#endif

#ifdef __APPLE__
#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100
#define NO_TFO
#endif
#endif

typedef struct
{
double cur, min, avg, max, sd, med;
Expand Down
4 changes: 4 additions & 0 deletions help.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ void version(void)
#endif
#endif

#ifndef NO_TFO
fprintf(stderr, gettext(" * TFO (TCP fast open) support included (-F)\n"));
#endif
fprintf(stderr, gettext("\n"));
}

Expand Down Expand Up @@ -207,7 +209,9 @@ void usage(const char *me)
format_help("-r", "--resolve-once", gettext("resolve hostname only once (useful when pinging roundrobin DNS: also takes the first DNS lookup out of the loop so that the first measurement is also correct)"));
format_help("-W", NULL, gettext("do not abort the program if resolving failed: keep retrying"));
format_help("-y x", "--bind-to", gettext("bind to an ip-address (and thus interface) with an optional port"));
#ifndef NO_TFO
format_help("-F", "--tcp-fast-open", gettext("\"TCP fast open\" (TFO), reduces the latency of TCP connects"));
#endif
#ifdef linux
format_help(NULL, "--priority", gettext("set priority of packets"));
#endif
Expand Down
8 changes: 7 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,11 @@ int main(int argc, char *argv[])
break;

case 'F':
#ifdef NO_TFO
fprintf(stderr, gettext("Warning: TCP TFO is not supported. Disabling.\n"));
#else
use_tfo = 1;
#endif
break;

case 22:
Expand Down Expand Up @@ -2157,7 +2161,7 @@ int main(int argc, char *argv[])
#if defined(linux) || defined(__FreeBSD__)
if (getsockopt(fd, IPPROTO_TCP, TCP_INFO, &info, &info_len) == 0)
{
#ifdef TCPI_OPT_SYN_DATA
#if defined(TCPI_OPT_SYN_DATA) && !defined(NO_TFO)
if (info.tcpi_options & TCPI_OPT_SYN_DATA)
tfo_success = 1;
#endif
Expand Down Expand Up @@ -2345,8 +2349,10 @@ int main(int argc, char *argv[])
#endif
}

#ifndef NO_TFO
if (tfo_success)
str_add(&line, " F");
#endif

#if HAVE_NCURSES
if (ncurses_mode)
Expand Down
7 changes: 7 additions & 0 deletions tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ int connect_to(int fd, struct addrinfo *ai, double timeout, char *tfo, char *msg
to.tv_usec = (long)(timeout * 1000.0) % 1000000;

/* connect to peer */
#ifdef NO_TFO
(void)tfo;
(void)msg;
(void)msg_len;
(void)msg_accepted;
#else
if (tfo && *tfo)
{
#if defined(__FreeBSD__)
Expand All @@ -182,6 +188,7 @@ int connect_to(int fd, struct addrinfo *ai, double timeout, char *tfo, char *msg
}
}
else
#endif
{
int rc = -1;

Expand Down

0 comments on commit 577d587

Please sign in to comment.