summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhugh <>2002-05-30 09:37:38 +0000
committerhugh <>2002-05-30 09:37:38 +0000
commite5dd640096925637a0dd19991130c58a8a39dcea (patch)
tree25114c6253ff72cb89e3fa7d0dd6a34cb8e5b8c1 /src
parentcbe7e59bea91cecb23d39ad01809b3639a007194 (diff)
downloadopenbsd-e5dd640096925637a0dd19991130c58a8a39dcea.tar.gz
openbsd-e5dd640096925637a0dd19991130c58a8a39dcea.tar.bz2
openbsd-e5dd640096925637a0dd19991130c58a8a39dcea.zip
Avoid spinning poll, and while we're at it more closely reproduce the
original netcat's timeout behaviour. Theo says go.
Diffstat (limited to 'src')
-rw-r--r--src/usr.bin/nc/netcat.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index 3a1e9c1193..67e33de490 100644
--- a/src/usr.bin/nc/netcat.c
+++ b/src/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: netcat.c,v 1.48 2002/05/29 09:23:25 deraadt Exp $ */ 1/* $OpenBSD: netcat.c,v 1.49 2002/05/30 09:37:38 hugh Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * 4 *
@@ -66,7 +66,7 @@ int vflag; /* Verbosity */
66int xflag; /* Socks proxy */ 66int xflag; /* Socks proxy */
67int zflag; /* Port Scan Flag */ 67int zflag; /* Port Scan Flag */
68 68
69int timeout; 69int timeout = -1;
70int family = AF_UNSPEC; 70int family = AF_UNSPEC;
71char *portlist[PORT_MAX]; 71char *portlist[PORT_MAX];
72 72
@@ -160,6 +160,9 @@ main(int argc, char *argv[])
160 timeout = (int)strtoul(optarg, &endp, 10); 160 timeout = (int)strtoul(optarg, &endp, 10);
161 if (timeout < 0 || *endp != '\0') 161 if (timeout < 0 || *endp != '\0')
162 errx(1, "timeout cannot be negative"); 162 errx(1, "timeout cannot be negative");
163 if (timeout >= (INT_MAX / 1000))
164 errx(1, "timeout too large");
165 timeout *= 1000;
163 break; 166 break;
164 case 'x': 167 case 'x':
165 xflag = 1; 168 xflag = 1;
@@ -548,13 +551,16 @@ readwrite(int nfd)
548 if (iflag) 551 if (iflag)
549 sleep(iflag); 552 sleep(iflag);
550 553
551 if (poll(pfd, 2, timeout) < 0) { 554 if ((n = poll(pfd, 2, timeout)) < 0) {
552 close(nfd); 555 close(nfd);
553 close(wfd); 556 close(wfd);
554 free(pfd); 557 free(pfd);
555 errx(1, "Polling Error"); 558 errx(1, "Polling Error");
556 } 559 }
557 560
561 if (n == 0)
562 return;
563
558 if (pfd[0].revents & POLLIN) { 564 if (pfd[0].revents & POLLIN) {
559 if ((n = read(nfd, buf, sizeof(buf))) <= 0) { 565 if ((n = read(nfd, buf, sizeof(buf))) <= 0) {
560 return; 566 return;