summaryrefslogtreecommitdiff
path: root/net/obnc
diff options
context:
space:
mode:
authorJoerg Wunsch <joerg@FreeBSD.org>2003-08-31 21:07:23 +0000
committerJoerg Wunsch <joerg@FreeBSD.org>2003-08-31 21:07:23 +0000
commit7a5e8bb518eb134ebaf765c49181b03f04d27240 (patch)
tree98774481c0bc8cca3c8181270e661c9140e1969a /net/obnc
parent- New port mail/p5-Email-Folder (diff)
Implement an option -o ("Once only") that allows this netcat utility
to terminate at the first EOF condition on local input (as opposed to waiting for the network end to shut down). Can be useful when talking to network servers that never drop the connection on their end, like an port 9100 printer server in my case. I've also submitted that to the OpenBSD maintainer, so in case they accept, we can later on undo my local patch. Approved by: dd (maintainer)
Notes
Notes: svn path=/head/; revision=88211
Diffstat (limited to 'net/obnc')
-rw-r--r--net/obnc/files/patch-nc.126
-rw-r--r--net/obnc/files/patch-netcat.c47
2 files changed, 57 insertions, 16 deletions
diff --git a/net/obnc/files/patch-nc.1 b/net/obnc/files/patch-nc.1
index 5dffa70aacbb..d562e7d057fe 100644
--- a/net/obnc/files/patch-nc.1
+++ b/net/obnc/files/patch-nc.1
@@ -1,16 +1,16 @@
---- nc.1.orig Fri Oct 19 07:42:18 2001
-+++ nc.1 Fri Oct 19 07:52:16 2001
+--- nc.1.orig Tue Feb 19 23:45:18 2002
++++ nc.1 Wed Jul 30 11:41:47 2003
@@ -33,7 +33,8 @@
.Nd "arbitrary TCP and UDP connections and listens"
.Sh SYNOPSIS
.Nm nc
-.Op Fl 46hklnrtuvzU
-+.Op Fl 46EhklnrtuvzU
++.Op Fl 46EhklnortuvzU
+.Op Fl e Ar IPsec policy
.Op Fl i Ar interval
.Op Fl p Ar source port
.Op Fl s Ar source ip address
-@@ -90,6 +91,12 @@
+@@ -89,6 +90,12 @@
Prints out
.Nm
help.
@@ -23,7 +23,23 @@
.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.
-@@ -149,6 +156,10 @@
+@@ -105,6 +112,15 @@
+ .It Fl n
+ Do not do any DNS or service lookups on any specified addresses,
+ hostnames or ports.
++.It Fl o
++.Dq Once-only mode .
++By default,
++.Nm
++does not terminate on EOF condition on input,
++but continues until the network side has been closed down.
++Specifying
++.Fl o
++will make it terminate on EOF as well.
+ .It Fl p Ar port
+ Specifies the source port
+ .Nm
+@@ -157,6 +173,10 @@
.It Li "nc -s 10.1.2.3 example.host 42"
Open a TCP connection to port 42 of example.host using 10.1.2.3 as the
IP for the local end of the connection.
diff --git a/net/obnc/files/patch-netcat.c b/net/obnc/files/patch-netcat.c
index 9d75b5e652c5..6807501f4a8b 100644
--- a/net/obnc/files/patch-netcat.c
+++ b/net/obnc/files/patch-netcat.c
@@ -1,5 +1,5 @@
---- netcat.c.orig Tue Feb 19 22:42:04 2002
-+++ netcat.c Thu Feb 21 23:37:07 2002
+--- netcat.c.orig Tue Feb 19 23:42:04 2002
++++ netcat.c Wed Jul 30 11:41:11 2003
@@ -37,6 +37,9 @@
#include <sys/un.h>
@@ -10,7 +10,7 @@
#include <arpa/telnet.h>
#include <err.h>
-@@ -53,6 +56,7 @@
+@@ -53,10 +56,12 @@
#define PORT_MAX 65535
/* Command Line Options */
@@ -18,7 +18,12 @@
int iflag; /* Interval Flag */
int kflag; /* More than one connect */
int lflag; /* Bind to local port */
-@@ -84,10 +88,16 @@
+ int nflag; /* Dont do name lookup */
++int oflag; /* Once only: stop on EOF */
+ char *pflag; /* Localport flag */
+ int rflag; /* Random ports flag */
+ char *sflag; /* Source Address */
+@@ -84,10 +89,16 @@
int unix_listen(char *);
void usage(int);
@@ -36,7 +41,7 @@
char *host, *uport, *endp;
struct addrinfo hints;
struct servent *sv;
-@@ -99,12 +109,13 @@
+@@ -99,12 +110,13 @@
ret = 1;
s = 0;
@@ -47,11 +52,11 @@
sv = NULL;
- while ((ch = getopt(argc, argv, "46Uhi:klnp:rs:tuvw:x:z")) != -1) {
-+ while ((ch = getopt(argc, argv, "46e:EUhi:klnp:rs:tuvw:x:z")) != -1) {
++ while ((ch = getopt(argc, argv, "46e:EUhi:klnop:rs:tuvw:x:z")) != -1) {
switch (ch) {
case '4':
family = AF_INET;
-@@ -115,6 +126,21 @@
+@@ -115,6 +127,21 @@
case 'U':
family = AF_UNIX;
break;
@@ -73,7 +78,17 @@
case 'h':
help();
break;
-@@ -422,6 +448,12 @@
+@@ -132,6 +159,9 @@
+ case 'n':
+ nflag = 1;
+ break;
++ case 'o':
++ oflag = 1;
++ break;
+ case 'p':
+ pflag = optarg;
+ break;
+@@ -422,6 +452,12 @@
if ((s = socket(res0->ai_family, res0->ai_socktype,
res0->ai_protocol)) < 0)
continue;
@@ -86,7 +101,7 @@
/* Bind to a local port or source address if specified */
if (sflag || pflag) {
-@@ -497,6 +529,12 @@
+@@ -497,6 +533,12 @@
ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
if (ret == -1)
err(1, NULL);
@@ -99,7 +114,17 @@
if (bind(s, (struct sockaddr *)res0->ai_addr,
res0->ai_addrlen) == 0)
-@@ -690,7 +728,13 @@
+@@ -561,7 +603,8 @@
+ }
+
+ if (pfd[1].revents & POLLIN) {
+- if ((n = read(wfd, buf, sizeof(buf))) < 0) {
++ if ((n = read(wfd, buf, sizeof(buf))) < 0 ||
++ (oflag && n == 0)) {
+ return;
+ } else
+ if((ret = atomicio(write, nfd, buf, n)) != n)
+@@ -690,7 +733,13 @@
usage(0);
fprintf(stderr, "\tCommand Summary:\n\
\t-4 Use IPv4\n\
@@ -114,7 +139,7 @@
\t-U Use UNIX domain socket\n\
\t-h This help text\n\
\t-i secs\t Delay interval for lines sent, ports scanned\n\
-@@ -707,13 +751,42 @@
+@@ -707,13 +756,42 @@
\t-x addr[:port]\tSpecify socks5 proxy address and port\n\
\t-z Zero-I/O mode [used for scanning]\n\
Port numbers can be individual or ranges: lo-hi [inclusive]\n");