summaryrefslogtreecommitdiff
path: root/src/usr.bin/nc/netcat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr.bin/nc/netcat.c')
-rw-r--r--src/usr.bin/nc/netcat.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index df5c44a8ce..baeb3cefd1 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.64 2003/10/19 22:50:35 deraadt Exp $ */ 1/* $OpenBSD: netcat.c,v 1.65 2004/01/22 13:28:46 markus Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * 4 *
@@ -37,6 +37,7 @@
37#include <sys/un.h> 37#include <sys/un.h>
38 38
39#include <netinet/in.h> 39#include <netinet/in.h>
40#include <netinet/tcp.h>
40#include <arpa/telnet.h> 41#include <arpa/telnet.h>
41 42
42#include <err.h> 43#include <err.h>
@@ -71,6 +72,7 @@ int uflag; /* UDP - Default to TCP */
71int vflag; /* Verbosity */ 72int vflag; /* Verbosity */
72int xflag; /* Socks proxy */ 73int xflag; /* Socks proxy */
73int zflag; /* Port Scan Flag */ 74int zflag; /* Port Scan Flag */
75int Sflag; /* TCP MD5 signature option */
74 76
75int timeout = -1; 77int timeout = -1;
76int family = AF_UNSPEC; 78int family = AF_UNSPEC;
@@ -111,7 +113,7 @@ main(int argc, char *argv[])
111 endp = NULL; 113 endp = NULL;
112 sv = NULL; 114 sv = NULL;
113 115
114 while ((ch = getopt(argc, argv, "46UX:hi:klnp:rs:tuvw:x:z")) != -1) { 116 while ((ch = getopt(argc, argv, "46UX:hi:klnp:rs:tuvw:x:zS")) != -1) {
115 switch (ch) { 117 switch (ch) {
116 case '4': 118 case '4':
117 family = AF_INET; 119 family = AF_INET;
@@ -178,6 +180,9 @@ main(int argc, char *argv[])
178 case 'z': 180 case 'z':
179 zflag = 1; 181 zflag = 1;
180 break; 182 break;
183 case 'S':
184 Sflag = 1;
185 break;
181 default: 186 default:
182 usage(1); 187 usage(1);
183 } 188 }
@@ -437,7 +442,7 @@ int
437remote_connect(char *host, char *port, struct addrinfo hints) 442remote_connect(char *host, char *port, struct addrinfo hints)
438{ 443{
439 struct addrinfo *res, *res0; 444 struct addrinfo *res, *res0;
440 int s, error; 445 int s, error, x = 1;
441 446
442 if ((error = getaddrinfo(host, port, &hints, &res))) 447 if ((error = getaddrinfo(host, port, &hints, &res)))
443 errx(1, "getaddrinfo: %s", gai_strerror(error)); 448 errx(1, "getaddrinfo: %s", gai_strerror(error));
@@ -472,6 +477,11 @@ remote_connect(char *host, char *port, struct addrinfo hints)
472 errx(1, "bind failed: %s", strerror(errno)); 477 errx(1, "bind failed: %s", strerror(errno));
473 freeaddrinfo(ares); 478 freeaddrinfo(ares);
474 } 479 }
480 if (Sflag) {
481 if (setsockopt(s, IPPROTO_TCP, TCP_SIGNATURE_ENABLE,
482 &x, sizeof(x)) == -1)
483 err(1, NULL);
484 }
475 485
476 if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) 486 if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0)
477 break; 487 break;
@@ -519,6 +529,12 @@ local_listen(char *host, char *port, struct addrinfo hints)
519 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); 529 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
520 if (ret == -1) 530 if (ret == -1)
521 err(1, NULL); 531 err(1, NULL);
532 if (Sflag) {
533 ret = setsockopt(s, IPPROTO_TCP, TCP_SIGNATURE_ENABLE,
534 &x, sizeof(x));
535 if (ret == -1)
536 err(1, NULL);
537 }
522 538
523 if (bind(s, (struct sockaddr *)res0->ai_addr, 539 if (bind(s, (struct sockaddr *)res0->ai_addr,
524 res0->ai_addrlen) == 0) 540 res0->ai_addrlen) == 0)
@@ -730,6 +746,7 @@ help(void)
730 fprintf(stderr, "\tCommand Summary:\n\ 746 fprintf(stderr, "\tCommand Summary:\n\
731 \t-4 Use IPv4\n\ 747 \t-4 Use IPv4\n\
732 \t-6 Use IPv6\n\ 748 \t-6 Use IPv6\n\
749 \t-S Enable the TCP MD5 signature option\n\
733 \t-U Use UNIX domain socket\n\ 750 \t-U Use UNIX domain socket\n\
734 \t-X vers\t SOCKS version (4 or 5)\n\ 751 \t-X vers\t SOCKS version (4 or 5)\n\
735 \t-h This help text\n\ 752 \t-h This help text\n\
@@ -753,7 +770,7 @@ help(void)
753void 770void
754usage(int ret) 771usage(int ret)
755{ 772{
756 fprintf(stderr, "usage: nc [-46Uhklnrtuvz] [-i interval] [-p source port]\n"); 773 fprintf(stderr, "usage: nc [-46SUhklnrtuvz] [-i interval] [-p source port]\n");
757 fprintf(stderr, "\t [-s ip address] [-w timeout] [-X vers] [-x proxy address [:port]]\n"); 774 fprintf(stderr, "\t [-s ip address] [-w timeout] [-X vers] [-x proxy address [:port]]\n");
758 fprintf(stderr, "\t [hostname] [port[s...]]\n"); 775 fprintf(stderr, "\t [hostname] [port[s...]]\n");
759 if (ret) 776 if (ret)