svn commit: r205563 - stable/7/contrib/netcat

Xin LI delphij at FreeBSD.org
Tue Mar 23 23:09:39 UTC 2010


Author: delphij
Date: Tue Mar 23 23:09:38 2010
New Revision: 205563
URL: http://svn.freebsd.org/changeset/base/205563

Log:
  MFC: nc from OpenBSD 4.6.

Deleted:
  stable/7/contrib/netcat/FREEBSD-Xlist
  stable/7/contrib/netcat/FREEBSD-upgrade
Modified:
  stable/7/contrib/netcat/atomicio.c   (contents, props changed)
  stable/7/contrib/netcat/atomicio.h   (contents, props changed)
  stable/7/contrib/netcat/nc.1
  stable/7/contrib/netcat/netcat.c
Directory Properties:
  stable/7/contrib/netcat/   (props changed)
  stable/7/contrib/netcat/socks.c   (props changed)

Modified: stable/7/contrib/netcat/atomicio.c
==============================================================================
--- stable/7/contrib/netcat/atomicio.c	Tue Mar 23 23:03:30 2010	(r205562)
+++ stable/7/contrib/netcat/atomicio.c	Tue Mar 23 23:09:38 2010	(r205563)
@@ -1,7 +1,7 @@
-/* $OpenBSD: atomicio.c,v 1.8 2006/02/11 19:31:18 otto Exp $ */
-
+/* $OpenBSD: atomicio.c,v 1.9 2007/09/07 14:50:44 tobias Exp $ */
 /*
- * Copyright (c) 2005 Anil Madhavapeddy.  All rights served.
+ * Copyright (c) 2006 Damien Miller. All rights reserved.
+ * Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
  * Copyright (c) 1995,1999 Theo de Raadt.  All rights reserved.
  * All rights reserved.
  *
@@ -26,32 +26,37 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <sys/types.h>
-#include <sys/uio.h>
+#include <sys/param.h>
+
 #include <errno.h>
+#include <poll.h>
 #include <unistd.h>
+
 #include "atomicio.h"
 
 /*
  * ensure all of data on socket comes through. f==read || f==vwrite
  */
 size_t
-atomicio(f, fd, _s, n)
-	ssize_t (*f) (int, void *, size_t);
-	int fd;
-	void *_s;
-	size_t n;
+atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n)
 {
 	char *s = _s;
 	size_t pos = 0;
 	ssize_t res;
+	struct pollfd pfd;
 
+	pfd.fd = fd;
+	pfd.events = f == read ? POLLIN : POLLOUT;
 	while (n > pos) {
 		res = (f) (fd, s + pos, n - pos);
 		switch (res) {
 		case -1:
-			if (errno == EINTR || errno == EAGAIN)
+			if (errno == EINTR)
+				continue;
+			if (errno == EAGAIN) {
+				(void)poll(&pfd, 1, -1);
 				continue;
+			}
 			return 0;
 		case 0:
 			errno = EPIPE;
@@ -60,5 +65,5 @@ atomicio(f, fd, _s, n)
 			pos += (size_t)res;
 		}
 	}
-	return pos;
+	return (pos);
 }

Modified: stable/7/contrib/netcat/atomicio.h
==============================================================================
--- stable/7/contrib/netcat/atomicio.h	Tue Mar 23 23:03:30 2010	(r205562)
+++ stable/7/contrib/netcat/atomicio.h	Tue Mar 23 23:09:38 2010	(r205563)
@@ -1,6 +1,7 @@
-/*	$OpenBSD: atomicio.h,v 1.1 2005/05/24 20:13:28 avsm Exp $	*/
+/* $OpenBSD: atomicio.h,v 1.2 2007/09/07 14:50:44 tobias Exp $ */
 
 /*
+ * Copyright (c) 2006 Damien Miller.  All rights reserved.
  * Copyright (c) 1995,1999 Theo de Raadt.  All rights reserved.
  * All rights reserved.
  *
@@ -25,9 +26,14 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef _ATOMICIO_H
+#define _ATOMICIO_H
+
 /*
  * Ensure all of data on socket comes through. f==read || f==vwrite
  */
 size_t	atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
 
 #define vwrite (ssize_t (*)(int, void *, size_t))write
+
+#endif /* _ATOMICIO_H */

Modified: stable/7/contrib/netcat/nc.1
==============================================================================
--- stable/7/contrib/netcat/nc.1	Tue Mar 23 23:03:30 2010	(r205562)
+++ stable/7/contrib/netcat/nc.1	Tue Mar 23 23:09:38 2010	(r205563)
@@ -1,4 +1,4 @@
-.\"     $OpenBSD: nc.1,v 1.44 2006/12/02 01:08:30 jmc Exp $
+.\"     $OpenBSD: nc.1,v 1.50 2009/06/05 06:47:12 jmc Exp $
 .\"
 .\" Copyright (c) 1996 David Sacerdote
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 21, 2006
+.Dd June 5 2009
 .Dt NC 1
 .Os
 .Sh NAME
@@ -36,13 +36,17 @@
 .Sh SYNOPSIS
 .Nm nc
 .Bk -words
-.Op Fl 46DEdhklnorStUuvz
+.Op Fl 46DdEhklnorStUuvz
 .Op Fl e Ar IPsec_policy
+.Op Fl I Ar length
 .Op Fl i Ar interval
+.Op Fl -no-tcpopt
+.Op Fl O Ar length
 .Op Fl P Ar proxy_username
 .Op Fl p Ar source_port
 .Op Fl s Ar source_ip_address
 .Op Fl T Ar ToS
+.Op Fl V Ar fib
 .Op Fl w Ar timeout
 .Op Fl X Ar proxy_protocol
 .Oo Xo
@@ -50,7 +54,7 @@
 .Ar port Oc Oc
 .Xc
 .Op Ar hostname
-.Op Ar port Ns Bq Ar s
+.Op Ar port
 .Ek
 .Sh DESCRIPTION
 The
@@ -100,10 +104,6 @@ to use IPv6 addresses only.
 Enable debugging on the socket.
 .It Fl d
 Do not attempt to read from stdin.
-.It Fl h
-Prints out
-.Nm
-help.
 .It Fl E
 Shortcut for
 .Qo
@@ -118,6 +118,12 @@ to be used using the syntax described in
 .Xr ipsec_set_policy 3 .
 This flag can be specified up to two times, as typically one policy for
 each direction is needed.
+.It Fl h
+Prints out
+.Nm
+help.
+.It Fl I Ar length
+Specifies the size of the TCP receive buffer.
 .It Fl i Ar interval
 Specifies a delay time interval between lines of text sent and received.
 Also causes a delay time between connections to multiple ports.
@@ -146,6 +152,13 @@ option are ignored.
 .It Fl n
 Do not do any DNS or service lookups on any specified addresses,
 hostnames or ports.
+.It Fl -no-tcpopt
+Disables the use of TCP options on the socket, by setting the boolean
+TCP_NOOPT
+socket option.
+.It Fl O Ar length
+Specifies the size of the TCP send buffer.
+When
 .It Fl o
 .Dq Once-only mode .
 By default,
@@ -196,6 +209,9 @@ to script telnet sessions.
 Specifies to use Unix Domain Sockets.
 .It Fl u
 Use UDP instead of the default option of TCP.
+.It Fl V Ar fib
+Set the routing table (FIB).
+The default is 0.
 .It Fl v
 Have
 .Nm
@@ -263,8 +279,8 @@ unless the
 option is given
 (in which case the local host is used).
 .Pp
-.Ar port Ns Op Ar s
-can be single integers or ranges.
+.Ar port
+can be a single integer or a range of ports.
 Ranges are in the form nn-mm.
 In general,
 a destination port must be specified,
@@ -437,7 +453,9 @@ if the proxy requires it:
 .Ex -std
 .Sh SEE ALSO
 .Xr cat 1 ,
-.Xr ssh 1
+.Xr setfib 1 ,
+.Xr ssh 1 ,
+.Xr tcp 4
 .Sh AUTHORS
 Original implementation by *Hobbit*
 .Aq hobbit at avian.org .

Modified: stable/7/contrib/netcat/netcat.c
==============================================================================
--- stable/7/contrib/netcat/netcat.c	Tue Mar 23 23:03:30 2010	(r205562)
+++ stable/7/contrib/netcat/netcat.c	Tue Mar 23 23:09:38 2010	(r205563)
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcat.c,v 1.89 2007/02/20 14:11:17 jmc Exp $ */
+/* $OpenBSD: netcat.c,v 1.93 2009/06/05 00:18:10 claudio Exp $ */
 /*
  * Copyright (c) 2001 Eric Jackson <ericj at monkey.org>
  *
@@ -36,6 +36,7 @@
 #include <sys/limits.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/sysctl.h>
 #include <sys/time.h>
 #include <sys/un.h>
 
@@ -50,6 +51,7 @@
 
 #include <err.h>
 #include <errno.h>
+#include <getopt.h>
 #include <netdb.h>
 #include <poll.h>
 #include <stdarg.h>
@@ -78,6 +80,7 @@ int	kflag;					/* More than one connect 
 int	lflag;					/* Bind to local port */
 int	nflag;					/* Don't do name look up */
 int	oflag;					/* Once only: stop on EOF */
+int	FreeBSD_Oflag;				/* Do not use TCP options */
 char   *Pflag;					/* Proxy username */
 char   *pflag;					/* Localport flag */
 int	rflag;					/* Random ports flag */
@@ -88,8 +91,11 @@ int	vflag;					/* Verbosity */
 int	xflag;					/* Socks proxy */
 int	zflag;					/* Port Scan Flag */
 int	Dflag;					/* sodebug */
+int	Iflag;					/* TCP receive buffer size */
+int	Oflag;					/* TCP send buffer size */
 int	Sflag;					/* TCP MD5 signature option */
 int	Tflag = -1;				/* IP Type of Service */
+u_int	rdomain;
 
 int timeout = -1;
 int family = AF_UNSPEC;
@@ -120,6 +126,8 @@ int
 main(int argc, char *argv[])
 {
 	int ch, s, ret, socksv, ipsec_count;
+	int numfibs;
+	size_t intsize = sizeof(int);
 	char *host, *uport;
 	struct addrinfo hints;
 	struct servent *sv;
@@ -128,7 +136,12 @@ main(int argc, char *argv[])
 	char *proxy;
 	const char *errstr, *proxyhost = "", *proxyport = NULL;
 	struct addrinfo proxyhints;
+	struct option longopts[] = {
+		{ "no-tcpopt",	no_argument,	&FreeBSD_Oflag,	1 },
+		{ NULL,		0,		NULL,		0 }
+	};
 
+	rdomain = 0;
 	ret = 1;
 	ipsec_count = 0;
 	s = 0;
@@ -137,8 +150,9 @@ main(int argc, char *argv[])
 	uport = NULL;
 	sv = NULL;
 
-	while ((ch = getopt(argc, argv,
-	    "46e:DEdhi:jklnoP:p:rSs:tT:Uuvw:X:x:z")) != -1) {
+	while ((ch = getopt_long(argc, argv,
+	    "46DdEe:hI:i:jklnO:oP:p:rSs:tT:UuV:vw:X:x:z",
+	    longopts, NULL)) != -1) {
 		switch (ch) {
 		case '4':
 			family = AF_INET;
@@ -220,6 +234,14 @@ main(int argc, char *argv[])
 		case 'u':
 			uflag = 1;
 			break;
+		case 'V':
+			if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1)
+				errx(1, "Multiple FIBS not supported");
+			rdomain = (unsigned int)strtonum(optarg, 0,
+			    numfibs - 1, &errstr);
+			if (errstr)
+				errx(1, "FIB %s: %s", errstr, optarg);
+			break;
 		case 'v':
 			vflag = 1;
 			break;
@@ -240,12 +262,28 @@ main(int argc, char *argv[])
 		case 'D':
 			Dflag = 1;
 			break;
+		case 'I':
+			Iflag = strtonum(optarg, 1, 65536 << 14, &errstr);
+			if (errstr != NULL)
+				errx(1, "TCP receive window %s: %s",
+				    errstr, optarg);
+			break;
+		case 'O':
+			Oflag = strtonum(optarg, 1, 65536 << 14, &errstr);
+			if (errstr != NULL) {
+			    if (strcmp(errstr, "invalid") != 0)
+				errx(1, "TCP send window %s: %s",
+				    errstr, optarg);
+			}
+			break;
 		case 'S':
 			Sflag = 1;
 			break;
 		case 'T':
 			Tflag = parse_iptos(optarg);
 			break;
+		case 0:
+			break;
 		default:
 			usage(1);
 		}
@@ -508,7 +546,7 @@ int
 remote_connect(const char *host, const char *port, struct addrinfo hints)
 {
 	struct addrinfo *res, *res0;
-	int s, error;
+	int s, error, on = 1;
 
 	if ((error = getaddrinfo(host, port, &hints, &res)))
 		errx(1, "getaddrinfo: %s", gai_strerror(error));
@@ -525,10 +563,19 @@ remote_connect(const char *host, const c
 			add_ipsec_policy(s, ipsec_policy[1]);
 #endif
 
+		if (rdomain) {
+			if (setfib(rdomain) == -1)
+				err(1, "setfib");
+		}
+
 		/* Bind to a local port or source address if specified. */
 		if (sflag || pflag) {
 			struct addrinfo ahints, *ares;
 
+#ifdef SO_BINDANY
+			/* try SO_BINDANY, but don't insist */
+			setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on));
+#endif
 			memset(&ahints, 0, sizeof(struct addrinfo));
 			ahints.ai_family = res0->ai_family;
 			ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
@@ -591,6 +638,11 @@ local_listen(char *host, char *port, str
 		    res0->ai_protocol)) < 0)
 			continue;
 
+		if (rdomain) {
+			if (setfib(rdomain) == -1)
+				err(1, "setfib");
+		}
+
 		ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
 		if (ret == -1)
 			err(1, NULL);
@@ -600,6 +652,11 @@ local_listen(char *host, char *port, str
 		if (ipsec_policy[1] != NULL)
 			add_ipsec_policy(s, ipsec_policy[1]);
 #endif
+		if (FreeBSD_Oflag) {
+			if (setsockopt(s, IPPROTO_TCP, TCP_NOOPT,
+			    &FreeBSD_Oflag, sizeof(FreeBSD_Oflag)) == -1)
+				err(1, "disable TCP options");
+		}
 
 		if (bind(s, (struct sockaddr *)res0->ai_addr,
 		    res0->ai_addrlen) == 0)
@@ -829,6 +886,21 @@ set_common_sockopts(int s)
 		    &Tflag, sizeof(Tflag)) == -1)
 			err(1, "set IP ToS");
 	}
+	if (Iflag) {
+		if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
+		    &Iflag, sizeof(Iflag)) == -1)
+			err(1, "set TCP receive buffer size");
+	}
+	if (Oflag) {
+		if (setsockopt(s, SOL_SOCKET, SO_SNDBUF,
+		    &Oflag, sizeof(Oflag)) == -1)
+			err(1, "set TCP send buffer size");
+	}
+	if (FreeBSD_Oflag) {
+		if (setsockopt(s, IPPROTO_TCP, TCP_NOOPT,
+		    &FreeBSD_Oflag, sizeof(FreeBSD_Oflag)) == -1)
+			err(1, "disable TCP options");
+	}
 }
 
 int
@@ -854,20 +926,24 @@ help(void)
 	usage(0);
 	fprintf(stderr, "\tCommand Summary:\n\
 	\t-4		Use IPv4\n\
-	\t-6            Use IPv6\n");
+	\t-6		Use IPv6\n\
+	\t-D		Enable the debug socket option\n\
+	\t-d		Detach from stdin\n");
 #ifdef IPSEC
 	fprintf(stderr, "\
-	\t-e policy     Use specified IPsec policy\n\
-	\t-E            Use IPsec ESP\n");
+	\t-E		Use IPsec ESP\n\
+	\t-e policy	Use specified IPsec policy\n");
 #endif
 	fprintf(stderr, "\
-	\t-D		Enable the debug socket option\n\
-	\t-d		Detach from stdin\n\
 	\t-h		This help text\n\
+	\t-I length	TCP receive buffer length\n\
 	\t-i secs\t	Delay interval for lines sent, ports scanned\n\
 	\t-k		Keep inbound sockets open for multiple connects\n\
 	\t-l		Listen mode, for inbound connects\n\
 	\t-n		Suppress name/port resolutions\n\
+	\t--no-tcpopt	Disable TCP options\n\
+	\t-O length	TCP send buffer length\n\
+	\t-o		Terminate on EOF on input\n\
 	\t-P proxyuser\tUsername for proxy authentication\n\
 	\t-p port\t	Specify local port for remote connects\n\
 	\t-r		Randomize remote ports\n\
@@ -877,6 +953,7 @@ help(void)
 	\t-t		Answer TELNET negotiation\n\
 	\t-U		Use UNIX domain socket\n\
 	\t-u		UDP mode\n\
+	\t-V fib	Specify alternate routing table (FIB)\n\
 	\t-v		Verbose\n\
 	\t-w secs\t	Timeout for connects and final net reads\n\
 	\t-X proto	Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\
@@ -914,13 +991,15 @@ add_ipsec_policy(int s, char *policy)
 void
 usage(int ret)
 {
+	fprintf(stderr,
 #ifdef IPSEC
-	fprintf(stderr, "usage: nc [-46DEdhklnrStUuvz] [-e policy] [-i interval] [-P proxy_username] [-p source_port]\n");
+	    "usage: nc [-46DdEhklnorStUuvz] [-e policy] [-I length] [-i interval] [-O length]\n"
 #else
-	fprintf(stderr, "usage: nc [-46DdhklnrStUuvz] [-i interval] [-P proxy_username] [-p source_port]\n");
+	    "usage: nc [-46DdhklnorStUuvz] [-I length] [-i interval] [-O length]\n"
 #endif
-	fprintf(stderr, "\t  [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]\n");
-	fprintf(stderr, "\t  [-x proxy_address[:port]] [hostname] [port[s]]\n");
+	    "\t  [-P proxy_username] [-p source_port] [-s source_ip_address] [-T ToS]\n"
+	    "\t  [-V fib] [-w timeout] [-X proxy_protocol]\n"
+	    "\t  [-x proxy_address[:port]] [hostname] [port]\n");
 	if (ret)
 		exit(1);
 }


More information about the svn-src-stable mailing list