aboutsummaryrefslogtreecommitdiff
path: root/toys/netcat.c
diff options
context:
space:
mode:
Diffstat (limited to 'toys/netcat.c')
-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"