summaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
authorDenis Vlasenko2007-09-07 13:43:28 +0000
committerDenis Vlasenko2007-09-07 13:43:28 +0000
commit87f3b26b3a17369c12f4f9a70d6845796f8648d6 (patch)
tree2f7fe9fc910d5e97f695c902f848db497fec8bfd /networking/udhcp
parent40f0bcf9d3f8f8a8d14a9b2cff51761019c75cf4 (diff)
downloadbusybox-87f3b26b3a17369c12f4f9a70d6845796f8648d6.zip
busybox-87f3b26b3a17369c12f4f9a70d6845796f8648d6.tar.gz
*: replace select-for-one descriptor with poll, it's smaller.
$ ./.cmk bloatcheck function old new delta readit 406 364 -42 syslogd_main 1249 1206 -43 traceroute_main 4115 4060 -55 mysleep 112 45 -67 arpping 579 441 -138 tftp 1575 1182 -393 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-738) Total: -738 bytes text data bss dec hex filename 770580 1051 10764 782395 bf03b busybox_old 769820 1051 10764 781635 bed43 busybox_unstripped
Diffstat (limited to 'networking/udhcp')
-rw-r--r--networking/udhcp/arpping.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c
index 4ac52c6..3351807 100644
--- a/networking/udhcp/arpping.c
+++ b/networking/udhcp/arpping.c
@@ -37,14 +37,12 @@ struct arpMsg {
int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface)
{
- int timeout = 2;
- int s; /* socket */
+ int timeout_ms = 2000;
+ struct pollfd pfd[1];
+#define s (pfd[0].fd) /* socket */
int rv = 1; /* "no reply received" yet */
struct sockaddr addr; /* for interface name */
struct arpMsg arp;
- fd_set fdset;
- struct timeval tm;
- unsigned prevTime;
s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP));
if (s == -1) {
@@ -80,18 +78,17 @@ int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *i
/* wait for arp reply, and check it */
do {
int r;
- prevTime = monotonic_sec();
- FD_ZERO(&fdset);
- FD_SET(s, &fdset);
- tm.tv_sec = timeout;
- tm.tv_usec = 0;
- r = select(s + 1, &fdset, NULL, NULL, &tm);
+ unsigned prevTime = monotonic_us();
+
+ pfd[0].events = POLLIN;
+ r = poll(pfd, 1, timeout_ms);
if (r < 0) {
- bb_perror_msg("error on ARPING request");
- if (errno != EINTR)
+ if (errno != EINTR) {
+ bb_perror_msg("poll");
break;
+ }
} else if (r) {
- if (recv(s, &arp, sizeof(arp), 0) < 0)
+ if (read(s, &arp, sizeof(arp)) < 0)
break;
if (arp.operation == htons(ARPOP_REPLY)
&& 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
break;
}
}
- timeout -= monotonic_sec() - prevTime;
- } while (timeout > 0);
+ timeout_ms -= (monotonic_us() - prevTime) / 1000;
+ } while (timeout_ms > 0);
ret:
close(s);