Commit 2ebffb01 authored by Guilhem Moulin's avatar Guilhem Moulin
Browse files

Allow usage of -s with -l for consistency with netcat-traditional.

Closes: #879853.
parent a3778052
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -5,6 +5,9 @@ netcat-openbsd (1.187-1) UNRELEASED; urgency=low
  * debian/patches/send-crlf.patch: clarify in the manpage that the "-C" flag
    (translate LF to CR+LF) only affects input data, and that LF characters
    that are already preceded with CR are not translated.  Closes: #861062.
  * Allow usage of -s with -l for consistency with netcat-traditional.  `nc -l
    -p 12345 -s ::1` now behave as `nc -l -p 12345 ::1` and `nc -l ::1 12345`.
    Closes: #879853.

 -- Guilhem Moulin <guilhem@debian.org>  Thu, 23 Nov 2017 04:01:10 +0100

+77 −35
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@ Date: Mon, 13 Feb 2012 19:06:52 +0800
Subject: misc failures and features

---
 Makefile |    3 +-
 nc.1     |   76 +++++++++++++++++++++++++++++++++++++++++++++++++---
 netcat.c |   91 ++++++++++++++++++++++++++++++++++++++++++++-------------------
 3 files changed, 138 insertions(+), 32 deletions(-)
 Makefile |    3 +
 nc.1     |   98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
 netcat.c |   98 +++++++++++++++++++++++++++++++++++++++++++--------------------
 3 files changed, 156 insertions(+), 43 deletions(-)

--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,44 @@ Subject: misc failures and features
 .It Fl C
 Send CRLF as line-ending.  Each line feed (LF) character from the input
 data is translated into CR+LF before being written to the socket.  Line
@@ -361,6 +363,54 @@ and which side is being used as a
@@ -148,12 +150,21 @@ Used to specify that
 .Nm
 should listen for an incoming connection rather than initiate a
 connection to a remote host.
-It is an error to use this option in conjunction with the
-.Fl p ,
-.Fl s ,
-or
+The
+.Ar destination
+and
+.Ar port
+to listen on can be specified either as non-optional arguments, or with
+options
+.Fl s
+and
+.Fl p
+respctively.
+It is an error to use
+.Fl l
+in conjunction with the
 .Fl z
-options.
+option.
 Additionally, any timeouts specified with the
 .Fl w
 option are ignored.
@@ -200,9 +211,6 @@ For
 .Ux Ns -domain
 datagram sockets, specifies the local temporary socket file
 to create and use so that datagrams can be received.
-It is an error to use this option in conjunction with the
-.Fl l
-option.
 .It Fl T Ar keyword
 Change IPv4 TOS value.
 .Ar keyword
@@ -361,6 +369,54 @@ and which side is being used as a
 The connection may be terminated using an
 .Dv EOF
 .Pq Sq ^D .
@@ -95,7 +132,7 @@ Subject: misc failures and features
 .Sh DATA TRANSFER
 The example in the previous section can be expanded to build a
 basic data transfer model.
@@ -420,15 +470,30 @@ The
@@ -420,15 +476,30 @@ The
 flag can be used to tell
 .Nm
 to report open ports,
@@ -129,7 +166,7 @@ Subject: misc failures and features
 .Pp
 Alternatively, it might be useful to know which server software
 is running, and which versions.
@@ -493,6 +558,9 @@ Original implementation by *Hobbit*
@@ -493,6 +564,9 @@ Original implementation by *Hobbit*
 .br
 Rewritten with IPv6 support by
 .An Eric Jackson Aq Mt ericj@monkey.org .
@@ -209,61 +246,66 @@ Subject: misc failures and features
 		case 'U':
 			family = AF_UNIX;
 			break;
@@ -499,32 +511,39 @@ main(int argc, char *argv[])
@@ -498,33 +510,41 @@ main(int argc, char *argv[])
 # endif
 
 	/* Cruft to make sure options are clean, and used properly. */
 	if (argv[0] && !argv[1] && family == AF_UNIX) {
-	if (argv[0] && !argv[1] && family == AF_UNIX) {
- 		if (uflag)
- 			errx(1, "cannot use -u and -U");
+	if (family == AF_UNIX) {
 # if defined(IPPROTO_DCCP) && defined(SOCK_DCCP)
 		if (dccpflag)
 			errx(1, "cannot use -Z and -U");
 # endif
 		host = argv[0];
 		uport = NULL;
-		host = argv[0];
-		uport = NULL;
-	} else if (!argv[0] && lflag) {
-		if (sflag)
-			errx(1, "cannot use -s and -l");
-		if (pflag)
-			errx(1, "cannot use -p and -l");
-		if (zflag)
-			errx(1, "cannot use -z and -l");
-		if (pflag)
-			uport=pflag;
-	} else if (argv[0] && !argv[1]) {
-		if (!lflag)
-			usage(1);
+		if (!argv[0] && sflag)
+			host = sflag;
+		else if (argv[0] && !argv[1] && !sflag)
+			host = argv[0];
+		else
 			usage(1);
-		uport = argv[0];
-		host = NULL;
+		uport = NULL;
+	} else if (argv[0] && !argv[1] && lflag) {
+		if (pflag) {
+			uport = &pflag;
+			host = argv[0];
+			if (sflag)
+				usage(1);
+		} else {
+			uport = argv;
+			host = NULL;
+			host = sflag;
+		}
+	} else if (!argv[0] && lflag && pflag) {
+		uport = &pflag;
 		host = NULL;
+		host = sflag;
 	} else if (argv[0] && argv[1]) {
 		host = argv[0];
-		uport = argv[1];
+ 		uport = &argv[1];
+		if (pflag || sflag)
+			usage(1);
 	} else
 		usage(1);
 
+	if (lflag) {
+		if (sflag)
+			errx(1, "cannot use -s and -l");
+		if (zflag)
+	if (lflag && zflag)
+		errx(1, "cannot use -z and -l");
+		if (pflag)
+			/* This still does not work well because of getopt mess
+			errx(1, "cannot use -p and -l"); */
+			uport = &pflag;
+	}
 	if (!lflag && kflag)
 		errx(1, "must use -l with -k");
 # if defined(TLS)
@@ -693,7 +712,7 @@ main(int argc, char *argv[])
@@ -693,7 +713,7 @@ main(int argc, char *argv[])
 			else
 				s = unix_listen(host);
 		} else
@@ -272,7 +314,7 @@ Subject: misc failures and features
 		if (s < 0)
 			err(1, NULL);
 
@@ -702,7 +721,8 @@ main(int argc, char *argv[])
@@ -702,7 +722,8 @@ main(int argc, char *argv[])
 			local = "::";
 		else
 			local = "0.0.0.0";
@@ -282,7 +324,7 @@ Subject: misc failures and features
 			host ?: local,
 			family,
 			*uport);
@@ -917,6 +937,8 @@ unix_bind(char *path, int flags)
@@ -917,6 +938,8 @@ unix_bind(char *path, int flags)
 	    0)) < 0)
 		return -1;
 
@@ -291,7 +333,7 @@ Subject: misc failures and features
 	memset(&s_un, 0, sizeof(struct sockaddr_un));
 	s_un.sun_family = AF_UNIX;
 
@@ -1040,8 +1062,10 @@ unix_connect(char *path)
@@ -1040,8 +1063,10 @@ unix_connect(char *path)
 		if ((s = unix_bind(unix_dg_tmp_socket, SOCK_CLOEXEC)) < 0)
 			return -1;
 	} else {
@@ -303,7 +345,7 @@ Subject: misc failures and features
 	}
 
 	memset(&s_un, 0, sizeof(struct sockaddr_un));
@@ -1051,10 +1075,12 @@ unix_connect(char *path)
@@ -1051,10 +1076,12 @@ unix_connect(char *path)
 	    sizeof(s_un.sun_path)) {
 		close(s);
 		errno = ENAMETOOLONG;
@@ -316,7 +358,7 @@ Subject: misc failures and features
 		close(s);
 		errno = save_errno;
 		return -1;
@@ -1749,25 +1775,26 @@ strtoport(char *portstr, int udp)
@@ -1749,25 +1776,26 @@ strtoport(char *portstr, int udp)
  * that we should try to connect to.
  */
 void
@@ -347,7 +389,7 @@ Subject: misc failures and features
 		if (lo > hi) {
 			cp = hi;
 			hi = lo;
@@ -1795,7 +1822,7 @@ build_ports(char *p)
@@ -1795,7 +1823,7 @@ build_ports(char *p)
 	} else {
 		char *tmp;
 
@@ -356,7 +398,7 @@ Subject: misc failures and features
 		if (asprintf(&tmp, "%d", hi) != -1)
 			portlist[0] = tmp;
 		else
@@ -1833,6 +1860,15 @@ set_common_sockopts(int s, const struct
@@ -1833,6 +1861,15 @@ set_common_sockopts(int s, const struct
 	int x = 1;
 	int af = sa->sa_family;
 
@@ -372,7 +414,7 @@ Subject: misc failures and features
 # if defined(TCP_MD5SIG) && defined(TCP_MD5SIG_MAXKEYLEN)
 	if (Sflag) {
 		struct tcp_md5sig sig;
@@ -2102,6 +2138,7 @@ help(void)
@@ -2102,6 +2139,7 @@ help(void)
 	fprintf(stderr, "\tCommand Summary:\n\
 	\t-4		Use IPv4\n\
 	\t-6		Use IPv6\n\
+2 −2
Original line number Diff line number Diff line
@@ -185,10 +185,10 @@ Subject: port to linux with libsd
+	} else if (!argv[0] && lflag) {
+		if (sflag)
+			errx(1, "cannot use -s and -l");
+		if (pflag)
+			errx(1, "cannot use -p and -l");
+		if (zflag)
+			errx(1, "cannot use -z and -l");
+		if (pflag)
+			uport=pflag;
 	} else if (argv[0] && !argv[1]) {
 		if (!lflag)
 			usage(1);