diff options
Diffstat (limited to 'toys/net')
-rw-r--r-- | toys/net/netcat.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/toys/net/netcat.c b/toys/net/netcat.c index 13ba3114..795f7b3c 100644 --- a/toys/net/netcat.c +++ b/toys/net/netcat.c @@ -126,11 +126,15 @@ void netcat_main(void) // TODO xconnect if (connect(sockfd, (struct sockaddr *)address, sizeof(*address))<0) perror_exit("connect"); - in1 = out2 = sockfd; - // Listen for incoming connections + // We have a connection. Disarm timeout. + set_alarm(0); + + in1 = out2 = sockfd; + pollinate(in1, in2, out1, out2, TT.idle, TT.quit_delay); } else { + // Listen for incoming connections socklen_t len = sizeof(*address); if (listen(sockfd, 5)) error_exit("listen"); @@ -143,7 +147,7 @@ void netcat_main(void) if (CFG_TOYBOX_FORK && toys.optc && xfork()) goto cleanup; } - for (;;) { + do { child = 0; len = sizeof(*address); // gcc's insane optimizer can overwrite this in1 = out2 = accept(sockfd, (struct sockaddr *)address, &len); @@ -189,15 +193,10 @@ void netcat_main(void) pollinate(in1, in2, out1, out2, TT.idle, TT.quit_delay); close(in1); - } + } while (!(toys.optflags&FLAG_l)); } } - // We have a connection. Disarm timeout. - set_alarm(0); - - pollinate(in1, in2, out1, out2, TT.idle, TT.quit_delay); - cleanup: if (CFG_TOYBOX_FREE) { close(in1); |