[nc/f13/master] Accept ports separated by commas.

Petr Sabata psabata at fedoraproject.org
Fri Oct 8 13:41:34 UTC 2010


commit f377b45159ffc9d41d53ba229f9363a23730331c
Author: Petr Sabata <psabata at redhat.com>
Date:   Fri Oct 8 15:41:30 2010 +0200

    Accept ports separated by commas.

 nc-1.84-port-comma.patch |  131 ++++++++++++++++++++++++++++++++++++++++++++++
 nc.spec                  |    8 +++-
 2 files changed, 138 insertions(+), 1 deletions(-)
---
diff --git a/nc-1.84-port-comma.patch b/nc-1.84-port-comma.patch
new file mode 100644
index 0000000..e502220
--- /dev/null
+++ b/nc-1.84-port-comma.patch
@@ -0,0 +1,131 @@
+--- a/netcat.c 	2010-08-07 23:22:36.504902769 -0400
++++ b/netcat.c	2010-08-07 23:33:22.934901172 -0400
+@@ -805,61 +805,71 @@ atelnet(int nfd, unsigned char *buf, uns
+ void
+ build_ports(char *p)
+ {
+-	char *n, *endp;
++	char *n, *endp, *comma;
+ 	int hi, lo, cp;
+ 	int x = 0;
+ 
+-	if ((n = strchr(p, '-')) != NULL) {
+-		if (lflag)
+-			errx(1, "Cannot use -l with multiple ports!");
+-
+-		*n = '\0';
+-		n++;
+-
+-		/* Make sure the ports are in order: lowest->highest. */
+-		hi = (int)strtoul(n, &endp, 10);
+-		if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
+-			errx(1, "port range not valid");
+-		lo = (int)strtoul(p, &endp, 10);
+-		if (lo <= 0 || lo > PORT_MAX || *endp != '\0')
+-			errx(1, "port range not valid");
+-
+-		if (lo > hi) {
+-			cp = hi;
+-			hi = lo;
+-			lo = cp;
+-		}
++	do {
++		comma = strchr(p, ',');
++		if (comma)
++			*comma = '\0';
++
++		if ((n = strchr(p, '-')) != NULL) {
++			if (lflag)
++				errx(1, "Cannot use -l with multiple ports!");
++
++			*n = '\0';
++			n++;
++
++			/* Make sure the ports are in order: lowest->highest. */
++			hi = (int)strtoul(n, &endp, 10);
++			if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
++				errx(1, "port range not valid");
++			lo = (int)strtoul(p, &endp, 10);
++			if (lo <= 0 || lo > PORT_MAX || *endp != '\0')
++				errx(1, "port range not valid");
++
++			if (lo > hi) {
++				cp = hi;
++				hi = lo;
++				lo = cp;
++			}
+ 
+-		/* Load ports sequentially. */
+-		for (cp = lo; cp <= hi; cp++) {
++			/* Load ports sequentially. */
++			for (cp = lo; cp <= hi; cp++) {
++				portlist[x] = calloc(1, PORT_MAX_LEN);
++				if (portlist[x] == NULL)
++					err(1, NULL);
++				snprintf(portlist[x], PORT_MAX_LEN, "%d", cp);
++				x++;
++			}
++		} else {
++			hi = (int)strtoul(p, &endp, 10);
++			if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
++				errx(1, "port range not valid");
+ 			portlist[x] = calloc(1, PORT_MAX_LEN);
+-			if (portlist[x] == NULL)
++			if (portlist[0] == NULL)
+ 				err(1, NULL);
+-			snprintf(portlist[x], PORT_MAX_LEN, "%d", cp);
++			snprintf(portlist[x], PORT_MAX_LEN, "%d", hi);
+ 			x++;
+ 		}
+-
+-		/* Randomly swap ports. */
+-		if (rflag) {
+-			int y;
+-			char *c;
+-
+-			for (x = 0; x <= (hi - lo); x++) {
+-				/* use random instead of arc4random */
+-				y = (random() & 0xFFFF) % (hi - lo);
+-				c = portlist[x];
+-				portlist[x] = portlist[y];
+-				portlist[y] = c;
+-			}
++		if (comma)
++			p = comma + 1;
++	} while (comma);
++
++	/* Randomly swap ports. */
++	if (rflag) {
++		int max = x;
++		int y;
++		char *c;
++
++		for (x = 0; x < max; x++) {
++			/* use random instead of arc4random */
++			y = (random() & 0xFFFF) % max;
++			c = portlist[x];
++			portlist[x] = portlist[y];
++			portlist[y] = c;
+ 		}
+-	} else {
+-		hi = (int)strtoul(p, &endp, 10);
+-		if (hi <= 0 || hi > PORT_MAX || *endp != '\0')
+-			errx(1, "port range not valid");
+-		portlist[0] = calloc(1, PORT_MAX_LEN);
+-		if (portlist[0] == NULL)
+-			err(1, NULL);
+-		portlist[0] = p;
+ 	}
+ }
+ 
+--- nc/nc.1	2010-10-08 15:33:47.092169419 +0200
++++ nc/nc.1.comma	2010-10-08 15:38:10.701171878 +0200
+@@ -235,7 +235,7 @@
+ (in which case the local host is used).
+ .Pp
+ .Ar port Ns Op Ar s
+-can be single integers or ranges.
++can be one or more comma-separated integers or ranges.
+ Ranges are in the form nn-mm.
+ In general,
+ a destination port must be specified,
diff --git a/nc.spec b/nc.spec
index aa53c0c..4b1eb23 100644
--- a/nc.spec
+++ b/nc.spec
@@ -1,7 +1,7 @@
 Summary: Reads and writes data across network connections using TCP or UDP
 Name: nc
 Version: 1.84
-Release: 22%{?dist}
+Release: 23%{?dist}
 URL:	 http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/nc/
 # source is CVS checkout
 Source0: nc-%{version}.tar.bz2
@@ -18,6 +18,7 @@ Patch9: nc-1.84-man.patch
 Patch10: nc-1.84-gcc4.3.patch
 Patch11: nc-1.84-efficient_reads.patch
 Patch12: nc-1.84-verbose-segfault.patch
+Patch13: nc-1.84-port-comma.patch
 
 License: BSD
 Group: Applications/Internet
@@ -52,6 +53,7 @@ capabilities.
 %patch10 -p1 -b .gcc
 %patch11 -p1 -b .reads
 %patch12 -p1 -b .verb-segfault
+%patch13 -p1 -b .port-comma
 
 %build
 gcc $RPM_OPT_FLAGS -Werror -fno-strict-aliasing `pkg-config --cflags --libs glib-2.0` netcat.c atomicio.c socks.c -o nc
@@ -79,6 +81,10 @@ rm -rf ${RPM_BUILD_ROOT}
 %doc README
 
 %changelog
+* Fri Oct 08 2010 Petr Sabata <psabata at redhat.com> - 1.84-23
+- accept ports separated by commas, patch by Jonathan Kamens
+- rhbz#622204
+
 * Wed Jan 06 2010 Jan Zeleny <jzeleny at redhat.com> - 1.84-22
 - some updates in spec file in order to complete merge review
 - changed location of testing scripts to /usr/share/nc/scripts


More information about the scm-commits mailing list