+ /* Set up timeout */
+ timeout.tv_sec = (time_t) obj->timeout;
+ timeout.tv_usec = (suseconds_t) (1000000 * (obj->timeout - ((double) timeout.tv_sec)));
+
+ dprintf ("Set timeout to %i.%06i seconds\n",
+ (int) timeout.tv_sec,
+ (int) timeout.tv_usec);
+
+ ping_timeval_add (&nowtime, &timeout, &endtime);
+
+ ptr = ph;
+ num_fds = 0;
+ if (fd4 != -1) num_fds++;
+ if (fd6 != -1) num_fds++;
+ max_fd = fd4 > fd6 ? fd4 : fd6;
+
+ while (pings > 0 || ptr != NULL)
+ {
+ FD_ZERO (&read_fds);
+ FD_ZERO (&write_fds);
+ FD_ZERO (&err_fds);
+
+ if (fd4 != -1) FD_SET(fd4, &read_fds);
+ if (fd6 != -1) FD_SET(fd6, &read_fds);
+
+ if (fd4 != -1 && ptr != NULL && ptr->addrfamily == AF_INET)
+ FD_SET(fd4, &write_fds);
+ if (fd6 != -1 && ptr != NULL && ptr->addrfamily == AF_INET6)
+ FD_SET(fd6, &write_fds);
+ if (fd4 != -1) FD_SET(fd4, &err_fds);
+ if (fd6 != -1) FD_SET(fd6, &err_fds);
+
+ if (gettimeofday (&nowtime, NULL) == -1)
+ {
+ ping_set_errno (obj, errno);
+ return (-1);
+ }
+
+ if (ping_timeval_sub (&endtime, &nowtime, &timeout) == -1)
+ break;
+
+ dprintf ("Waiting on %i sockets for %i.%06i seconds\n", num_fds,
+ (int) timeout.tv_sec,
+ (int) timeout.tv_usec);
+
+ status = select (max_fd + 1, &read_fds, &write_fds, &err_fds, &timeout);
+
+ if (gettimeofday (&nowtime, NULL) == -1)
+ {
+ ping_set_errno (obj, errno);
+ return (-1);
+ }
+
+ if ((status == -1) && (errno == EINTR))
+ {
+ dprintf ("select was interrupted by signal..\n");
+ continue;
+ }
+ else if (status < 0)
+ {
+#if WITH_DEBUG
+ char errbuf[PING_ERRMSG_LEN];
+ dprintf ("select: %s\n",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+#endif
+ break;
+ }
+ else if (status == 0)
+ {
+ dprintf ("select timed out\n");
+ for (ptr = ph; ptr != NULL; ptr = ptr->next)
+ if (ptr->latency < 0.0)
+ ptr->dropped++;
+
+ break;
+ }
+
+ if (fd4 != -1)
+ {
+ if (FD_ISSET (fd4, &read_fds))
+ {
+ if (!ping_receive_one(obj, &nowtime, AF_INET))
+ --pings;
+ }
+ else if (ptr != NULL && ptr->addrfamily == AF_INET &&
+ FD_ISSET (fd4, &write_fds))
+ {
+ if (!ping_send_one(obj, ptr, fd4))
+ {
+ ptr = ptr->next;
+ ++pings;
+ }
+ else
+ {
+ --ret;
+ }
+ }
+
+ }
+
+ if (fd6 != -1)
+ {
+ if (FD_ISSET (fd6, &read_fds))
+ {
+ if (!ping_receive_one(obj, &nowtime, AF_INET6))
+ --pings;
+ }
+ else if (ptr != NULL && ptr->addrfamily == AF_INET6 &&
+ FD_ISSET (fd6, &write_fds))
+ {
+ if (!ping_send_one(obj, ptr, fd6))
+ {
+ ++pings;
+ ptr = ptr->next;
+ }
+ else
+ {
+ --ret;
+ }
+ }
+ }
+
+ } /* while (1) */