still ok

Florian Obser([email protected]) on 2020.10.20 21:36:06 +0200:
> On Tue, Oct 20, 2020 at 01:11:09PM -0600, Theo de Raadt wrote:
> > I believe most of the new local variables you added in main,
> > can instead be added in the flush loop you wrote, even if you
> > have to instantiate them.  Or move it into a new function,
> > then it is even easier.  their scope is just too large...
> 
> Sure, I'd like to go with this for now and then refactor main later
> and split it into functions. It's always a pain to find the spot where
> it does anything...
> 
> diff --git ping.c ping.c
> index d198d233921..7cca8c70342 100644
> --- ping.c
> +++ ping.c
> @@ -786,6 +786,55 @@ main(int argc, char *argv[])
>       smsghdr.msg_iov = &smsgiov;
>       smsghdr.msg_iovlen = 1;
>  
> +     /* Drain our socket. */
> +     (void)signal(SIGALRM, onsignal);
> +     memset(&itimer, 0, sizeof(itimer));
> +     itimer.it_value.tv_sec = 1; /* make sure we don't get stuck */
> +     (void)setitimer(ITIMER_REAL, &itimer, NULL);
> +     for (;;) {
> +             struct msghdr           m;
> +             union {
> +                     struct cmsghdr hdr;
> +                     u_char buf[CMSG_SPACE(1024)];
> +             }                       cmsgbuf;
> +             struct iovec            iov[1];
> +             struct pollfd           pfd;
> +             struct sockaddr_in      peer4;
> +             struct sockaddr_in6     peer6;
> +             ssize_t                 cc;
> +
> +             if (seenalrm)
> +                     break;
> +
> +             pfd.fd = s;
> +             pfd.events = POLLIN;
> +
> +             if (poll(&pfd, 1, 0) <= 0)
> +                     break;
> +
> +             if (v6flag) {
> +                     m.msg_name = &peer6;
> +                     m.msg_namelen = sizeof(peer6);
> +             } else {
> +                     m.msg_name = &peer4;
> +                     m.msg_namelen = sizeof(peer4);
> +             }
> +             memset(&iov, 0, sizeof(iov));
> +             iov[0].iov_base = (caddr_t)packet;
> +             iov[0].iov_len = packlen;
> +
> +             m.msg_iov = iov;
> +             m.msg_iovlen = 1;
> +             m.msg_control = (caddr_t)&cmsgbuf.buf;
> +             m.msg_controllen = sizeof(cmsgbuf.buf);
> +
> +             cc = recvmsg(s, &m, 0);
> +             if (cc == -1 && errno != EINTR)
> +                     break;
> +     }
> +     memset(&itimer, 0, sizeof(itimer));
> +     (void)setitimer(ITIMER_REAL, &itimer, NULL);
> +
>       while (preload--)               /* Fire off them quickies. */
>               pinger(s);
>  
> 
> 
> -- 
> I'm not entirely sure you are real.
> 

Reply via email to