Index: contrib/tnftp/src/cmds.c =================================================================== --- contrib/tnftp/src/cmds.c (revision 355749) +++ contrib/tnftp/src/cmds.c (working copy) @@ -2653,10 +2653,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: contrib/tnftp/src/ftp_var.h =================================================================== --- contrib/tnftp/src/ftp_var.h (revision 355749) +++ contrib/tnftp/src/ftp_var.h (working copy) @@ -298,6 +298,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: contrib/tnftp/src/main.c =================================================================== --- contrib/tnftp/src/main.c (revision 355749) +++ contrib/tnftp/src/main.c (working copy) @@ -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" @@ -510,6 +513,13 @@ (void)xsignal(SIGUSR2, crankrate); (void)xsignal(SIGWINCH, setttywidth); + 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); + if (argc > 0) { if (isupload) { rval = auto_put(argc, argv, upload_path); Index: contrib/tnftp/src/util.c =================================================================== --- contrib/tnftp/src/util.c (revision 355749) +++ contrib/tnftp/src/util.c (working copy) @@ -1087,10 +1087,18 @@ sndbuf_size); } +#ifdef __FreeBSD__ + DPRINTF("auto_rcvbuf = %d\n", auto_rcvbuf); + 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_sndbuf = %d\n", auto_sndbuf); + 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);