1 /* $OpenBSD: netcat.c,v 1.109 2012/07/07 15:33:02 haesbaert Exp $ */
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
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.
32 * Re-written nc(1) for OpenBSD. Original implementation by
33 * *Hobbit* <hobbit@avian.org>.
36 #include <sys/limits.h>
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <sys/sysctl.h>
43 #include <netinet/in.h>
44 #include <netinet/in_systm.h>
46 #include <netipsec/ipsec.h>
48 #include <netinet/tcp.h>
49 #include <netinet/ip.h>
50 #include <arpa/telnet.h>
68 (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
71 #define PORT_MAX 65535
72 #define PORT_MAX_LEN 6
73 #define UNIX_DG_TMP_SOCKET_SIZE 19
75 /* Command Line Options */
76 int dflag; /* detached, no stdin */
77 unsigned int iflag; /* Interval Flag */
78 int kflag; /* More than one connect */
79 int lflag; /* Bind to local port */
80 int nflag; /* Don't do name look up */
81 int FreeBSD_Oflag; /* Do not use TCP options */
82 char *Pflag; /* Proxy username */
83 char *pflag; /* Localport flag */
84 int rflag; /* Random ports flag */
85 char *sflag; /* Source Address */
86 int tflag; /* Telnet Emulation */
87 int uflag; /* UDP - Default to TCP */
88 int vflag; /* Verbosity */
89 int xflag; /* Socks proxy */
90 int zflag; /* Port Scan Flag */
91 int Dflag; /* sodebug */
92 int Iflag; /* TCP receive buffer size */
93 int Oflag; /* TCP send buffer size */
94 int Sflag; /* TCP MD5 signature option */
95 int Tflag = -1; /* IP Type of Service */
99 int family = AF_UNSPEC;
100 char *portlist[PORT_MAX+1];
101 char *unix_dg_tmp_socket;
103 void atelnet(int, unsigned char *, unsigned int);
104 void build_ports(char *);
106 int local_listen(char *, char *, struct addrinfo);
108 int remote_connect(const char *, const char *, struct addrinfo);
109 int timeout_connect(int, const struct sockaddr *, socklen_t);
110 int socks_connect(const char *, const char *, struct addrinfo,
111 const char *, const char *, struct addrinfo, int, const char *);
113 int unix_bind(char *);
114 int unix_connect(char *);
115 int unix_listen(char *);
116 void set_common_sockopts(int);
117 int map_tos(char *, int *);
118 void report_connect(const struct sockaddr *, socklen_t);
122 void add_ipsec_policy(int, char *);
124 char *ipsec_policy[2];
128 main(int argc, char *argv[])
130 int ch, s, ret, socksv, ipsec_count;
132 size_t intsize = sizeof(int);
134 struct addrinfo hints;
137 struct sockaddr_storage cliaddr;
139 const char *errstr, *proxyhost = "", *proxyport = NULL;
140 struct addrinfo proxyhints;
141 char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE];
142 struct option longopts[] = {
143 { "no-tcpopt", no_argument, &FreeBSD_Oflag, 1 },
155 while ((ch = getopt_long(argc, argv,
156 "46DdEe:hI:i:klnoO:P:p:rSs:tT:UuV:vw:X:x:z",
157 longopts, NULL)) != -1) {
169 if (strcasecmp(optarg, "connect") == 0)
170 socksv = -1; /* HTTP proxy CONNECT */
171 else if (strcmp(optarg, "4") == 0)
172 socksv = 4; /* SOCKS v.4 */
173 else if (strcmp(optarg, "5") == 0)
174 socksv = 5; /* SOCKS v.5 */
176 errx(1, "unsupported proxy protocol");
183 ipsec_policy[ipsec_count++ % 2] = optarg;
185 errx(1, "IPsec support unavailable.");
190 ipsec_policy[0] = "in ipsec esp/transport//require";
191 ipsec_policy[1] = "out ipsec esp/transport//require";
193 errx(1, "IPsec support unavailable.");
200 iflag = strtonum(optarg, 0, UINT_MAX, &errstr);
202 errx(1, "interval %s: %s", errstr, optarg);
214 fprintf(stderr, "option -o is deprecated.\n");
235 if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1)
236 errx(1, "Multiple FIBS not supported");
237 rtableid = (unsigned int)strtonum(optarg, 0,
238 numfibs - 1, &errstr);
240 errx(1, "rtable %s: %s", errstr, optarg);
246 timeout = strtonum(optarg, 0, INT_MAX / 1000, &errstr);
248 errx(1, "timeout %s: %s", errstr, optarg);
253 if ((proxy = strdup(optarg)) == NULL)
263 Iflag = strtonum(optarg, 1, 65536 << 14, &errstr);
265 errx(1, "TCP receive window %s: %s",
269 Oflag = strtonum(optarg, 1, 65536 << 14, &errstr);
270 if (errstr != NULL) {
271 if (strcmp(errstr, "invalid") != 0)
272 errx(1, "TCP send window %s: %s",
282 if (map_tos(optarg, &Tflag))
284 if (strlen(optarg) > 1 && optarg[0] == '0' &&
286 Tflag = (int)strtol(optarg, NULL, 16);
288 Tflag = (int)strtonum(optarg, 0, 255,
290 if (Tflag < 0 || Tflag > 255 || errstr || errno)
291 errx(1, "illegal tos value %s", optarg);
300 /* Cruft to make sure options are clean, and used properly. */
301 if (argv[0] && !argv[1] && family == AF_UNIX) {
304 } else if (argv[0] && !argv[1]) {
309 } else if (argv[0] && argv[1]) {
316 errx(1, "cannot use -s and -l");
318 errx(1, "cannot use -p and -l");
320 errx(1, "cannot use -z and -l");
322 errx(1, "must use -l with -k");
324 /* Get name of temporary socket for unix datagram client */
325 if ((family == AF_UNIX) && uflag && !lflag) {
327 unix_dg_tmp_socket = sflag;
329 strlcpy(unix_dg_tmp_socket_buf, "/tmp/nc.XXXXXXXXXX",
330 UNIX_DG_TMP_SOCKET_SIZE);
331 if (mktemp(unix_dg_tmp_socket_buf) == NULL)
333 unix_dg_tmp_socket = unix_dg_tmp_socket_buf;
337 /* Initialize addrinfo structure. */
338 if (family != AF_UNIX) {
339 memset(&hints, 0, sizeof(struct addrinfo));
340 hints.ai_family = family;
341 hints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
342 hints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
344 hints.ai_flags |= AI_NUMERICHOST;
349 errx(1, "no proxy support for UDP mode");
352 errx(1, "no proxy support for listen");
354 if (family == AF_UNIX)
355 errx(1, "no proxy support for unix sockets");
357 /* XXX IPv6 transport to proxy would probably work */
358 if (family == AF_INET6)
359 errx(1, "no proxy support for IPv6");
362 errx(1, "no proxy support for local source address");
364 proxyhost = strsep(&proxy, ":");
367 memset(&proxyhints, 0, sizeof(struct addrinfo));
368 proxyhints.ai_family = family;
369 proxyhints.ai_socktype = SOCK_STREAM;
370 proxyhints.ai_protocol = IPPROTO_TCP;
372 proxyhints.ai_flags |= AI_NUMERICHOST;
379 if (family == AF_UNIX) {
383 s = unix_listen(host);
386 /* Allow only one connection at a time, but stay alive. */
388 if (family != AF_UNIX)
389 s = local_listen(host, uport, hints);
393 * For UDP and -k, don't connect the socket, let it
394 * receive datagrams from multiple socket pairs.
399 * For UDP and not -k, we will use recvfrom() initially
400 * to wait for a caller, then use the regular functions
401 * to talk to the caller.
403 else if (uflag && !kflag) {
406 struct sockaddr_storage z;
410 rv = recvfrom(s, buf, plen, MSG_PEEK,
411 (struct sockaddr *)&z, &len);
415 rv = connect(s, (struct sockaddr *)&z, len);
420 report_connect((struct sockaddr *)&z, len);
424 len = sizeof(cliaddr);
425 connfd = accept(s, (struct sockaddr *)&cliaddr,
431 report_connect((struct sockaddr *)&cliaddr, len);
437 if (family != AF_UNIX)
440 if (connect(s, NULL, 0) < 0)
447 } else if (family == AF_UNIX) {
450 if ((s = unix_connect(host)) > 0 && !zflag) {
457 unlink(unix_dg_tmp_socket);
463 /* Construct the portlist[] array. */
466 /* Cycle through portlist, connecting to each port. */
467 for (i = 0; portlist[i] != NULL; i++) {
472 s = socks_connect(host, portlist[i], hints,
473 proxyhost, proxyport, proxyhints, socksv,
476 s = remote_connect(host, portlist[i], hints);
482 if (vflag || zflag) {
483 /* For UDP, make sure we are connected. */
485 if (udptest(s) == -1) {
491 /* Don't look up port if -n. */
496 ntohs(atoi(portlist[i])),
497 uflag ? "udp" : "tcp");
501 "Connection to %s %s port [%s/%s] "
502 "succeeded!\n", host, portlist[i],
503 uflag ? "udp" : "tcp",
504 sv ? sv->s_name : "*");
519 * Returns a unix socket bound to the given path
522 unix_bind(char *path)
524 struct sockaddr_un sun;
527 /* Create unix domain socket. */
528 if ((s = socket(AF_UNIX, uflag ? SOCK_DGRAM : SOCK_STREAM,
532 memset(&sun, 0, sizeof(struct sockaddr_un));
533 sun.sun_family = AF_UNIX;
535 if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
536 sizeof(sun.sun_path)) {
538 errno = ENAMETOOLONG;
542 if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
551 * Returns a socket connected to a local unix socket. Returns -1 on failure.
554 unix_connect(char *path)
556 struct sockaddr_un sun;
560 if ((s = unix_bind(unix_dg_tmp_socket)) < 0)
563 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
566 (void)fcntl(s, F_SETFD, 1);
568 memset(&sun, 0, sizeof(struct sockaddr_un));
569 sun.sun_family = AF_UNIX;
571 if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
572 sizeof(sun.sun_path)) {
574 errno = ENAMETOOLONG;
577 if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
587 * Create a unix domain socket, and listen on it.
590 unix_listen(char *path)
593 if ((s = unix_bind(path)) < 0)
596 if (listen(s, 5) < 0) {
605 * Returns a socket connected to a remote host. Properly binds to a local
606 * port or source address if needed. Returns -1 on failure.
609 remote_connect(const char *host, const char *port, struct addrinfo hints)
611 struct addrinfo *res, *res0;
612 int s, error, on = 1;
614 if ((error = getaddrinfo(host, port, &hints, &res)))
615 errx(1, "getaddrinfo: %s", gai_strerror(error));
619 if ((s = socket(res0->ai_family, res0->ai_socktype,
620 res0->ai_protocol)) < 0)
623 if (ipsec_policy[0] != NULL)
624 add_ipsec_policy(s, ipsec_policy[0]);
625 if (ipsec_policy[1] != NULL)
626 add_ipsec_policy(s, ipsec_policy[1]);
630 if (setsockopt(s, SOL_SOCKET, SO_SETFIB, &rtableid,
631 sizeof(rtableid)) == -1)
632 err(1, "setsockopt(.., SO_SETFIB, %u, ..)",
636 /* Bind to a local port or source address if specified. */
637 if (sflag || pflag) {
638 struct addrinfo ahints, *ares;
640 /* try IP_BINDANY, but don't insist */
641 setsockopt(s, IPPROTO_IP, IP_BINDANY, &on, sizeof(on));
642 memset(&ahints, 0, sizeof(struct addrinfo));
643 ahints.ai_family = res0->ai_family;
644 ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
645 ahints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
646 ahints.ai_flags = AI_PASSIVE;
647 if ((error = getaddrinfo(sflag, pflag, &ahints, &ares)))
648 errx(1, "getaddrinfo: %s", gai_strerror(error));
650 if (bind(s, (struct sockaddr *)ares->ai_addr,
651 ares->ai_addrlen) < 0)
652 errx(1, "bind failed: %s", strerror(errno));
656 set_common_sockopts(s);
658 if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == 0)
661 warn("connect to %s port %s (%s) failed", host, port,
662 uflag ? "udp" : "tcp");
666 } while ((res0 = res0->ai_next) != NULL);
674 timeout_connect(int s, const struct sockaddr *name, socklen_t namelen)
682 flags = fcntl(s, F_GETFL, 0);
683 if (fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
684 err(1, "set non-blocking mode");
687 if ((ret = connect(s, name, namelen)) != 0 && errno == EINPROGRESS) {
689 pfd.events = POLLOUT;
690 if ((ret = poll(&pfd, 1, timeout)) == 1) {
691 optlen = sizeof(optval);
692 if ((ret = getsockopt(s, SOL_SOCKET, SO_ERROR,
693 &optval, &optlen)) == 0) {
695 ret = optval == 0 ? 0 : -1;
697 } else if (ret == 0) {
701 err(1, "poll failed");
704 if (timeout != -1 && fcntl(s, F_SETFL, flags) == -1)
705 err(1, "restoring flags");
712 * Returns a socket listening on a local port, binds to specified source
713 * address. Returns -1 on failure.
716 local_listen(char *host, char *port, struct addrinfo hints)
718 struct addrinfo *res, *res0;
722 /* Allow nodename to be null. */
723 hints.ai_flags |= AI_PASSIVE;
726 * In the case of binding to a wildcard address
727 * default to binding to an ipv4 address.
729 if (host == NULL && hints.ai_family == AF_UNSPEC)
730 hints.ai_family = AF_INET;
732 if ((error = getaddrinfo(host, port, &hints, &res)))
733 errx(1, "getaddrinfo: %s", gai_strerror(error));
737 if ((s = socket(res0->ai_family, res0->ai_socktype,
738 res0->ai_protocol)) < 0)
742 ret = setsockopt(s, SOL_SOCKET, SO_SETFIB, &rtableid,
745 err(1, "setsockopt(.., SO_SETFIB, %u, ..)",
749 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
753 if (ipsec_policy[0] != NULL)
754 add_ipsec_policy(s, ipsec_policy[0]);
755 if (ipsec_policy[1] != NULL)
756 add_ipsec_policy(s, ipsec_policy[1]);
759 if (setsockopt(s, IPPROTO_TCP, TCP_NOOPT,
760 &FreeBSD_Oflag, sizeof(FreeBSD_Oflag)) == -1)
761 err(1, "disable TCP options");
764 if (bind(s, (struct sockaddr *)res0->ai_addr,
765 res0->ai_addrlen) == 0)
770 } while ((res0 = res0->ai_next) != NULL);
772 if (!uflag && s != -1) {
773 if (listen(s, 1) < 0)
784 * Loop that polls on the network file descriptor and stdin.
789 struct pollfd pfd[2];
790 unsigned char buf[16384];
791 int n, wfd = fileno(stdin);
792 int lfd = fileno(stdout);
797 /* Setup Network FD */
799 pfd[0].events = POLLIN;
801 /* Set up STDIN FD. */
803 pfd[1].events = POLLIN;
805 while (pfd[0].fd != -1) {
809 if ((n = poll(pfd, 2 - dflag, timeout)) < 0) {
811 err(1, "Polling Error");
817 if (pfd[0].revents & POLLIN) {
818 if ((n = read(nfd, buf, plen)) < 0)
821 shutdown(nfd, SHUT_RD);
826 atelnet(nfd, buf, n);
827 if (atomicio(vwrite, lfd, buf, n) != n)
832 if (!dflag && pfd[1].revents & POLLIN) {
833 if ((n = read(wfd, buf, plen)) < 0)
836 shutdown(nfd, SHUT_WR);
840 if (atomicio(vwrite, nfd, buf, n) != n)
847 /* Deal with RFC 854 WILL/WONT DO/DONT negotiation. */
849 atelnet(int nfd, unsigned char *buf, unsigned int size)
851 unsigned char *p, *end;
852 unsigned char obuf[4];
856 end = buf + size - 2;
858 for (p = buf; p < end; p++) {
864 if ((*p == WILL) || (*p == WONT))
866 else if ((*p == DO) || (*p == DONT))
873 if (atomicio(vwrite, nfd, obuf, 3) != 3)
874 warn("Write Error!");
880 * Build an array of ports in portlist[], listing each port
881 * that we should try to connect to.
891 if ((n = strchr(p, '-')) != NULL) {
895 /* Make sure the ports are in order: lowest->highest. */
896 hi = strtonum(n, 1, PORT_MAX, &errstr);
898 errx(1, "port number %s: %s", errstr, n);
899 lo = strtonum(p, 1, PORT_MAX, &errstr);
901 errx(1, "port number %s: %s", errstr, p);
909 /* Load ports sequentially. */
910 for (cp = lo; cp <= hi; cp++) {
911 portlist[x] = calloc(1, PORT_MAX_LEN);
912 if (portlist[x] == NULL)
914 snprintf(portlist[x], PORT_MAX_LEN, "%d", cp);
918 /* Randomly swap ports. */
923 for (x = 0; x <= (hi - lo); x++) {
924 y = (arc4random() & 0xFFFF) % (hi - lo);
926 portlist[x] = portlist[y];
931 hi = strtonum(p, 1, PORT_MAX, &errstr);
933 errx(1, "port number %s: %s", errstr, p);
934 portlist[0] = strdup(p);
935 if (portlist[0] == NULL)
942 * Do a few writes to see if the UDP port is there.
943 * Fails once PF state table is full.
950 for (i = 0; i <= 3; i++) {
951 if (write(s, "X", 1) == 1)
960 set_common_sockopts(int s)
965 if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
966 &x, sizeof(x)) == -1)
970 if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
971 &x, sizeof(x)) == -1)
975 if (setsockopt(s, IPPROTO_IP, IP_TOS,
976 &Tflag, sizeof(Tflag)) == -1)
977 err(1, "set IP ToS");
980 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
981 &Iflag, sizeof(Iflag)) == -1)
982 err(1, "set TCP receive buffer size");
985 if (setsockopt(s, SOL_SOCKET, SO_SNDBUF,
986 &Oflag, sizeof(Oflag)) == -1)
987 err(1, "set TCP send buffer size");
990 if (setsockopt(s, IPPROTO_TCP, TCP_NOOPT,
991 &FreeBSD_Oflag, sizeof(FreeBSD_Oflag)) == -1)
992 err(1, "disable TCP options");
997 map_tos(char *s, int *val)
999 /* DiffServ Codepoints and other TOS mappings */
1000 const struct toskeywords {
1001 const char *keyword;
1003 } *t, toskeywords[] = {
1004 { "af11", IPTOS_DSCP_AF11 },
1005 { "af12", IPTOS_DSCP_AF12 },
1006 { "af13", IPTOS_DSCP_AF13 },
1007 { "af21", IPTOS_DSCP_AF21 },
1008 { "af22", IPTOS_DSCP_AF22 },
1009 { "af23", IPTOS_DSCP_AF23 },
1010 { "af31", IPTOS_DSCP_AF31 },
1011 { "af32", IPTOS_DSCP_AF32 },
1012 { "af33", IPTOS_DSCP_AF33 },
1013 { "af41", IPTOS_DSCP_AF41 },
1014 { "af42", IPTOS_DSCP_AF42 },
1015 { "af43", IPTOS_DSCP_AF43 },
1016 { "critical", IPTOS_PREC_CRITIC_ECP },
1017 { "cs0", IPTOS_DSCP_CS0 },
1018 { "cs1", IPTOS_DSCP_CS1 },
1019 { "cs2", IPTOS_DSCP_CS2 },
1020 { "cs3", IPTOS_DSCP_CS3 },
1021 { "cs4", IPTOS_DSCP_CS4 },
1022 { "cs5", IPTOS_DSCP_CS5 },
1023 { "cs6", IPTOS_DSCP_CS6 },
1024 { "cs7", IPTOS_DSCP_CS7 },
1025 { "ef", IPTOS_DSCP_EF },
1026 { "inetcontrol", IPTOS_PREC_INTERNETCONTROL },
1027 { "lowdelay", IPTOS_LOWDELAY },
1028 { "netcontrol", IPTOS_PREC_NETCONTROL },
1029 { "reliability", IPTOS_RELIABILITY },
1030 { "throughput", IPTOS_THROUGHPUT },
1034 for (t = toskeywords; t->keyword != NULL; t++) {
1035 if (strcmp(s, t->keyword) == 0) {
1045 report_connect(const struct sockaddr *sa, socklen_t salen)
1047 char remote_host[NI_MAXHOST];
1048 char remote_port[NI_MAXSERV];
1050 int flags = NI_NUMERICSERV;
1053 flags |= NI_NUMERICHOST;
1055 if ((herr = getnameinfo(sa, salen,
1056 remote_host, sizeof(remote_host),
1057 remote_port, sizeof(remote_port),
1059 if (herr == EAI_SYSTEM)
1060 err(1, "getnameinfo");
1062 errx(1, "getnameinfo: %s", gai_strerror(herr));
1066 "Connection from %s %s "
1067 "received!\n", remote_host, remote_port);
1074 fprintf(stderr, "\tCommand Summary:\n\
1077 \t-D Enable the debug socket option\n\
1078 \t-d Detach from stdin\n");
1081 \t-E Use IPsec ESP\n\
1082 \t-e policy Use specified IPsec policy\n");
1085 \t-h This help text\n\
1086 \t-I length TCP receive buffer length\n\
1087 \t-i secs\t Delay interval for lines sent, ports scanned\n\
1088 \t-k Keep inbound sockets open for multiple connects\n\
1089 \t-l Listen mode, for inbound connects\n\
1090 \t-n Suppress name/port resolutions\n\
1091 \t--no-tcpopt Disable TCP options\n\
1092 \t-O length TCP send buffer length\n\
1093 \t-P proxyuser\tUsername for proxy authentication\n\
1094 \t-p port\t Specify local port for remote connects\n\
1095 \t-r Randomize remote ports\n\
1096 \t-S Enable the TCP MD5 signature option\n\
1097 \t-s addr\t Local source address\n\
1098 \t-T toskeyword\tSet IP Type of Service\n\
1099 \t-t Answer TELNET negotiation\n\
1100 \t-U Use UNIX domain socket\n\
1102 \t-V rtable Specify alternate routing table\n\
1104 \t-w secs\t Timeout for connects and final net reads\n\
1105 \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\
1106 \t-x addr[:port]\tSpecify proxy address and port\n\
1107 \t-z Zero-I/O mode [used for scanning]\n\
1108 Port numbers can be individual or ranges: lo-hi [inclusive]\n");
1110 fprintf(stderr, "See ipsec_set_policy(3) for -e argument format\n");
1117 add_ipsec_policy(int s, char *policy)
1122 raw = ipsec_set_policy(policy, strlen(policy));
1124 errx(1, "ipsec_set_policy `%s': %s", policy,
1126 e = setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY, raw,
1127 ipsec_get_policylen(raw));
1129 err(1, "ipsec policy cannot be configured");
1132 fprintf(stderr, "ipsec policy configured: `%s'\n", policy);
1142 "usage: nc [-46DdEhklnrStUuvz] [-e policy] [-I length] [-i interval] [-O length]\n"
1144 "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n"
1146 "\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n"
1147 "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
1148 "\t [-x proxy_address[:port]] [destination] [port]\n");