diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-02-11 13:26:54 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-02-11 13:26:54 +0000 |
commit | f536b99d2646cee6c86e025d29d4a8ae12989e1b (patch) | |
tree | d5ca320f3767a0e57f844f6fa1041049b6ddaa62 | |
parent | a985d306a1fb5533e6fd93dbbcc04e493a126de8 (diff) | |
download | busybox-w32-f536b99d2646cee6c86e025d29d4a8ae12989e1b.tar.gz busybox-w32-f536b99d2646cee6c86e025d29d4a8ae12989e1b.tar.bz2 busybox-w32-f536b99d2646cee6c86e025d29d4a8ae12989e1b.zip |
- shrink a tiny bit (-30Bytes)
-rw-r--r-- | networking/arping.c | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/networking/arping.c b/networking/arping.c index f71a98498..c89b97567 100644 --- a/networking/arping.c +++ b/networking/arping.c | |||
@@ -121,7 +121,7 @@ static void finish(void) | |||
121 | if (option_mask32 & DAD) | 121 | if (option_mask32 & DAD) |
122 | exit(!!received); | 122 | exit(!!received); |
123 | if (option_mask32 & UNSOLICITED) | 123 | if (option_mask32 & UNSOLICITED) |
124 | exit(0); | 124 | exit(EXIT_SUCCESS); |
125 | exit(!received); | 125 | exit(!received); |
126 | } | 126 | } |
127 | 127 | ||
@@ -148,7 +148,7 @@ static void catcher(void) | |||
148 | alarm(1); | 148 | alarm(1); |
149 | } | 149 | } |
150 | 150 | ||
151 | static int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) | 151 | static bool recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) |
152 | { | 152 | { |
153 | struct arphdr *ah = (struct arphdr *) buf; | 153 | struct arphdr *ah = (struct arphdr *) buf; |
154 | unsigned char *p = (unsigned char *) (ah + 1); | 154 | unsigned char *p = (unsigned char *) (ah + 1); |
@@ -158,35 +158,33 @@ static int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) | |||
158 | if (FROM->sll_pkttype != PACKET_HOST | 158 | if (FROM->sll_pkttype != PACKET_HOST |
159 | && FROM->sll_pkttype != PACKET_BROADCAST | 159 | && FROM->sll_pkttype != PACKET_BROADCAST |
160 | && FROM->sll_pkttype != PACKET_MULTICAST) | 160 | && FROM->sll_pkttype != PACKET_MULTICAST) |
161 | return 0; | 161 | return false; |
162 | 162 | ||
163 | /* Only these types are recognised */ | 163 | /* Only these types are recognised */ |
164 | if (ah->ar_op != htons(ARPOP_REQUEST) && ah->ar_op != htons(ARPOP_REPLY)) | 164 | if (ah->ar_op != htons(ARPOP_REQUEST) && ah->ar_op != htons(ARPOP_REPLY)) |
165 | return 0; | 165 | return false; |
166 | 166 | ||
167 | /* ARPHRD check and this darned FDDI hack here :-( */ | 167 | /* ARPHRD check and this darned FDDI hack here :-( */ |
168 | if (ah->ar_hrd != htons(FROM->sll_hatype) | 168 | if (ah->ar_hrd != htons(FROM->sll_hatype) |
169 | && (FROM->sll_hatype != ARPHRD_FDDI || ah->ar_hrd != htons(ARPHRD_ETHER))) | 169 | && (FROM->sll_hatype != ARPHRD_FDDI || ah->ar_hrd != htons(ARPHRD_ETHER))) |
170 | return 0; | 170 | return false; |
171 | 171 | ||
172 | /* Protocol must be IP. */ | 172 | /* Protocol must be IP. */ |
173 | if (ah->ar_pro != htons(ETH_P_IP)) | 173 | if (ah->ar_pro != htons(ETH_P_IP) |
174 | return 0; | 174 | || (ah->ar_pln != 4) |
175 | if (ah->ar_pln != 4) | 175 | || (ah->ar_hln != me.sll_halen) |
176 | return 0; | 176 | || (len < sizeof(*ah) + 2 * (4 + ah->ar_hln))) |
177 | if (ah->ar_hln != me.sll_halen) | 177 | return false; |
178 | return 0; | 178 | |
179 | if (len < sizeof(*ah) + 2 * (4 + ah->ar_hln)) | ||
180 | return 0; | ||
181 | memcpy(&src_ip, p + ah->ar_hln, 4); | 179 | memcpy(&src_ip, p + ah->ar_hln, 4); |
182 | memcpy(&dst_ip, p + ah->ar_hln + 4 + ah->ar_hln, 4); | 180 | memcpy(&dst_ip, p + ah->ar_hln + 4 + ah->ar_hln, 4); |
181 | |||
182 | if (dst.s_addr != src_ip.s_addr) | ||
183 | return false; | ||
183 | if (!(option_mask32 & DAD)) { | 184 | if (!(option_mask32 & DAD)) { |
184 | if (dst.s_addr != src_ip.s_addr) | 185 | if ((src.s_addr != dst_ip.s_addr) |
185 | return 0; | 186 | || (memcmp(p + ah->ar_hln + 4, &me.sll_addr, ah->ar_hln))) |
186 | if (src.s_addr != dst_ip.s_addr) | 187 | return false; |
187 | return 0; | ||
188 | if (memcmp(p + ah->ar_hln + 4, &me.sll_addr, ah->ar_hln)) | ||
189 | return 0; | ||
190 | } else { | 188 | } else { |
191 | /* DAD packet was: | 189 | /* DAD packet was: |
192 | src_ip = 0 (or some src) | 190 | src_ip = 0 (or some src) |
@@ -201,12 +199,9 @@ static int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) | |||
201 | also that it matches to dst_ip, otherwise | 199 | also that it matches to dst_ip, otherwise |
202 | dst_ip/dst_hw do not matter. | 200 | dst_ip/dst_hw do not matter. |
203 | */ | 201 | */ |
204 | if (src_ip.s_addr != dst.s_addr) | 202 | if ((memcmp(p, &me.sll_addr, me.sll_halen) == 0) |
205 | return 0; | 203 | || (src.s_addr && src.s_addr != dst_ip.s_addr)) |
206 | if (memcmp(p, &me.sll_addr, me.sll_halen) == 0) | 204 | return false; |
207 | return 0; | ||
208 | if (src.s_addr && src.s_addr != dst_ip.s_addr) | ||
209 | return 0; | ||
210 | } | 205 | } |
211 | if (!(option_mask32 & QUIET)) { | 206 | if (!(option_mask32 & QUIET)) { |
212 | int s_printed = 0; | 207 | int s_printed = 0; |
@@ -246,7 +241,7 @@ static int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) | |||
246 | memcpy(he.sll_addr, p, me.sll_halen); | 241 | memcpy(he.sll_addr, p, me.sll_halen); |
247 | option_mask32 |= UNICASTING; | 242 | option_mask32 |= UNICASTING; |
248 | } | 243 | } |
249 | return 1; | 244 | return true; |
250 | } | 245 | } |
251 | 246 | ||
252 | int arping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 247 | int arping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -256,6 +251,7 @@ int arping_main(int argc, char **argv) | |||
256 | char *source = NULL; | 251 | char *source = NULL; |
257 | char *target; | 252 | char *target; |
258 | unsigned char *packet; | 253 | unsigned char *packet; |
254 | char *err_str; | ||
259 | 255 | ||
260 | INIT_G(); | 256 | INIT_G(); |
261 | 257 | ||
@@ -265,6 +261,7 @@ int arping_main(int argc, char **argv) | |||
265 | // Need to remove SUID_NEVER from applets.h for this to work | 261 | // Need to remove SUID_NEVER from applets.h for this to work |
266 | //xsetuid(getuid()); | 262 | //xsetuid(getuid()); |
267 | 263 | ||
264 | err_str = xasprintf("interface %s %%s", device); | ||
268 | { | 265 | { |
269 | unsigned opt; | 266 | unsigned opt; |
270 | char *str_count, *str_timeout; | 267 | char *str_count, *str_timeout; |
@@ -294,16 +291,16 @@ int arping_main(int argc, char **argv) | |||
294 | strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name) - 1); | 291 | strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name) - 1); |
295 | /* We use ifr.ifr_name in error msg so that problem | 292 | /* We use ifr.ifr_name in error msg so that problem |
296 | * with truncated name will be visible */ | 293 | * with truncated name will be visible */ |
297 | ioctl_or_perror_and_die(sock_fd, SIOCGIFINDEX, &ifr, "interface %s not found", ifr.ifr_name); | 294 | ioctl_or_perror_and_die(sock_fd, SIOCGIFINDEX, &ifr, err_str, "not found"); |
298 | me.sll_ifindex = ifr.ifr_ifindex; | 295 | me.sll_ifindex = ifr.ifr_ifindex; |
299 | 296 | ||
300 | xioctl(sock_fd, SIOCGIFFLAGS, (char *) &ifr); | 297 | xioctl(sock_fd, SIOCGIFFLAGS, (char *) &ifr); |
301 | 298 | ||
302 | if (!(ifr.ifr_flags & IFF_UP)) { | 299 | if (!(ifr.ifr_flags & IFF_UP)) { |
303 | bb_error_msg_and_die("interface %s is down", device); | 300 | bb_error_msg_and_die(err_str, "is down"); |
304 | } | 301 | } |
305 | if (ifr.ifr_flags & (IFF_NOARP | IFF_LOOPBACK)) { | 302 | if (ifr.ifr_flags & (IFF_NOARP | IFF_LOOPBACK)) { |
306 | bb_error_msg("interface %s is not ARPable", device); | 303 | bb_error_msg(err_str, "is not ARPable"); |
307 | return (option_mask32 & DAD ? 0 : 2); | 304 | return (option_mask32 & DAD ? 0 : 2); |
308 | } | 305 | } |
309 | } | 306 | } |
@@ -368,7 +365,7 @@ int arping_main(int argc, char **argv) | |||
368 | } | 365 | } |
369 | } | 366 | } |
370 | if (me.sll_halen == 0) { | 367 | if (me.sll_halen == 0) { |
371 | bb_error_msg("interface %s is not ARPable (no ll address)", device); | 368 | bb_error_msg(err_str, "is not ARPable (no ll address)"); |
372 | return (option_mask32 & DAD ? 0 : 2); | 369 | return (option_mask32 & DAD ? 0 : 2); |
373 | } | 370 | } |
374 | he = me; | 371 | he = me; |