/* vi: set sw=4 ts=4: */
/*
- * arpping.c
- *
* Mostly stolen from: dhcpcd - DHCP client daemon
* by Yoichi Hariguchi <yoichi@fore.com>
*
- * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
*/
#include <netinet/if_ether.h>
#include <net/if_arp.h>
/* wait for arp reply, and check it */
timeout_ms = 2000;
do {
+ typedef uint32_t aliased_uint32_t FIX_ALIASING;
int r;
- unsigned prevTime = monotonic_us();
+ unsigned prevTime = monotonic_ms();
pfd[0].events = POLLIN;
r = safe_poll(pfd, 1, timeout_ms);
&& arp.operation == htons(ARPOP_REPLY)
/* don't check it: Linux doesn't return proper tHaddr (fixed in 2.6.24?) */
/* && memcmp(arp.tHaddr, from_mac, 6) == 0 */
- && *((uint32_t *) arp.sInaddr) == test_nip
+ && *(aliased_uint32_t*)arp.sInaddr == test_nip
) {
/* if ARP source MAC matches safe_mac
* (which is client's MAC), then it's not a conflict
break;
}
}
- timeout_ms -= ((unsigned)monotonic_us() - prevTime) / 1000;
- } while (timeout_ms > 0);
+ timeout_ms -= (unsigned)monotonic_ms() - prevTime + 1;
+
+ /* We used to check "timeout_ms > 0", but
+ * this is more under/overflow-resistant
+ * (people did see overflows here when system time jumps):
+ */
+ } while ((unsigned)timeout_ms <= 2000);
ret:
close(s);