Add '-n' flag: don't attempt to read any data from standard input.
This commit is contained in:
parent
5edcf9c853
commit
0d3e728618
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=63931
@ -72,10 +72,11 @@ main(int ac, char *av[])
|
|||||||
int csock, dsock;
|
int csock, dsock;
|
||||||
int asciiFlag = 0;
|
int asciiFlag = 0;
|
||||||
int loopFlag = 0;
|
int loopFlag = 0;
|
||||||
|
int noInput = 0;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
/* Parse flags */
|
/* Parse flags */
|
||||||
while ((ch = getopt(ac, av, "adl")) != EOF) {
|
while ((ch = getopt(ac, av, "adln")) != EOF) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'a':
|
case 'a':
|
||||||
asciiFlag = 1;
|
asciiFlag = 1;
|
||||||
@ -86,6 +87,9 @@ main(int ac, char *av[])
|
|||||||
case 'l':
|
case 'l':
|
||||||
loopFlag = 1;
|
loopFlag = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'n':
|
||||||
|
noInput = 1;
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
Usage();
|
Usage();
|
||||||
@ -119,13 +123,18 @@ main(int ac, char *av[])
|
|||||||
NGM_GENERIC_COOKIE, NGM_CONNECT, &ngc, sizeof(ngc)) < 0)
|
NGM_GENERIC_COOKIE, NGM_CONNECT, &ngc, sizeof(ngc)) < 0)
|
||||||
errx(EX_OSERR, "can't connect to node");
|
errx(EX_OSERR, "can't connect to node");
|
||||||
|
|
||||||
|
/* Close standard input if not reading from it */
|
||||||
|
if (noInput)
|
||||||
|
fclose(stdin);
|
||||||
|
|
||||||
/* Relay data */
|
/* Relay data */
|
||||||
while (1) {
|
while (1) {
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
|
|
||||||
/* Setup bits */
|
/* Setup bits */
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_SET(0, &rfds);
|
if (!noInput)
|
||||||
|
FD_SET(0, &rfds);
|
||||||
FD_SET(dsock, &rfds);
|
FD_SET(dsock, &rfds);
|
||||||
|
|
||||||
/* Wait for something to happen */
|
/* Wait for something to happen */
|
||||||
@ -224,6 +233,6 @@ WriteAscii(u_char *buf, int len)
|
|||||||
static void
|
static void
|
||||||
Usage(void)
|
Usage(void)
|
||||||
{
|
{
|
||||||
errx(EX_USAGE, "usage: nghook [-da] path [hookname]");
|
errx(EX_USAGE, "usage: nghook [-adln] path [hookname]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ node
|
|||||||
.Op Fl a
|
.Op Fl a
|
||||||
.Op Fl d
|
.Op Fl d
|
||||||
.Op Fl l
|
.Op Fl l
|
||||||
|
.Op Fl n
|
||||||
.Ar path
|
.Ar path
|
||||||
.Op Ar hookname
|
.Op Ar hookname
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
@ -65,18 +66,27 @@ is assumed.
|
|||||||
At this point all data written to standard input is sent
|
At this point all data written to standard input is sent
|
||||||
to the node and all data received from the node is relayed
|
to the node and all data received from the node is relayed
|
||||||
to standard output.
|
to standard output.
|
||||||
|
.Nm
|
||||||
|
exits when
|
||||||
|
.Dv EOF
|
||||||
|
is detected on standard input.
|
||||||
.Pp
|
.Pp
|
||||||
The options are as follows:
|
The options are as follows:
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width indent
|
.Bl -tag -width indent
|
||||||
.It Fl a
|
.It Fl a
|
||||||
Output each read packet in
|
Output each packet read in human-readable decoded
|
||||||
.Tn ASCII .
|
.Tn ASCII
|
||||||
|
form instead of raw binary.
|
||||||
.It Fl d
|
.It Fl d
|
||||||
Increase the debugging verbosity level.
|
Increase the debugging verbosity level.
|
||||||
.It Fl l
|
.It Fl l
|
||||||
Loops all received data back to the hook in addition to writing it
|
Loops all received data back to the hook in addition to writing it
|
||||||
to standard output.
|
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
|
.El
|
||||||
.Sh BUGS
|
.Sh BUGS
|
||||||
Although all input is read in unbuffered mode,
|
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
|
.Sh SEE ALSO
|
||||||
.Xr netgraph 4 ,
|
.Xr netgraph 4 ,
|
||||||
.Xr netgraph 3 ,
|
.Xr netgraph 3 ,
|
||||||
.Xr ngctl 8 .
|
.Xr ngctl 8
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
The
|
The
|
||||||
.Em netgraph
|
.Em netgraph
|
||||||
@ -92,5 +102,5 @@ system was designed and first implemented at Whistle Communications, Inc.
|
|||||||
in a version of
|
in a version of
|
||||||
.Fx 2.2
|
.Fx 2.2
|
||||||
customized for the Whistle InterJet.
|
customized for the Whistle InterJet.
|
||||||
.Sh AUTHOR
|
.Sh AUTHORS
|
||||||
.An Archie Cobbs Aq archie@whistle.com
|
.An Archie Cobbs Aq archie@whistle.com
|
||||||
|
Loading…
Reference in New Issue
Block a user