Index: tnftp/dist/src/cmds.c =================================================================== --- tnftp/dist/src/cmds.c +++ tnftp/dist/src/cmds.c @@ -2659,10 +2659,14 @@ goto usage; } - if (dir & RATE_PUT) + if (dir & RATE_PUT) { sndbuf_size = size; - if (dir & RATE_GET) + auto_sndbuf = 0; + } + if (dir & RATE_GET) { rcvbuf_size = size; + auto_rcvbuf = 0; + } fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n", sndbuf_size, rcvbuf_size); code = 0; Index: tnftp/dist/src/ftp_var.h =================================================================== --- tnftp/dist/src/ftp_var.h +++ tnftp/dist/src/ftp_var.h @@ -302,6 +302,8 @@ GLOBAL int sndbuf_size; /* socket send buffer size */ GLOBAL int rcvbuf_size; /* socket receive buffer size */ +GLOBAL int auto_sndbuf; /* flag: if != 0 then use auto sndbuf size */ +GLOBAL int auto_rcvbuf; /* flag: if != 0 then use auto rcvbuf size */ GLOBAL int macnum; /* number of defined macros */ GLOBAL struct macel macros[16]; Index: tnftp/dist/src/main.c =================================================================== --- tnftp/dist/src/main.c +++ tnftp/dist/src/main.c @@ -127,6 +127,9 @@ #include #endif /* tnftp */ +#ifdef __FreeBSD__ +#include +#endif #define GLOBAL /* force GLOBAL decls in ftp_var.h to be declared */ #include "ftp_var.h" @@ -521,6 +524,15 @@ (void)xsignal(SIGUSR1, crankrate); (void)xsignal(SIGUSR2, crankrate); (void)xsignal(SIGWINCH, setttywidth); + +#ifdef __FreeBSD__ + auto_rcvbuf = ((sysctlbyname("net.inet.tcp.recvbuf_auto", + &auto_rcvbuf, &(size_t []){[0] = sizeof(int)}[0], NULL, 0) == 0) && + auto_rcvbuf == 1); + auto_sndbuf = ((sysctlbyname("net.inet.tcp.sendbuf_auto", + &auto_sndbuf, &(size_t []){[0] = sizeof(int)}[0], NULL, 0) == 0) && + auto_sndbuf == 1); +#endif if (argc > 0) { if (isupload) { Index: tnftp/dist/src/util.c =================================================================== --- tnftp/dist/src/util.c +++ tnftp/dist/src/util.c @@ -1113,10 +1113,18 @@ sndbuf_size); } +#ifdef __FreeBSD__ + DPRINTF("auto_sndbuf = %d\n", auto_sndbuf); + if (auto_sndbuf == 0) +#endif if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (void *)&sndbuf_size, sizeof(sndbuf_size)) == -1) warn("Unable to set sndbuf size %d", sndbuf_size); +#ifdef __FreeBSD__ + DPRINTF("auto_rcvbuf = %d\n", auto_rcvbuf); + if (auto_rcvbuf == 0) +#endif if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void *)&rcvbuf_size, sizeof(rcvbuf_size)) == -1) warn("Unable to set rcvbuf size %d", rcvbuf_size);