diff options
-rw-r--r-- | sbin/ping/ping.c | 29 | ||||
-rw-r--r-- | sbin/ping6/ping6.c | 28 |
2 files changed, 31 insertions, 26 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index b6f18bedeb8..7a02f7fa9d1 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping.c,v 1.101 2014/04/23 12:27:31 florian Exp $ */ +/* $OpenBSD: ping.c,v 1.102 2014/04/23 18:16:36 jca Exp $ */ /* $NetBSD: ping.c,v 1.20 1995/08/11 22:37:58 cgd Exp $ */ /* @@ -178,10 +178,8 @@ main(int argc, char *argv[]) { struct hostent *hp; struct sockaddr_in *to; - struct pollfd fdmaskp[1]; struct in_addr saddr; - int i, ch, hold = 1, packlen, preload, maxsize, df = 0, tos = 0; - int timeout; + int ch, hold = 1, i, packlen, preload, maxsize, df = 0, tos = 0; u_char *datap, *packet, ttl = MAXTTL, loop = 1; char *target, hnamebuf[MAXHOSTNAMELEN]; #ifdef IP_OPTIONS @@ -508,27 +506,32 @@ main(int argc, char *argv[]) catcher(0); /* start things going */ for (;;) { - struct sockaddr_in from; - sigset_t omask, nmask; - socklen_t fromlen; - int cc; + struct sockaddr_in from; + sigset_t omask, nmask; + socklen_t fromlen; + struct pollfd pfd; + ssize_t cc; + int ret, timeout; if (options & F_FLOOD) { pinger(); timeout = 10; } else timeout = INFTIM; - fdmaskp[0].fd = s; - fdmaskp[0].events = POLLIN; - cc = poll(fdmaskp, 1, timeout); - if (cc < 0) { + + pfd.fd = s; + pfd.events = POLLIN; + + ret = poll(&pfd, 1, timeout); + if (ret < 0) { if (errno != EINTR) { warn("poll"); sleep(1); } continue; - } else if (cc == 0) + } else if (ret == 0) continue; + fromlen = sizeof(from); if ((cc = recvfrom(s, packet, packlen, 0, (struct sockaddr *)&from, &fromlen)) < 0) { diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index a0cb298a145..701bc0a934a 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.88 2014/01/10 21:57:44 florian Exp $ */ +/* $OpenBSD: ping6.c,v 1.89 2014/04/23 18:16:36 jca Exp $ */ /* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */ /* @@ -250,11 +250,8 @@ main(int argc, char *argv[]) { struct itimerval itimer; struct sockaddr_in6 from; - int timeout; struct addrinfo hints; - struct pollfd fdmaskp[1]; - int cc, i; - int ch, hold, packlen, preload, optval, ret_ga; + int ch, hold, i, packlen, preload, optval, ret_ga; u_char *datap, *packet; char *e, *target, *ifname = NULL, *gateway = NULL; const char *errstr; @@ -887,12 +884,15 @@ main(int argc, char *argv[]) #endif for (;;) { - struct msghdr m; + struct msghdr m; union { struct cmsghdr hdr; u_char buf[CMSG_SPACE(1024)]; - } cmsgbuf; - struct iovec iov[2]; + } cmsgbuf; + struct iovec iov[2]; + struct pollfd pfd; + ssize_t cc; + int ret, timeout; /* signal handling */ if (seenalrm) { @@ -918,16 +918,18 @@ main(int argc, char *argv[]) timeout = 10; } else timeout = INFTIM; - fdmaskp[0].fd = s; - fdmaskp[0].events = POLLIN; - cc = poll(fdmaskp, 1, timeout); - if (cc < 0) { + + pfd.fd = s; + pfd.events = POLLIN; + + ret = poll(&pfd, 1, timeout); + if (ret < 0) { if (errno != EINTR) { warn("poll"); sleep(1); } continue; - } else if (cc == 0) + } else if (ret == 0) continue; m.msg_name = &from; |