diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2008-05-06 05:47:40 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2008-05-06 05:47:40 +0000 |
commit | 6ca236c8629db5e6e30b7cd23c1932488878b1f9 (patch) | |
tree | bf9693f87e736cf8ba46fea10288272d7ae1f543 /usr.bin | |
parent | 8a313ad5d402ab3bd48b4b40f2f9116dca559d3f (diff) |
allow setting of TCP send/receive buffer sizes; ok markus@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/nc/nc.1 | 10 | ||||
-rw-r--r-- | usr.bin/nc/netcat.c | 33 |
2 files changed, 38 insertions, 5 deletions
diff --git a/usr.bin/nc/nc.1 b/usr.bin/nc/nc.1 index 441ef321985..9e32ad97c6a 100644 --- a/usr.bin/nc/nc.1 +++ b/usr.bin/nc/nc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: nc.1,v 1.45 2007/05/31 19:20:13 jmc Exp $ +.\" $OpenBSD: nc.1,v 1.46 2008/05/06 05:47:39 djm Exp $ .\" .\" Copyright (c) 1996 David Sacerdote .\" All rights reserved. @@ -25,7 +25,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: May 6 2008 $ .Dt NC 1 .Os .Sh NAME @@ -35,7 +35,9 @@ .Nm nc .Bk -words .Op Fl 46DdhklnrStUuvz +.Op Fl I Ar receive_buffer_len .Op Fl i Ar interval +.Op Fl O Ar send_buffer_len .Op Fl P Ar proxy_username .Op Fl p Ar source_port .Op Fl s Ar source_ip_address @@ -101,6 +103,8 @@ Do not attempt to read from stdin. Prints out .Nm help. +.It Fl I Ar receive_buffer_len +Specifies the size of the TCP receive buffer. .It Fl i Ar interval Specifies a delay time interval between lines of text sent and received. Also causes a delay time between connections to multiple ports. @@ -118,6 +122,8 @@ Used to specify that should listen for an incoming connection rather than initiate a connection to a remote host. It is an error to use this option in conjunction with the +.It Fl O Ar send_buffer_len +Specifies the size of the TCP send buffer. .Fl p , .Fl s , or diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c index 1c671f2e75e..4228326bdd8 100644 --- a/usr.bin/nc/netcat.c +++ b/usr.bin/nc/netcat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcat.c,v 1.89 2007/02/20 14:11:17 jmc Exp $ */ +/* $OpenBSD: netcat.c,v 1.90 2008/05/06 05:47:39 djm Exp $ */ /* * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> * @@ -80,6 +80,8 @@ int vflag; /* Verbosity */ int xflag; /* Socks proxy */ int zflag; /* Port Scan Flag */ int Dflag; /* sodebug */ +int Iflag; /* TCP receive buffer size */ +int Oflag; /* TCP send buffer size */ int Sflag; /* TCP MD5 signature option */ int Tflag = -1; /* IP Type of Service */ @@ -123,7 +125,7 @@ main(int argc, char *argv[]) sv = NULL; while ((ch = getopt(argc, argv, - "46Ddhi:jklnP:p:rSs:tT:Uuvw:X:x:z")) != -1) { + "46DdhI:i:jklnO:P:p:rSs:tT:Uuvw:X:x:z")) != -1) { switch (ch) { case '4': family = AF_INET; @@ -205,6 +207,18 @@ main(int argc, char *argv[]) case 'D': Dflag = 1; break; + case 'I': + Iflag = strtonum(optarg, 1, 65536 << 14, &errstr); + if (errstr != NULL) + errx(1, "TCP receive window %s: %s", + errstr, optarg); + break; + case 'O': + Oflag = strtonum(optarg, 1, 65536 << 14, &errstr); + if (errstr != NULL) + errx(1, "TCP send window %s: %s", + errstr, optarg); + break; case 'S': Sflag = 1; break; @@ -781,6 +795,16 @@ set_common_sockopts(int s) &Tflag, sizeof(Tflag)) == -1) err(1, "set IP ToS"); } + if (Iflag) { + if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, + &Iflag, sizeof(Iflag)) == -1) + err(1, "set TCP receive buffer size"); + } + if (Oflag) { + if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, + &Oflag, sizeof(Oflag)) == -1) + err(1, "set TCP send buffer size"); + } } int @@ -810,10 +834,12 @@ help(void) \t-D Enable the debug socket option\n\ \t-d Detach from stdin\n\ \t-h This help text\n\ + \t-I length TCP receive buffer length\n\ \t-i secs\t Delay interval for lines sent, ports scanned\n\ \t-k Keep inbound sockets open for multiple connects\n\ \t-l Listen mode, for inbound connects\n\ \t-n Suppress name/port resolutions\n\ + \t-O length TCP send buffer length\n\ \t-P proxyuser\tUsername for proxy authentication\n\ \t-p port\t Specify local port for remote connects\n\ \t-r Randomize remote ports\n\ @@ -835,7 +861,8 @@ help(void) void usage(int ret) { - fprintf(stderr, "usage: nc [-46DdhklnrStUuvz] [-i interval] [-P proxy_username] [-p source_port]\n"); + fprintf(stderr, "usage: nc [-46DdhklnrStUuvz] [-I receive_buffer_len] [-i interval]\n"); + fprintf(stderr, "\t [-O send_buffer_len] [-P proxy_username] [-p source_port]\n"); fprintf(stderr, "\t [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]\n"); fprintf(stderr, "\t [-x proxy_address[:port]] [hostname] [port[s]]\n"); if (ret) |