1 /* $OpenBSD: netcat.c,v 1.105 2012/02/09 06:25:35 lum 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 jflag; /* use jumbo frames if we can */
79 int kflag; /* More than one connect */
80 int lflag; /* Bind to local port */
81 int nflag; /* Don't do name look up */
82 int FreeBSD_Oflag; /* Do not use TCP options */
83 char *Pflag; /* Proxy username */
84 char *pflag; /* Localport flag */
85 int rflag; /* Random ports flag */
86 char *sflag; /* Source Address */
87 int tflag; /* Telnet Emulation */
88 int uflag; /* UDP - Default to TCP */
89 int vflag; /* Verbosity */
90 int xflag; /* Socks proxy */
91 int zflag; /* Port Scan Flag */
92 int Dflag; /* sodebug */
93 int Iflag; /* TCP receive buffer size */
94 int Oflag; /* TCP send buffer size */
95 int Sflag; /* TCP MD5 signature option */
96 int Tflag = -1; /* IP Type of Service */
100 int family = AF_UNSPEC;
101 char *portlist[PORT_MAX+1];
102 char *unix_dg_tmp_socket;
104 void atelnet(int, unsigned char *, unsigned int);
105 void build_ports(char *);
107 int local_listen(char *, char *, struct addrinfo);
109 int remote_connect(const char *, const char *, struct addrinfo);
110 int timeout_connect(int, const struct sockaddr *, socklen_t);
111 int socks_connect(const char *, const char *, struct addrinfo,
112 const char *, const char *, struct addrinfo, int, const char *);
114 int unix_bind(char *);
115 int unix_connect(char *);
116 int unix_listen(char *);
117 void set_common_sockopts(int);
118 int map_tos(char *, int *);
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:jklnoO: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);
219 fprintf(stderr, "option -o is deprecated.\n");
240 if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1)
241 errx(1, "Multiple FIBS not supported");
242 rtableid = (unsigned int)strtonum(optarg, 0,
243 numfibs - 1, &errstr);
245 errx(1, "rtable %s: %s", errstr, optarg);
251 timeout = strtonum(optarg, 0, INT_MAX / 1000, &errstr);
253 errx(1, "timeout %s: %s", errstr, optarg);
258 if ((proxy = strdup(optarg)) == NULL)
268 Iflag = strtonum(optarg, 1, 65536 << 14, &errstr);
270 errx(1, "TCP receive window %s: %s",
274 Oflag = strtonum(optarg, 1, 65536 << 14, &errstr);
275 if (errstr != NULL) {
276 if (strcmp(errstr, "invalid") != 0)
277 errx(1, "TCP send window %s: %s",
287 if (map_tos(optarg, &Tflag))
289 if (strlen(optarg) > 1 && optarg[0] == '0' &&
291 Tflag = (int)strtol(optarg, NULL, 16);
293 Tflag = (int)strtonum(optarg, 0, 255,
295 if (Tflag < 0 || Tflag > 255 || errstr || errno)
296 errx(1, "illegal tos value %s", optarg);
305 /* Cruft to make sure options are clean, and used properly. */
306 if (argv[0] && !argv[1] && family == AF_UNIX) {
309 } else if (argv[0] && !argv[1]) {
314 } else if (argv[0] && argv[1]) {
321 errx(1, "cannot use -s and -l");
323 errx(1, "cannot use -p and -l");
325 errx(1, "cannot use -z and -l");
327 errx(1, "must use -l with -k");
329 /* Get name of temporary socket for unix datagram client */
330 if ((family == AF_UNIX) && uflag && !lflag) {
332 unix_dg_tmp_socket = sflag;
334 strlcpy(unix_dg_tmp_socket_buf, "/tmp/nc.XXXXXXXXXX",
335 UNIX_DG_TMP_SOCKET_SIZE);
336 if (mktemp(unix_dg_tmp_socket_buf) == NULL)
338 unix_dg_tmp_socket = unix_dg_tmp_socket_buf;
342 /* Initialize addrinfo structure. */
343 if (family != AF_UNIX) {
344 memset(&hints, 0, sizeof(struct addrinfo));
345 hints.ai_family = family;
346 hints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
347 hints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
349 hints.ai_flags |= AI_NUMERICHOST;
354 errx(1, "no proxy support for UDP mode");
357 errx(1, "no proxy support for listen");
359 if (family == AF_UNIX)
360 errx(1, "no proxy support for unix sockets");
362 /* XXX IPv6 transport to proxy would probably work */
363 if (family == AF_INET6)
364 errx(1, "no proxy support for IPv6");
367 errx(1, "no proxy support for local source address");
369 proxyhost = strsep(&proxy, ":");
372 memset(&proxyhints, 0, sizeof(struct addrinfo));
373 proxyhints.ai_family = family;
374 proxyhints.ai_socktype = SOCK_STREAM;
375 proxyhints.ai_protocol = IPPROTO_TCP;
377 proxyhints.ai_flags |= AI_NUMERICHOST;
384 if (family == AF_UNIX) {
388 s = unix_listen(host);
391 /* Allow only one connection at a time, but stay alive. */
393 if (family != AF_UNIX)
394 s = local_listen(host, uport, hints);
398 * For UDP, we will use recvfrom() initially
399 * to wait for a caller, then use the regular
400 * functions to talk to the caller.
405 struct sockaddr_storage z;
408 plen = jflag ? 16384 : 2048;
409 rv = recvfrom(s, buf, plen, MSG_PEEK,
410 (struct sockaddr *)&z, &len);
414 rv = connect(s, (struct sockaddr *)&z, len);
420 len = sizeof(cliaddr);
421 connfd = accept(s, (struct sockaddr *)&cliaddr,
427 if (family != AF_UNIX)
430 if (connect(s, NULL, 0) < 0)
437 } else if (family == AF_UNIX) {
440 if ((s = unix_connect(host)) > 0 && !zflag) {
447 unlink(unix_dg_tmp_socket);
453 /* Construct the portlist[] array. */
456 /* Cycle through portlist, connecting to each port. */
457 for (i = 0; portlist[i] != NULL; i++) {
462 s = socks_connect(host, portlist[i], hints,
463 proxyhost, proxyport, proxyhints, socksv,
466 s = remote_connect(host, portlist[i], hints);
472 if (vflag || zflag) {
473 /* For UDP, make sure we are connected. */
475 if (udptest(s) == -1) {
481 /* Don't look up port if -n. */
486 ntohs(atoi(portlist[i])),
487 uflag ? "udp" : "tcp");
491 "Connection to %s %s port [%s/%s] "
492 "succeeded!\n", host, portlist[i],
493 uflag ? "udp" : "tcp",
494 sv ? sv->s_name : "*");
509 * Returns a unix socket bound to the given path
512 unix_bind(char *path)
514 struct sockaddr_un sun;
517 /* Create unix domain socket. */
518 if ((s = socket(AF_UNIX, uflag ? SOCK_DGRAM : SOCK_STREAM,
522 memset(&sun, 0, sizeof(struct sockaddr_un));
523 sun.sun_family = AF_UNIX;
525 if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
526 sizeof(sun.sun_path)) {
528 errno = ENAMETOOLONG;
532 if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
541 * Returns a socket connected to a local unix socket. Returns -1 on failure.
544 unix_connect(char *path)
546 struct sockaddr_un sun;
550 if ((s = unix_bind(unix_dg_tmp_socket)) < 0)
553 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
556 (void)fcntl(s, F_SETFD, 1);
558 memset(&sun, 0, sizeof(struct sockaddr_un));
559 sun.sun_family = AF_UNIX;
561 if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
562 sizeof(sun.sun_path)) {
564 errno = ENAMETOOLONG;
567 if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
577 * Create a unix domain socket, and listen on it.
580 unix_listen(char *path)
583 if ((s = unix_bind(path)) < 0)
586 if (listen(s, 5) < 0) {
595 * Returns a socket connected to a remote host. Properly binds to a local
596 * port or source address if needed. Returns -1 on failure.
599 remote_connect(const char *host, const char *port, struct addrinfo hints)
601 struct addrinfo *res, *res0;
602 int s, error, on = 1;
604 if ((error = getaddrinfo(host, port, &hints, &res)))
605 errx(1, "getaddrinfo: %s", gai_strerror(error));
609 if ((s = socket(res0->ai_family, res0->ai_socktype,
610 res0->ai_protocol)) < 0)
613 if (ipsec_policy[0] != NULL)
614 add_ipsec_policy(s, ipsec_policy[0]);
615 if (ipsec_policy[1] != NULL)
616 add_ipsec_policy(s, ipsec_policy[1]);
620 if (setsockopt(s, SOL_SOCKET, SO_SETFIB, &rtableid,
621 sizeof(rtableid)) == -1)
622 err(1, "setsockopt(.., SO_SETFIB, %u, ..)",
626 /* Bind to a local port or source address if specified. */
627 if (sflag || pflag) {
628 struct addrinfo ahints, *ares;
630 /* try IP_BINDANY, but don't insist */
631 setsockopt(s, IPPROTO_IP, IP_BINDANY, &on, sizeof(on));
632 memset(&ahints, 0, sizeof(struct addrinfo));
633 ahints.ai_family = res0->ai_family;
634 ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
635 ahints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP;
636 ahints.ai_flags = AI_PASSIVE;
637 if ((error = getaddrinfo(sflag, pflag, &ahints, &ares)))
638 errx(1, "getaddrinfo: %s", gai_strerror(error));
640 if (bind(s, (struct sockaddr *)ares->ai_addr,
641 ares->ai_addrlen) < 0)
642 errx(1, "bind failed: %s", strerror(errno));
646 set_common_sockopts(s);
648 if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == 0)
651 warn("connect to %s port %s (%s) failed", host, port,
652 uflag ? "udp" : "tcp");
656 } while ((res0 = res0->ai_next) != NULL);
664 timeout_connect(int s, const struct sockaddr *name, socklen_t namelen)
672 flags = fcntl(s, F_GETFL, 0);
673 if (fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
674 err(1, "set non-blocking mode");
677 if ((ret = connect(s, name, namelen)) != 0 && errno == EINPROGRESS) {
679 pfd.events = POLLOUT;
680 if ((ret = poll(&pfd, 1, timeout)) == 1) {
681 optlen = sizeof(optval);
682 if ((ret = getsockopt(s, SOL_SOCKET, SO_ERROR,
683 &optval, &optlen)) == 0) {
685 ret = optval == 0 ? 0 : -1;
687 } else if (ret == 0) {
691 err(1, "poll failed");
694 if (timeout != -1 && fcntl(s, F_SETFL, flags) == -1)
695 err(1, "restoring flags");
702 * Returns a socket listening on a local port, binds to specified source
703 * address. Returns -1 on failure.
706 local_listen(char *host, char *port, struct addrinfo hints)
708 struct addrinfo *res, *res0;
712 /* Allow nodename to be null. */
713 hints.ai_flags |= AI_PASSIVE;
716 * In the case of binding to a wildcard address
717 * default to binding to an ipv4 address.
719 if (host == NULL && hints.ai_family == AF_UNSPEC)
720 hints.ai_family = AF_INET;
722 if ((error = getaddrinfo(host, port, &hints, &res)))
723 errx(1, "getaddrinfo: %s", gai_strerror(error));
727 if ((s = socket(res0->ai_family, res0->ai_socktype,
728 res0->ai_protocol)) < 0)
732 ret = setsockopt(s, SOL_SOCKET, SO_SETFIB, &rtableid,
735 err(1, "setsockopt(.., SO_SETFIB, %u, ..)",
739 ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
743 if (ipsec_policy[0] != NULL)
744 add_ipsec_policy(s, ipsec_policy[0]);
745 if (ipsec_policy[1] != NULL)
746 add_ipsec_policy(s, ipsec_policy[1]);
749 if (setsockopt(s, IPPROTO_TCP, TCP_NOOPT,
750 &FreeBSD_Oflag, sizeof(FreeBSD_Oflag)) == -1)
751 err(1, "disable TCP options");
754 if (bind(s, (struct sockaddr *)res0->ai_addr,
755 res0->ai_addrlen) == 0)
760 } while ((res0 = res0->ai_next) != NULL);
762 if (!uflag && s != -1) {
763 if (listen(s, 1) < 0)
774 * Loop that polls on the network file descriptor and stdin.
779 struct pollfd pfd[2];
780 unsigned char buf[16384];
781 int n, wfd = fileno(stdin);
782 int lfd = fileno(stdout);
785 plen = jflag ? 16384 : 2048;
787 /* Setup Network FD */
789 pfd[0].events = POLLIN;
791 /* Set up STDIN FD. */
793 pfd[1].events = POLLIN;
795 while (pfd[0].fd != -1) {
799 if ((n = poll(pfd, 2 - dflag, timeout)) < 0) {
801 err(1, "Polling Error");
807 if (pfd[0].revents & POLLIN) {
808 if ((n = read(nfd, buf, plen)) < 0)
811 shutdown(nfd, SHUT_RD);
816 atelnet(nfd, buf, n);
817 if (atomicio(vwrite, lfd, buf, n) != n)
822 if (!dflag && pfd[1].revents & POLLIN) {
823 if ((n = read(wfd, buf, plen)) < 0)
826 shutdown(nfd, SHUT_WR);
830 if (atomicio(vwrite, nfd, buf, n) != n)
837 /* Deal with RFC 854 WILL/WONT DO/DONT negotiation. */
839 atelnet(int nfd, unsigned char *buf, unsigned int size)
841 unsigned char *p, *end;
842 unsigned char obuf[4];
846 end = buf + size - 2;
848 for (p = buf; p < end; p++) {
854 if ((*p == WILL) || (*p == WONT))
856 else if ((*p == DO) || (*p == DONT))
863 if (atomicio(vwrite, nfd, obuf, 3) != 3)
864 warn("Write Error!");
870 * Build an array of ports in portlist[], listing each port
871 * that we should try to connect to.
881 if ((n = strchr(p, '-')) != NULL) {
885 /* Make sure the ports are in order: lowest->highest. */
886 hi = strtonum(n, 1, PORT_MAX, &errstr);
888 errx(1, "port number %s: %s", errstr, n);
889 lo = strtonum(p, 1, PORT_MAX, &errstr);
891 errx(1, "port number %s: %s", errstr, p);
899 /* Load ports sequentially. */
900 for (cp = lo; cp <= hi; cp++) {
901 portlist[x] = calloc(1, PORT_MAX_LEN);
902 if (portlist[x] == NULL)
904 snprintf(portlist[x], PORT_MAX_LEN, "%d", cp);
908 /* Randomly swap ports. */
913 for (x = 0; x <= (hi - lo); x++) {
914 y = (arc4random() & 0xFFFF) % (hi - lo);
916 portlist[x] = portlist[y];
921 hi = strtonum(p, 1, PORT_MAX, &errstr);
923 errx(1, "port number %s: %s", errstr, p);
924 portlist[0] = strdup(p);
925 if (portlist[0] == NULL)
932 * Do a few writes to see if the UDP port is there.
933 * Fails once PF state table is full.
940 for (i = 0; i <= 3; i++) {
941 if (write(s, "X", 1) == 1)
950 set_common_sockopts(int s)
955 if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
956 &x, sizeof(x)) == -1)
960 if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
961 &x, sizeof(x)) == -1)
966 if (setsockopt(s, SOL_SOCKET, SO_JUMBO,
967 &x, sizeof(x)) == -1)
972 if (setsockopt(s, IPPROTO_IP, IP_TOS,
973 &Tflag, sizeof(Tflag)) == -1)
974 err(1, "set IP ToS");
977 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
978 &Iflag, sizeof(Iflag)) == -1)
979 err(1, "set TCP receive buffer size");
982 if (setsockopt(s, SOL_SOCKET, SO_SNDBUF,
983 &Oflag, sizeof(Oflag)) == -1)
984 err(1, "set TCP send buffer size");
987 if (setsockopt(s, IPPROTO_TCP, TCP_NOOPT,
988 &FreeBSD_Oflag, sizeof(FreeBSD_Oflag)) == -1)
989 err(1, "disable TCP options");
994 map_tos(char *s, int *val)
996 /* DiffServ Codepoints and other TOS mappings */
997 const struct toskeywords {
1000 } *t, toskeywords[] = {
1001 { "af11", IPTOS_DSCP_AF11 },
1002 { "af12", IPTOS_DSCP_AF12 },
1003 { "af13", IPTOS_DSCP_AF13 },
1004 { "af21", IPTOS_DSCP_AF21 },
1005 { "af22", IPTOS_DSCP_AF22 },
1006 { "af23", IPTOS_DSCP_AF23 },
1007 { "af31", IPTOS_DSCP_AF31 },
1008 { "af32", IPTOS_DSCP_AF32 },
1009 { "af33", IPTOS_DSCP_AF33 },
1010 { "af41", IPTOS_DSCP_AF41 },
1011 { "af42", IPTOS_DSCP_AF42 },
1012 { "af43", IPTOS_DSCP_AF43 },
1013 { "critical", IPTOS_PREC_CRITIC_ECP },
1014 { "cs0", IPTOS_DSCP_CS0 },
1015 { "cs1", IPTOS_DSCP_CS1 },
1016 { "cs2", IPTOS_DSCP_CS2 },
1017 { "cs3", IPTOS_DSCP_CS3 },
1018 { "cs4", IPTOS_DSCP_CS4 },
1019 { "cs5", IPTOS_DSCP_CS5 },
1020 { "cs6", IPTOS_DSCP_CS6 },
1021 { "cs7", IPTOS_DSCP_CS7 },
1022 { "ef", IPTOS_DSCP_EF },
1023 { "inetcontrol", IPTOS_PREC_INTERNETCONTROL },
1024 { "lowdelay", IPTOS_LOWDELAY },
1025 { "netcontrol", IPTOS_PREC_NETCONTROL },
1026 { "reliability", IPTOS_RELIABILITY },
1027 { "throughput", IPTOS_THROUGHPUT },
1031 for (t = toskeywords; t->keyword != NULL; t++) {
1032 if (strcmp(s, t->keyword) == 0) {
1045 fprintf(stderr, "\tCommand Summary:\n\
1048 \t-D Enable the debug socket option\n\
1049 \t-d Detach from stdin\n");
1052 \t-E Use IPsec ESP\n\
1053 \t-e policy Use specified IPsec policy\n");
1056 \t-h This help text\n\
1057 \t-I length TCP receive buffer length\n\
1058 \t-i secs\t Delay interval for lines sent, ports scanned\n\
1059 \t-k Keep inbound sockets open for multiple connects\n\
1060 \t-l Listen mode, for inbound connects\n\
1061 \t-n Suppress name/port resolutions\n\
1062 \t--no-tcpopt Disable TCP options\n\
1063 \t-O length TCP send buffer length\n\
1064 \t-P proxyuser\tUsername for proxy authentication\n\
1065 \t-p port\t Specify local port for remote connects\n\
1066 \t-r Randomize remote ports\n\
1067 \t-S Enable the TCP MD5 signature option\n\
1068 \t-s addr\t Local source address\n\
1069 \t-T toskeyword\tSet IP Type of Service\n\
1070 \t-t Answer TELNET negotiation\n\
1071 \t-U Use UNIX domain socket\n\
1073 \t-V rtable Specify alternate routing table\n\
1075 \t-w secs\t Timeout for connects and final net reads\n\
1076 \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\
1077 \t-x addr[:port]\tSpecify proxy address and port\n\
1078 \t-z Zero-I/O mode [used for scanning]\n\
1079 Port numbers can be individual or ranges: lo-hi [inclusive]\n");
1081 fprintf(stderr, "See ipsec_set_policy(3) for -e argument format\n");
1088 add_ipsec_policy(int s, char *policy)
1093 raw = ipsec_set_policy(policy, strlen(policy));
1095 errx(1, "ipsec_set_policy `%s': %s", policy,
1097 e = setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY, raw,
1098 ipsec_get_policylen(raw));
1100 err(1, "ipsec policy cannot be configured");
1103 fprintf(stderr, "ipsec policy configured: `%s'\n", policy);
1113 "usage: nc [-46DdEhklnrStUuvz] [-e policy] [-I length] [-i interval] [-O length]\n"
1115 "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n"
1117 "\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n"
1118 "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
1119 "\t [-x proxy_address[:port]] [destination] [port]\n");