summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarius <>2005-05-28 16:57:48 +0000
committermarius <>2005-05-28 16:57:48 +0000
commit183b6733970efb96d69e51e501575f3da2c096fc (patch)
treeb7bea70bbd6c78d185cb78af9827d21dc80cc3a6
parent14301aa616fd926b3a5499a27d3725b57423f676 (diff)
downloadopenbsd-183b6733970efb96d69e51e501575f3da2c096fc.tar.gz
openbsd-183b6733970efb96d69e51e501575f3da2c096fc.tar.bz2
openbsd-183b6733970efb96d69e51e501575f3da2c096fc.zip
set jumbo flag on the listener, too. consolidate some common code.
ok mcbride@
-rw-r--r--src/usr.bin/nc/netcat.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index d39cc0f9bf..a8b4ac3839 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.80 2005/05/27 04:55:28 mcbride Exp $ */ 1/* $OpenBSD: netcat.c,v 1.81 2005/05/28 16:57:48 marius Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * 4 *
@@ -93,6 +93,7 @@ int socks_connect(const char *, const char *, struct addrinfo, const char *, con
93int udptest(int); 93int udptest(int);
94int unix_connect(char *); 94int unix_connect(char *);
95int unix_listen(char *); 95int unix_listen(char *);
96int set_common_sockopts(int);
96void usage(int); 97void usage(int);
97 98
98int 99int
@@ -462,7 +463,7 @@ int
462remote_connect(const char *host, const char *port, struct addrinfo hints) 463remote_connect(const char *host, const char *port, struct addrinfo hints)
463{ 464{
464 struct addrinfo *res, *res0; 465 struct addrinfo *res, *res0;
465 int s, error, x = 1; 466 int s, error;
466 467
467 if ((error = getaddrinfo(host, port, &hints, &res))) 468 if ((error = getaddrinfo(host, port, &hints, &res)))
468 errx(1, "getaddrinfo: %s", gai_strerror(error)); 469 errx(1, "getaddrinfo: %s", gai_strerror(error));
@@ -497,21 +498,8 @@ remote_connect(const char *host, const char *port, struct addrinfo hints)
497 errx(1, "bind failed: %s", strerror(errno)); 498 errx(1, "bind failed: %s", strerror(errno));
498 freeaddrinfo(ares); 499 freeaddrinfo(ares);
499 } 500 }
500 if (Sflag) { 501
501 if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG, 502 set_common_sockopts(s);
502 &x, sizeof(x)) == -1)
503 err(1, NULL);
504 }
505 if (Dflag) {
506 if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
507 &x, sizeof(x)) == -1)
508 err(1, NULL);
509 }
510 if (jflag) {
511 if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
512 &x, sizeof(x)) == -1)
513 err(1, NULL);
514 }
515 503
516 if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) 504 if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0)
517 break; 505 break;
@@ -562,17 +550,8 @@ local_listen(char *host, char *port, struct addrinfo hints)
562 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); 550 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
563 if (ret == -1) 551 if (ret == -1)
564 err(1, NULL); 552 err(1, NULL);
565 if (Sflag) { 553
566 ret = setsockopt(s, IPPROTO_TCP, TCP_MD5SIG, 554 set_common_sockopts(s);
567 &x, sizeof(x));
568 if (ret == -1)
569 err(1, NULL);
570 }
571 if (Dflag) {
572 if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
573 &x, sizeof(x)) == -1)
574 err(1, NULL);
575 }
576 555
577 if (bind(s, (struct sockaddr *)res0->ai_addr, 556 if (bind(s, (struct sockaddr *)res0->ai_addr,
578 res0->ai_addrlen) == 0) 557 res0->ai_addrlen) == 0)
@@ -773,6 +752,28 @@ udptest(int s)
773 return (ret); 752 return (ret);
774} 753}
775 754
755int
756set_common_sockopts(int s)
757{
758 int x = 1;
759
760 if (Sflag) {
761 if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
762 &x, sizeof(x)) == -1)
763 err(1, NULL);
764 }
765 if (Dflag) {
766 if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
767 &x, sizeof(x)) == -1)
768 err(1, NULL);
769 }
770 if (jflag) {
771 if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
772 &x, sizeof(x)) == -1)
773 err(1, NULL);
774 }
775}
776
776void 777void
777help(void) 778help(void)
778{ 779{