diff options
Diffstat (limited to 'networking/udhcp/arpping.c')
-rw-r--r-- | networking/udhcp/arpping.c | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c index 4ac52c640..33518077b 100644 --- a/networking/udhcp/arpping.c +++ b/networking/udhcp/arpping.c | |||
@@ -37,14 +37,12 @@ struct arpMsg { | |||
37 | 37 | ||
38 | int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface) | 38 | int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface) |
39 | { | 39 | { |
40 | int timeout = 2; | 40 | int timeout_ms = 2000; |
41 | int s; /* socket */ | 41 | struct pollfd pfd[1]; |
42 | #define s (pfd[0].fd) /* socket */ | ||
42 | int rv = 1; /* "no reply received" yet */ | 43 | int rv = 1; /* "no reply received" yet */ |
43 | struct sockaddr addr; /* for interface name */ | 44 | struct sockaddr addr; /* for interface name */ |
44 | struct arpMsg arp; | 45 | struct arpMsg arp; |
45 | fd_set fdset; | ||
46 | struct timeval tm; | ||
47 | unsigned prevTime; | ||
48 | 46 | ||
49 | s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); | 47 | s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); |
50 | if (s == -1) { | 48 | if (s == -1) { |
@@ -80,18 +78,17 @@ int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *i | |||
80 | /* wait for arp reply, and check it */ | 78 | /* wait for arp reply, and check it */ |
81 | do { | 79 | do { |
82 | int r; | 80 | int r; |
83 | prevTime = monotonic_sec(); | 81 | unsigned prevTime = monotonic_us(); |
84 | FD_ZERO(&fdset); | 82 | |
85 | FD_SET(s, &fdset); | 83 | pfd[0].events = POLLIN; |
86 | tm.tv_sec = timeout; | 84 | r = poll(pfd, 1, timeout_ms); |
87 | tm.tv_usec = 0; | ||
88 | r = select(s + 1, &fdset, NULL, NULL, &tm); | ||
89 | if (r < 0) { | 85 | if (r < 0) { |
90 | bb_perror_msg("error on ARPING request"); | 86 | if (errno != EINTR) { |
91 | if (errno != EINTR) | 87 | bb_perror_msg("poll"); |
92 | break; | 88 | break; |
89 | } | ||
93 | } else if (r) { | 90 | } else if (r) { |
94 | if (recv(s, &arp, sizeof(arp), 0) < 0) | 91 | if (read(s, &arp, sizeof(arp)) < 0) |
95 | break; | 92 | break; |
96 | if (arp.operation == htons(ARPOP_REPLY) | 93 | if (arp.operation == htons(ARPOP_REPLY) |
97 | && memcmp(arp.tHaddr, from_mac, 6) == 0 | 94 | && memcmp(arp.tHaddr, from_mac, 6) == 0 |
@@ -101,8 +98,8 @@ int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *i | |||
101 | break; | 98 | break; |
102 | } | 99 | } |
103 | } | 100 | } |
104 | timeout -= monotonic_sec() - prevTime; | 101 | timeout_ms -= (monotonic_us() - prevTime) / 1000; |
105 | } while (timeout > 0); | 102 | } while (timeout_ms > 0); |
106 | 103 | ||
107 | ret: | 104 | ret: |
108 | close(s); | 105 | close(s); |