aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2008-11-18 22:17:43 -0600
committerRob Landley <rob@landley.net>2008-11-18 22:17:43 -0600
commit7dbbe0d9ddc3d1b43b6699dc3c9cdd8a7b61851e (patch)
tree49aca5a645eea6b4ca3a03af7b063cd3b962a7c3
parent206a832f21f7b28f32127812da5ea764f8dd2644 (diff)
downloadtoybox-7dbbe0d9ddc3d1b43b6699dc3c9cdd8a7b61851e.tar.gz
More than 4k of input can be queued up in a pipe, so loop needs to continue reading until POLLIN is exhausted before acknowledging POLLHUP.
-rw-r--r--toys/netcat.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/toys/netcat.c b/toys/netcat.c
index 0ed2a36a..82039a91 100644
--- a/toys/netcat.c
+++ b/toys/netcat.c
@@ -93,6 +93,7 @@ void netcat_main(void)
int sockfd=-1, pollcount=2;
struct pollfd pollfds[2];
+ memset(pollfds, 0, 2*sizeof(struct pollfd));
pollfds[0].events = pollfds[1].events = POLLIN;
set_alarm(TT.wait);
@@ -108,8 +109,6 @@ void netcat_main(void)
int temp;
struct sockaddr_in address;
- pollfds[1].fd = 0;
-
// Setup socket
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (-1 == sockfd) perror_exit("socket");
@@ -212,8 +211,7 @@ void netcat_main(void)
int len = read(pollfds[i].fd, toybuf, sizeof(toybuf));
if (len<1) goto dohupnow;
xwrite(i ? pollfds[0].fd : 1, toybuf, len);
- }
- if (pollfds[i].revents & POLLHUP) {
+ } else if (pollfds[i].revents & POLLHUP) {
dohupnow:
// Close half-connection. This is needed for things like
// "echo GET / | netcat landley.net 80"