diff options
author | Mike Frysinger <vapier@gentoo.org> | 2006-03-23 23:44:29 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2006-03-23 23:44:29 +0000 |
commit | 787140df3992ccc3ebdc09f6d2dcb584f580f49f (patch) | |
tree | 666fdb071676c676f52bdc204f6df801b17e7196 /networking/udhcp/arpping.c | |
parent | e0fe93759339a9e043cd0489f5bfabd59b5fcb78 (diff) | |
download | busybox-w32-787140df3992ccc3ebdc09f6d2dcb584f580f49f.tar.gz busybox-w32-787140df3992ccc3ebdc09f6d2dcb584f580f49f.tar.bz2 busybox-w32-787140df3992ccc3ebdc09f6d2dcb584f580f49f.zip |
remove in place of external link
Diffstat (limited to 'networking/udhcp/arpping.c')
-rw-r--r-- | networking/udhcp/arpping.c | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c deleted file mode 100644 index 4831d4371..000000000 --- a/networking/udhcp/arpping.c +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | /* | ||
2 | * arpping.c | ||
3 | * | ||
4 | * Mostly stolen from: dhcpcd - DHCP client daemon | ||
5 | * by Yoichi Hariguchi <yoichi@fore.com> | ||
6 | */ | ||
7 | |||
8 | #include <sys/time.h> | ||
9 | #include <time.h> | ||
10 | #include <sys/socket.h> | ||
11 | #include <netinet/if_ether.h> | ||
12 | #include <net/if_arp.h> | ||
13 | #include <netinet/in.h> | ||
14 | #include <string.h> | ||
15 | #include <unistd.h> | ||
16 | #include <errno.h> | ||
17 | |||
18 | #include "dhcpd.h" | ||
19 | #include "arpping.h" | ||
20 | #include "common.h" | ||
21 | |||
22 | /* args: yiaddr - what IP to ping | ||
23 | * ip - our ip | ||
24 | * mac - our arp address | ||
25 | * interface - interface to use | ||
26 | * retn: 1 addr free | ||
27 | * 0 addr used | ||
28 | * -1 error | ||
29 | */ | ||
30 | |||
31 | /* FIXME: match response against chaddr */ | ||
32 | int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface) | ||
33 | { | ||
34 | |||
35 | int timeout = 2; | ||
36 | int optval = 1; | ||
37 | int s; /* socket */ | ||
38 | int rv = 1; /* return value */ | ||
39 | struct sockaddr addr; /* for interface name */ | ||
40 | struct arpMsg arp; | ||
41 | fd_set fdset; | ||
42 | struct timeval tm; | ||
43 | time_t prevTime; | ||
44 | |||
45 | |||
46 | if ((s = socket (PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) == -1) { | ||
47 | #ifdef IN_BUSYBOX | ||
48 | LOG(LOG_ERR, bb_msg_can_not_create_raw_socket); | ||
49 | #else | ||
50 | LOG(LOG_ERR, "Could not open raw socket"); | ||
51 | #endif | ||
52 | return -1; | ||
53 | } | ||
54 | |||
55 | if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) { | ||
56 | LOG(LOG_ERR, "Could not setsocketopt on raw socket"); | ||
57 | close(s); | ||
58 | return -1; | ||
59 | } | ||
60 | |||
61 | /* send arp request */ | ||
62 | memset(&arp, 0, sizeof(arp)); | ||
63 | memcpy(arp.h_dest, MAC_BCAST_ADDR, 6); /* MAC DA */ | ||
64 | memcpy(arp.h_source, mac, 6); /* MAC SA */ | ||
65 | arp.h_proto = htons(ETH_P_ARP); /* protocol type (Ethernet) */ | ||
66 | arp.htype = htons(ARPHRD_ETHER); /* hardware type */ | ||
67 | arp.ptype = htons(ETH_P_IP); /* protocol type (ARP message) */ | ||
68 | arp.hlen = 6; /* hardware address length */ | ||
69 | arp.plen = 4; /* protocol address length */ | ||
70 | arp.operation = htons(ARPOP_REQUEST); /* ARP op code */ | ||
71 | memcpy(arp.sInaddr, &ip, sizeof(ip)); /* source IP address */ | ||
72 | memcpy(arp.sHaddr, mac, 6); /* source hardware address */ | ||
73 | memcpy(arp.tInaddr, &yiaddr, sizeof(yiaddr)); /* target IP address */ | ||
74 | |||
75 | memset(&addr, 0, sizeof(addr)); | ||
76 | strcpy(addr.sa_data, interface); | ||
77 | if (sendto(s, &arp, sizeof(arp), 0, &addr, sizeof(addr)) < 0) | ||
78 | rv = 0; | ||
79 | |||
80 | /* wait arp reply, and check it */ | ||
81 | tm.tv_usec = 0; | ||
82 | prevTime = uptime(); | ||
83 | while (timeout > 0) { | ||
84 | FD_ZERO(&fdset); | ||
85 | FD_SET(s, &fdset); | ||
86 | tm.tv_sec = timeout; | ||
87 | if (select(s + 1, &fdset, (fd_set *) NULL, (fd_set *) NULL, &tm) < 0) { | ||
88 | DEBUG(LOG_ERR, "Error on ARPING request: %m"); | ||
89 | if (errno != EINTR) rv = 0; | ||
90 | } else if (FD_ISSET(s, &fdset)) { | ||
91 | if (recv(s, &arp, sizeof(arp), 0) < 0 ) rv = 0; | ||
92 | if (arp.operation == htons(ARPOP_REPLY) && | ||
93 | bcmp(arp.tHaddr, mac, 6) == 0 && | ||
94 | *((uint32_t *) arp.sInaddr) == yiaddr) { | ||
95 | DEBUG(LOG_INFO, "Valid arp reply receved for this address"); | ||
96 | rv = 0; | ||
97 | break; | ||
98 | } | ||
99 | } | ||
100 | timeout -= uptime() - prevTime; | ||
101 | prevTime = uptime(); | ||
102 | } | ||
103 | close(s); | ||
104 | DEBUG(LOG_INFO, "%salid arp replies for this address", rv ? "No v" : "V"); | ||
105 | return rv; | ||
106 | } | ||