Skip to content

Commit

Permalink
Change -o to uncollated, add -O for collated.
Browse files Browse the repository at this point in the history
  • Loading branch information
landley committed May 17, 2024
1 parent 9c3eb4b commit a21961f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions toys/net/netcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* TODO: genericize for telnet/microcom/tail-f, fix -t with login_tty()
USE_NETCAT(NEWTOY(netcat, "^tElLw#<1W#<1p#<1>65535q#<1o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U]", TOYFLAG_BIN))
USE_NETCAT(NEWTOY(netcat, "^tElLw#<1W#<1p#<1>65535q#<1O:o:s:f:46uUnz[!tlL][!Lw][!Lu][!46U][!oO]", TOYFLAG_BIN))
USE_NETCAT(OLDTOY(nc, netcat, TOYFLAG_USR|TOYFLAG_BIN))
config NETCAT
Expand All @@ -23,6 +23,7 @@ config NETCAT
-l Listen for one incoming connection, then exit
-n No DNS lookup
-o Hex dump to FILE (-o- writes hex only to stdout)
-O Hex dump to FILE (collated)
-p Local port number
-q Quit SECONDS after EOF on stdin, even if stdout hasn't closed yet
-s Local source address
Expand All @@ -49,7 +50,7 @@ config NETCAT
#include "toys.h"

GLOBALS(
char *f, *s, *o;
char *f, *s, *o, *O;
long q, p, W, w;

unsigned ofd, olast, opos, ocount[2];
Expand Down Expand Up @@ -113,7 +114,7 @@ void ohexwrite(int fd, void *buf, size_t len)
memcpy(TT.obuf+TT.opos, buf+i, j);
TT.opos += j;
i += j;
if (TT.opos == 16) oflush();
if (TT.opos==16 || !TT.O) oflush();
}

// Don't write data to stdout when -o goes to stdout.
Expand All @@ -132,6 +133,7 @@ void netcat_main(void)
pid_t child;

// -o - disables normal writes to stdout, just gives hex dump.
if (TT.O) TT.o = TT.O;
if (TT.o) {
if (!strcmp(TT.o, "-")) TT.ofd = 1;
else TT.ofd = xcreate(TT.o, O_CREAT|O_TRUNC|O_WRONLY, 0666);
Expand Down

0 comments on commit a21961f

Please sign in to comment.