X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Fudhcp%2Farpping.c;h=587339f9b1c1137942d9d2763ded1782c9b43545;hb=e40c04b82695c1cde8ad9ed1e2aa1756463d73a7;hp=e20395a9e874d573d8c9685f17b520c9fa3d540b;hpb=24833430bc2dbea733c3b0b9ea6c6b976f95474a;p=oweals%2Fbusybox.git diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c index e20395a9e..587339f9b 100644 --- a/networking/udhcp/arpping.c +++ b/networking/udhcp/arpping.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* * arpping.c * @@ -5,7 +6,6 @@ * by Yoichi Hariguchi */ -#include #include #include #include @@ -23,17 +23,17 @@ * ip - our ip * mac - our arp address * interface - interface to use - * retn: 1 addr free + * retn: 1 addr free * 0 addr used - * -1 error - */ + * -1 error + */ /* FIXME: match response against chaddr */ -int arpping(u_int32_t yiaddr, u_int32_t ip, unsigned char *mac, char *interface) +int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface) { int timeout = 2; - int optval = 1; + int optval = 1; int s; /* socket */ int rv = 1; /* return value */ struct sockaddr addr; /* for interface name */ @@ -43,22 +43,22 @@ int arpping(u_int32_t yiaddr, u_int32_t ip, unsigned char *mac, char *interface) time_t prevTime; - if ((s = socket (PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) == -1) { - LOG(LOG_ERR, bb_msg_can_not_create_raw_socket); + if ((s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) == -1) { + bb_perror_msg(bb_msg_can_not_create_raw_socket); return -1; } - + if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) { - LOG(LOG_ERR, "Could not setsocketopt on raw socket"); + bb_perror_msg("Could not setsocketopt on raw socket"); close(s); return -1; } /* send arp request */ memset(&arp, 0, sizeof(arp)); - memcpy(arp.ethhdr.h_dest, MAC_BCAST_ADDR, 6); /* MAC DA */ - memcpy(arp.ethhdr.h_source, mac, 6); /* MAC SA */ - arp.ethhdr.h_proto = htons(ETH_P_ARP); /* protocol type (Ethernet) */ + memcpy(arp.h_dest, MAC_BCAST_ADDR, 6); /* MAC DA */ + memcpy(arp.h_source, mac, 6); /* MAC SA */ + arp.h_proto = htons(ETH_P_ARP); /* protocol type (Ethernet) */ arp.htype = htons(ARPHRD_ETHER); /* hardware type */ arp.ptype = htons(ETH_P_IP); /* protocol type (ARP message) */ arp.hlen = 6; /* hardware address length */ @@ -67,36 +67,36 @@ int arpping(u_int32_t yiaddr, u_int32_t ip, unsigned char *mac, char *interface) memcpy(arp.sInaddr, &ip, sizeof(ip)); /* source IP address */ memcpy(arp.sHaddr, mac, 6); /* source hardware address */ memcpy(arp.tInaddr, &yiaddr, sizeof(yiaddr)); /* target IP address */ - + memset(&addr, 0, sizeof(addr)); strcpy(addr.sa_data, interface); if (sendto(s, &arp, sizeof(arp), 0, &addr, sizeof(addr)) < 0) rv = 0; - + /* wait arp reply, and check it */ tm.tv_usec = 0; - time(&prevTime); + prevTime = uptime(); while (timeout > 0) { FD_ZERO(&fdset); FD_SET(s, &fdset); tm.tv_sec = timeout; if (select(s + 1, &fdset, (fd_set *) NULL, (fd_set *) NULL, &tm) < 0) { - DEBUG(LOG_ERR, "Error on ARPING request: %m"); + bb_perror_msg("Error on ARPING request"); if (errno != EINTR) rv = 0; } else if (FD_ISSET(s, &fdset)) { if (recv(s, &arp, sizeof(arp), 0) < 0 ) rv = 0; - if (arp.operation == htons(ARPOP_REPLY) && - bcmp(arp.tHaddr, mac, 6) == 0 && - *((u_int *) arp.sInaddr) == yiaddr) { - DEBUG(LOG_INFO, "Valid arp reply receved for this address"); + if (arp.operation == htons(ARPOP_REPLY) && + memcmp(arp.tHaddr, mac, 6) == 0 && + *((uint32_t *) arp.sInaddr) == yiaddr) { + DEBUG("Valid arp reply received for this address"); rv = 0; break; } } - timeout -= time(NULL) - prevTime; - time(&prevTime); + timeout -= uptime() - prevTime; + prevTime = uptime(); } close(s); - DEBUG(LOG_INFO, "%salid arp replies for this address", rv ? "No v" : "V"); + DEBUG("%salid arp replies for this address", rv ? "No v" : "V"); return rv; }