summaryrefslogtreecommitdiff
path: root/usr.bin/nc/netcat.c
diff options
context:
space:
mode:
authorRyan Thomas McBride <mcbride@cvs.openbsd.org>2005-05-27 04:55:29 +0000
committerRyan Thomas McBride <mcbride@cvs.openbsd.org>2005-05-27 04:55:29 +0000
commit4470f6d571b57a867ad4f7875ea2cd7f46612f98 (patch)
tree8400c69016747dd92adad4694f3ecc9963d6d1f1 /usr.bin/nc/netcat.c
parente0dcbdc8ae74cec294cbf562a7cb834495055882 (diff)
Experimental support for opportunitic use of jumbograms where only some hosts
on the local network support them. This adds a new socket option, SO_JUMBO, and a new route flag, RTF_JUMBO. If _both_ the socket option is set and the route for the host has RTF_JUMBO set, ip_output will fragment the packet to the largest possible size for the link, ignoring the card's MTU. The semantics of this feature will be evolving rapidly; talk to us if you intend to use it. ok deraadt@ marius@
Diffstat (limited to 'usr.bin/nc/netcat.c')
-rw-r--r--usr.bin/nc/netcat.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
index 36d133a2bb4..d39cc0f9bf0 100644
--- a/usr.bin/nc/netcat.c
+++ b/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcat.c,v 1.79 2005/05/24 20:13:28 avsm Exp $ */
+/* $OpenBSD: netcat.c,v 1.80 2005/05/27 04:55:28 mcbride Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
*
@@ -63,6 +63,7 @@
/* Command Line Options */
int dflag; /* detached, no stdin */
int iflag; /* Interval Flag */
+int jflag; /* use jumbo frames if we can */
int kflag; /* More than one connect */
int lflag; /* Bind to local port */
int nflag; /* Don't do name look up */
@@ -115,7 +116,8 @@ main(int argc, char *argv[])
endp = NULL;
sv = NULL;
- while ((ch = getopt(argc, argv, "46Ddhi:klnp:rSs:tUuvw:X:x:z")) != -1) {
+ while ((ch = getopt(argc, argv,
+ "46Ddhi:jklnp:rSs:tUuvw:X:x:z")) != -1) {
switch (ch) {
case '4':
family = AF_INET;
@@ -147,6 +149,9 @@ main(int argc, char *argv[])
if (iflag < 0 || *endp != '\0')
errx(1, "interval cannot be negative");
break;
+ case 'j':
+ jflag = 1;
+ break;
case 'k':
kflag = 1;
break;
@@ -286,12 +291,13 @@ main(int argc, char *argv[])
* functions to talk to the caller.
*/
if (uflag) {
- int rv;
- char buf[1024];
+ int rv, plen;
+ char buf[8192];
struct sockaddr_storage z;
len = sizeof(z);
- rv = recvfrom(s, buf, sizeof(buf), MSG_PEEK,
+ plen = jflag ? 8192 : 1024;
+ rv = recvfrom(s, buf, plen, MSG_PEEK,
(struct sockaddr *)&z, &len);
if (rv < 0)
err(1, "recvfrom");
@@ -501,6 +507,11 @@ remote_connect(const char *host, const char *port, struct addrinfo hints)
&x, sizeof(x)) == -1)
err(1, NULL);
}
+ if (jflag) {
+ if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
+ &x, sizeof(x)) == -1)
+ err(1, NULL);
+ }
if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0)
break;
@@ -589,9 +600,12 @@ void
readwrite(int nfd)
{
struct pollfd pfd[2];
- unsigned char buf[BUFSIZ];
+ unsigned char buf[8192];
int n, wfd = fileno(stdin);
int lfd = fileno(stdout);
+ int plen;
+
+ plen = jflag ? 8192 : 1024;
/* Setup Network FD */
pfd[0].fd = nfd;
@@ -614,7 +628,7 @@ readwrite(int nfd)
return;
if (pfd[0].revents & POLLIN) {
- if ((n = read(nfd, buf, sizeof(buf))) < 0)
+ if ((n = read(nfd, buf, plen)) < 0)
return;
else if (n == 0) {
shutdown(nfd, SHUT_RD);
@@ -629,7 +643,7 @@ readwrite(int nfd)
}
if (!dflag && pfd[1].revents & POLLIN) {
- if ((n = read(wfd, buf, sizeof(buf))) < 0)
+ if ((n = read(wfd, buf, plen)) < 0)
return;
else if (n == 0) {
shutdown(nfd, SHUT_WR);