summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormcbride <>2005-05-27 04:55:28 +0000
committermcbride <>2005-05-27 04:55:28 +0000
commit14301aa616fd926b3a5499a27d3725b57423f676 (patch)
tree6e2d8c87fda3831e15f944bbafac007ce040613c
parent27cee54a9cc6905a9d4c2bd35d41c9125e9a0ff0 (diff)
downloadopenbsd-14301aa616fd926b3a5499a27d3725b57423f676.tar.gz
openbsd-14301aa616fd926b3a5499a27d3725b57423f676.tar.bz2
openbsd-14301aa616fd926b3a5499a27d3725b57423f676.zip
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@
-rw-r--r--src/usr.bin/nc/netcat.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index 36d133a2bb..d39cc0f9bf 100644
--- a/src/usr.bin/nc/netcat.c
+++ b/src/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: netcat.c,v 1.79 2005/05/24 20:13:28 avsm Exp $ */ 1/* $OpenBSD: netcat.c,v 1.80 2005/05/27 04:55:28 mcbride Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * 4 *
@@ -63,6 +63,7 @@
63/* Command Line Options */ 63/* Command Line Options */
64int dflag; /* detached, no stdin */ 64int dflag; /* detached, no stdin */
65int iflag; /* Interval Flag */ 65int iflag; /* Interval Flag */
66int jflag; /* use jumbo frames if we can */
66int kflag; /* More than one connect */ 67int kflag; /* More than one connect */
67int lflag; /* Bind to local port */ 68int lflag; /* Bind to local port */
68int nflag; /* Don't do name look up */ 69int nflag; /* Don't do name look up */
@@ -115,7 +116,8 @@ main(int argc, char *argv[])
115 endp = NULL; 116 endp = NULL;
116 sv = NULL; 117 sv = NULL;
117 118
118 while ((ch = getopt(argc, argv, "46Ddhi:klnp:rSs:tUuvw:X:x:z")) != -1) { 119 while ((ch = getopt(argc, argv,
120 "46Ddhi:jklnp:rSs:tUuvw:X:x:z")) != -1) {
119 switch (ch) { 121 switch (ch) {
120 case '4': 122 case '4':
121 family = AF_INET; 123 family = AF_INET;
@@ -147,6 +149,9 @@ main(int argc, char *argv[])
147 if (iflag < 0 || *endp != '\0') 149 if (iflag < 0 || *endp != '\0')
148 errx(1, "interval cannot be negative"); 150 errx(1, "interval cannot be negative");
149 break; 151 break;
152 case 'j':
153 jflag = 1;
154 break;
150 case 'k': 155 case 'k':
151 kflag = 1; 156 kflag = 1;
152 break; 157 break;
@@ -286,12 +291,13 @@ main(int argc, char *argv[])
286 * functions to talk to the caller. 291 * functions to talk to the caller.
287 */ 292 */
288 if (uflag) { 293 if (uflag) {
289 int rv; 294 int rv, plen;
290 char buf[1024]; 295 char buf[8192];
291 struct sockaddr_storage z; 296 struct sockaddr_storage z;
292 297
293 len = sizeof(z); 298 len = sizeof(z);
294 rv = recvfrom(s, buf, sizeof(buf), MSG_PEEK, 299 plen = jflag ? 8192 : 1024;
300 rv = recvfrom(s, buf, plen, MSG_PEEK,
295 (struct sockaddr *)&z, &len); 301 (struct sockaddr *)&z, &len);
296 if (rv < 0) 302 if (rv < 0)
297 err(1, "recvfrom"); 303 err(1, "recvfrom");
@@ -501,6 +507,11 @@ remote_connect(const char *host, const char *port, struct addrinfo hints)
501 &x, sizeof(x)) == -1) 507 &x, sizeof(x)) == -1)
502 err(1, NULL); 508 err(1, NULL);
503 } 509 }
510 if (jflag) {
511 if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
512 &x, sizeof(x)) == -1)
513 err(1, NULL);
514 }
504 515
505 if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) 516 if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0)
506 break; 517 break;
@@ -589,9 +600,12 @@ void
589readwrite(int nfd) 600readwrite(int nfd)
590{ 601{
591 struct pollfd pfd[2]; 602 struct pollfd pfd[2];
592 unsigned char buf[BUFSIZ]; 603 unsigned char buf[8192];
593 int n, wfd = fileno(stdin); 604 int n, wfd = fileno(stdin);
594 int lfd = fileno(stdout); 605 int lfd = fileno(stdout);
606 int plen;
607
608 plen = jflag ? 8192 : 1024;
595 609
596 /* Setup Network FD */ 610 /* Setup Network FD */
597 pfd[0].fd = nfd; 611 pfd[0].fd = nfd;
@@ -614,7 +628,7 @@ readwrite(int nfd)
614 return; 628 return;
615 629
616 if (pfd[0].revents & POLLIN) { 630 if (pfd[0].revents & POLLIN) {
617 if ((n = read(nfd, buf, sizeof(buf))) < 0) 631 if ((n = read(nfd, buf, plen)) < 0)
618 return; 632 return;
619 else if (n == 0) { 633 else if (n == 0) {
620 shutdown(nfd, SHUT_RD); 634 shutdown(nfd, SHUT_RD);
@@ -629,7 +643,7 @@ readwrite(int nfd)
629 } 643 }
630 644
631 if (!dflag && pfd[1].revents & POLLIN) { 645 if (!dflag && pfd[1].revents & POLLIN) {
632 if ((n = read(wfd, buf, sizeof(buf))) < 0) 646 if ((n = read(wfd, buf, plen)) < 0)
633 return; 647 return;
634 else if (n == 0) { 648 else if (n == 0) {
635 shutdown(nfd, SHUT_WR); 649 shutdown(nfd, SHUT_WR);