Better name for fdmaskp, reduce the scope of some variables, don't abuse
authorjca <jca@openbsd.org>
Wed, 23 Apr 2014 18:16:36 +0000 (18:16 +0000)
committerjca <jca@openbsd.org>
Wed, 23 Apr 2014 18:16:36 +0000 (18:16 +0000)
cc for poll()'s return value, and indent decls.  ok florian@

sbin/ping/ping.c
sbin/ping6/ping6.c

index b6f18be..7a02f7f 100644 (file)
@@ -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) {
index a0cb298..701bc0a 100644 (file)
@@ -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;