From 0d3e72861810e434c4f79b7a74e5268eac06b3fe Mon Sep 17 00:00:00 2001 From: Archie Cobbs Date: Thu, 27 Jul 2000 21:55:48 +0000 Subject: [PATCH] Add '-n' flag: don't attempt to read any data from standard input. --- usr.sbin/nghook/main.c | 15 ++++++++++++--- usr.sbin/nghook/nghook.8 | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/usr.sbin/nghook/main.c b/usr.sbin/nghook/main.c index 93ba6cd5cccf..c0ef43d572b6 100644 --- a/usr.sbin/nghook/main.c +++ b/usr.sbin/nghook/main.c @@ -72,10 +72,11 @@ main(int ac, char *av[]) int csock, dsock; int asciiFlag = 0; int loopFlag = 0; + int noInput = 0; int ch; /* Parse flags */ - while ((ch = getopt(ac, av, "adl")) != EOF) { + while ((ch = getopt(ac, av, "adln")) != EOF) { switch (ch) { case 'a': asciiFlag = 1; @@ -86,6 +87,9 @@ main(int ac, char *av[]) case 'l': loopFlag = 1; break; + case 'n': + noInput = 1; + break; case '?': default: Usage(); @@ -119,13 +123,18 @@ main(int ac, char *av[]) NGM_GENERIC_COOKIE, NGM_CONNECT, &ngc, sizeof(ngc)) < 0) errx(EX_OSERR, "can't connect to node"); + /* Close standard input if not reading from it */ + if (noInput) + fclose(stdin); + /* Relay data */ while (1) { fd_set rfds; /* Setup bits */ FD_ZERO(&rfds); - FD_SET(0, &rfds); + if (!noInput) + FD_SET(0, &rfds); FD_SET(dsock, &rfds); /* Wait for something to happen */ @@ -224,6 +233,6 @@ WriteAscii(u_char *buf, int len) static void Usage(void) { - errx(EX_USAGE, "usage: nghook [-da] path [hookname]"); + errx(EX_USAGE, "usage: nghook [-adln] path [hookname]"); } diff --git a/usr.sbin/nghook/nghook.8 b/usr.sbin/nghook/nghook.8 index 746095169778..abab2c2f5a5a 100644 --- a/usr.sbin/nghook/nghook.8 +++ b/usr.sbin/nghook/nghook.8 @@ -46,6 +46,7 @@ node .Op Fl a .Op Fl d .Op Fl l +.Op Fl n .Ar path .Op Ar hookname .Sh DESCRIPTION @@ -65,18 +66,27 @@ is assumed. At this point all data written to standard input is sent to the node and all data received from the node is relayed to standard output. +.Nm +exits when +.Dv EOF +is detected on standard input. .Pp The options are as follows: .Pp .Bl -tag -width indent .It Fl a -Output each read packet in -.Tn ASCII . +Output each packet read in human-readable decoded +.Tn ASCII +form instead of raw binary. .It Fl d Increase the debugging verbosity level. .It Fl l Loops all received data back to the hook in addition to writing it to standard output. +.It Fl n +Don't attempt to read any data from standard input. +.Nm +will continue reading from the node until stopped by a signal. .El .Sh BUGS Although all input is read in unbuffered mode, @@ -84,7 +94,7 @@ there's no way to control the packetization of the input. .Sh SEE ALSO .Xr netgraph 4 , .Xr netgraph 3 , -.Xr ngctl 8 . +.Xr ngctl 8 .Sh HISTORY The .Em netgraph @@ -92,5 +102,5 @@ system was designed and first implemented at Whistle Communications, Inc. in a version of .Fx 2.2 customized for the Whistle InterJet. -.Sh AUTHOR +.Sh AUTHORS .An Archie Cobbs Aq archie@whistle.com