diff options
author | Josh Gao <jmgao@google.com> | 2017-06-09 10:51:18 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2017-07-21 13:43:29 -0500 |
commit | 67bf48c1cb3ed55249c27e6f02f5c938b20e027d (patch) | |
tree | c11174ecd9eaf81ed92499d16c48d5b2ec4ef486 /toys | |
parent | 8d6d9bf4f1a3caa0decb058dece8c4b4bd463e4a (diff) | |
download | toybox-67bf48c1cb3ed55249c27e6f02f5c938b20e027d.tar.gz |
netcat: make -l exit after handling a request.
Bug: http://b/62305466
Diffstat (limited to 'toys')
-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); |