Deleted Added
sdiff udiff text old ( 206689 ) new ( 214047 )
full compact
1/* $OpenBSD: netcat.c,v 1.95 2010/02/27 00:58:56 nicm Exp $ */
2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright

--- 10 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/contrib/netcat/netcat.c 206689 2010-04-15 23:21:24Z delphij $
29 */
30
31/*
32 * Re-written nc(1) for OpenBSD. Original implementation by
33 * *Hobbit* <hobbit@avian.org>.
34 */
35
36#include <sys/limits.h>

--- 51 unchanged lines hidden (view full) ---

88int vflag; /* Verbosity */
89int xflag; /* Socks proxy */
90int zflag; /* Port Scan Flag */
91int Dflag; /* sodebug */
92int Iflag; /* TCP receive buffer size */
93int Oflag; /* TCP send buffer size */
94int Sflag; /* TCP MD5 signature option */
95int Tflag = -1; /* IP Type of Service */
96u_int rdomain;
97
98int timeout = -1;
99int family = AF_UNSPEC;
100char *portlist[PORT_MAX+1];
101
102void atelnet(int, unsigned char *, unsigned int);
103void build_ports(char *);
104void help(void);

--- 29 unchanged lines hidden (view full) ---

134 char *proxy;
135 const char *errstr, *proxyhost = "", *proxyport = NULL;
136 struct addrinfo proxyhints;
137 struct option longopts[] = {
138 { "no-tcpopt", no_argument, &FreeBSD_Oflag, 1 },
139 { NULL, 0, NULL, 0 }
140 };
141
142 rdomain = 0;
143 ret = 1;
144 ipsec_count = 0;
145 s = 0;
146 socksv = 5;
147 host = NULL;
148 uport = NULL;
149 sv = NULL;
150

--- 79 unchanged lines hidden (view full) ---

230 tflag = 1;
231 break;
232 case 'u':
233 uflag = 1;
234 break;
235 case 'V':
236 if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1)
237 errx(1, "Multiple FIBS not supported");
238 rdomain = (unsigned int)strtonum(optarg, 0,
239 numfibs - 1, &errstr);
240 if (errstr)
241 errx(1, "FIB %s: %s", errstr, optarg);
242 break;
243 case 'v':
244 vflag = 1;
245 break;
246 case 'w':
247 timeout = strtonum(optarg, 0, INT_MAX / 1000, &errstr);
248 if (errstr)
249 errx(1, "timeout %s: %s", errstr, optarg);

--- 116 unchanged lines hidden (view full) ---

366 err(1, NULL);
367 /*
368 * For UDP, we will use recvfrom() initially
369 * to wait for a caller, then use the regular
370 * functions to talk to the caller.
371 */
372 if (uflag) {
373 int rv, plen;
374 char buf[8192];
375 struct sockaddr_storage z;
376
377 len = sizeof(z);
378 plen = jflag ? 8192 : 1024;
379 rv = recvfrom(s, buf, plen, MSG_PEEK,
380 (struct sockaddr *)&z, &len);
381 if (rv < 0)
382 err(1, "recvfrom");
383
384 rv = connect(s, (struct sockaddr *)&z, len);
385 if (rv < 0)
386 err(1, "connect");

--- 169 unchanged lines hidden (view full) ---

556 continue;
557#ifdef IPSEC
558 if (ipsec_policy[0] != NULL)
559 add_ipsec_policy(s, ipsec_policy[0]);
560 if (ipsec_policy[1] != NULL)
561 add_ipsec_policy(s, ipsec_policy[1]);
562#endif
563
564 if (rdomain) {
565 if (setfib(rdomain) == -1)
566 err(1, "setfib");
567 }
568
569 /* Bind to a local port or source address if specified. */
570 if (sflag || pflag) {
571 struct addrinfo ahints, *ares;
572
573 /* try IP_BINDANY, but don't insist */

--- 55 unchanged lines hidden (view full) ---

629 errx(1, "getaddrinfo: %s", gai_strerror(error));
630
631 res0 = res;
632 do {
633 if ((s = socket(res0->ai_family, res0->ai_socktype,
634 res0->ai_protocol)) < 0)
635 continue;
636
637 if (rdomain) {
638 if (setfib(rdomain) == -1)
639 err(1, "setfib");
640 }
641
642 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
643 if (ret == -1)
644 err(1, NULL);
645#ifdef IPSEC
646 if (ipsec_policy[0] != NULL)

--- 28 unchanged lines hidden (view full) ---

675/*
676 * readwrite()
677 * Loop that polls on the network file descriptor and stdin.
678 */
679void
680readwrite(int nfd)
681{
682 struct pollfd pfd[2];
683 unsigned char buf[8192];
684 int n, wfd = fileno(stdin);
685 int lfd = fileno(stdout);
686 int plen;
687
688 plen = jflag ? 8192 : 1024;
689
690 /* Setup Network FD */
691 pfd[0].fd = nfd;
692 pfd[0].events = POLLIN;
693
694 /* Set up STDIN FD. */
695 pfd[1].fd = wfd;
696 pfd[1].events = POLLIN;

--- 125 unchanged lines hidden (view full) ---

822 portlist[x] = portlist[y];
823 portlist[y] = c;
824 }
825 }
826 } else {
827 hi = strtonum(p, 1, PORT_MAX, &errstr);
828 if (errstr)
829 errx(1, "port number %s: %s", errstr, p);
830 portlist[0] = calloc(1, PORT_MAX_LEN);
831 if (portlist[0] == NULL)
832 err(1, NULL);
833 portlist[0] = p;
834 }
835}
836
837/*
838 * udptest()
839 * Do a few writes to see if the UDP port is there.
840 * XXX - Better way of doing this? Doesn't work for IPv6.
841 * Also fails after around 100 ports checked.

--- 100 unchanged lines hidden (view full) ---

942 \t-p port\t Specify local port for remote connects\n\
943 \t-r Randomize remote ports\n\
944 \t-S Enable the TCP MD5 signature option\n\
945 \t-s addr\t Local source address\n\
946 \t-T ToS\t Set IP Type of Service\n\
947 \t-t Answer TELNET negotiation\n\
948 \t-U Use UNIX domain socket\n\
949 \t-u UDP mode\n\
950 \t-V fib Specify alternate routing table (FIB)\n\
951 \t-v Verbose\n\
952 \t-w secs\t Timeout for connects and final net reads\n\
953 \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\
954 \t-x addr[:port]\tSpecify proxy address and port\n\
955 \t-z Zero-I/O mode [used for scanning]\n\
956 Port numbers can be individual or ranges: lo-hi [inclusive]\n");
957#ifdef IPSEC
958 fprintf(stderr, "See ipsec_set_policy(3) for -e argument format\n");

--- 28 unchanged lines hidden (view full) ---

987{
988 fprintf(stderr,
989#ifdef IPSEC
990 "usage: nc [-46DdEhklnrStUuvz] [-e policy] [-I length] [-i interval] [-O length]\n"
991#else
992 "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n"
993#endif
994 "\t [-P proxy_username] [-p source_port] [-s source_ip_address] [-T ToS]\n"
995 "\t [-V fib] [-w timeout] [-X proxy_protocol]\n"
996 "\t [-x proxy_address[:port]] [hostname] [port]\n");
997 if (ret)
998 exit(1);
999}