From 6b3242c12c197664bcd78a5e7694121a43d26a5b Mon Sep 17 00:00:00 2001 From: tedu <> Date: Mon, 1 Mar 2004 00:37:08 +0000 Subject: resolve pr3694. add -d [etached] to ignore stdin. ok henning@ mcbride@ --- src/usr.bin/nc/nc.1 | 4 +++- src/usr.bin/nc/netcat.c | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/usr.bin/nc/nc.1 b/src/usr.bin/nc/nc.1 index 64a1dbbc8b..82712fad80 100644 --- a/src/usr.bin/nc/nc.1 +++ b/src/usr.bin/nc/nc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: nc.1,v 1.28 2004/02/20 10:53:10 jmc Exp $ +.\" $OpenBSD: nc.1,v 1.29 2004/03/01 00:37:08 tedu Exp $ .\" .\" Copyright (c) 1996 David Sacerdote .\" All rights reserved. @@ -89,6 +89,8 @@ to use IPv4 addresses only. Forces .Nm to use IPv6 addresses only. +.It Fl d +Do not attempt to read from stdin. .It Fl h Prints out .Nm diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 505cbd77b1..f303bd2fb1 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcat.c,v 1.67 2004/02/20 10:53:10 jmc Exp $ */ +/* $OpenBSD: netcat.c,v 1.68 2004/03/01 00:37:08 tedu Exp $ */ /* * Copyright (c) 2001 Eric Jackson * @@ -60,6 +60,7 @@ #define PORT_MAX_LEN 6 /* Command Line Options */ +int dflag; /* detached, no stdin */ int iflag; /* Interval Flag */ int kflag; /* More than one connect */ int lflag; /* Bind to local port */ @@ -113,7 +114,7 @@ main(int argc, char *argv[]) endp = NULL; sv = NULL; - while ((ch = getopt(argc, argv, "46UX:hi:klnp:rs:tuvw:x:zS")) != -1) { + while ((ch = getopt(argc, argv, "46UX:dhi:klnp:rs:tuvw:x:zS")) != -1) { switch (ch) { case '4': family = AF_INET; @@ -129,6 +130,9 @@ main(int argc, char *argv[]) if ((socksv != 4 && socksv != 5) || *endp != '\0') errx(1, "only SOCKS version 4 and 5 supported"); break; + case 'd': + dflag = 1; + break; case 'h': help(); break; @@ -578,7 +582,7 @@ readwrite(int nfd) if (iflag) sleep(iflag); - if ((n = poll(pfd, 2, timeout)) < 0) { + if ((n = poll(pfd, 2 - dflag, timeout)) < 0) { close(nfd); err(1, "Polling Error"); } @@ -603,7 +607,7 @@ readwrite(int nfd) } } - if (pfd[1].revents & POLLIN) { + if (!dflag && pfd[1].revents & POLLIN) { if ((n = read(wfd, buf, sizeof(buf))) < 0) return; else if (n == 0) { -- cgit v1.2.3-55-g6feb