Add '-n' flag: don't attempt to read any data from standard input.

This commit is contained in:
Archie Cobbs 2000-07-27 21:55:48 +00:00
parent 5edcf9c853
commit 0d3e728618
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=63931
2 changed files with 26 additions and 7 deletions

View File

@ -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]");
}

View File

@ -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