j...@wxcvbn.org (Jérémie Courrèges-Anglas) writes:

> Florian Obser <flor...@openbsd.org> writes:
>
>> On Tue, Apr 22, 2014 at 03:08:45PM -0400, pe...@petermalone.org wrote:
>>> Thanks Florian & team.
>>> 
>>> Please review the following diff.
>>
>> tab vs. space, more in sync with ping6
>> OK?
>
> ok.

Some changes I'd like:
- I find fdmaskp badly named, a remnant of when select was used
- recvfrom returns an ssize_t, cc shouldn't be (ab)used for poll's
  return value.
- the scope of cc, fdmaskp/pfd and timeout can be reduced
- add a bit more of whitespace to make things more readable

Index: ping/ping.c
===================================================================
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.101
diff -u -p -r1.101 ping.c
--- ping/ping.c 23 Apr 2014 12:27:31 -0000      1.101
+++ ping/ping.c 23 Apr 2014 13:01:01 -0000
@@ -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
@@ -509,26 +507,31 @@ main(int argc, char *argv[])
 
        for (;;) {
                struct sockaddr_in from;
-               sigset_t omask, nmask;
-               socklen_t fromlen;
-               int cc;
+               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: ping6/ping6.c
===================================================================
RCS file: /cvs/src/sbin/ping6/ping6.c,v
retrieving revision 1.88
diff -u -p -r1.88 ping6.c
--- ping6/ping6.c       10 Jan 2014 21:57:44 -0000      1.88
+++ ping6/ping6.c       23 Apr 2014 13:01:07 -0000
@@ -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;


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to