- while (! timer_expired &&
- (result = recvfrom(pi->icmpsock, packet, sizeof(packet),
- 0, &from, &fromlen)) > 0) {
+ while (! timer_expired) {
+ tv.tv_usec=pi->timeout;
+ tv.tv_sec=0;
+#if 0
+ /* This breaks on BSD, which uses bzero() in the definition of FD_ZERO */
+ FD_ZERO(&rfds);
+#else
+ memset (&rfds, 0, sizeof(rfds));
+#endif
+ FD_SET(pi->icmpsock,&rfds);
+ /* only wait a little while, in case we raced with the timer expiration.
+ From Valentijn Sessink <valentyn@openoffice.nl> */
+ if (select(pi->icmpsock+1, &rfds, NULL, NULL, &tv) >0) {
+ result = recvfrom(pi->icmpsock, packet, sizeof(packet),
+ 0, &from, &fromlen);