diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-01-19 13:31:41 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-01-19 13:31:41 +0000 |
commit | e6ae6e3d39443606f9f101b9c6ef0070f3c863a1 (patch) | |
tree | 8872c356470717444ddf0c1ee43ee22d3a8d974d /networking/arping.c | |
parent | f2ba45e339a8adc589704217409684f7f6d1d214 (diff) | |
download | busybox-w32-e6ae6e3d39443606f9f101b9c6ef0070f3c863a1.tar.gz busybox-w32-e6ae6e3d39443606f9f101b9c6ef0070f3c863a1.tar.bz2 busybox-w32-e6ae6e3d39443606f9f101b9c6ef0070f3c863a1.zip |
fix missed option argument for -I <device>, interface name checks
redesigned, patch by Nick Fedchik
Diffstat (limited to 'networking/arping.c')
-rw-r--r-- | networking/arping.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/networking/arping.c b/networking/arping.c index a0bfdaaf6..af44f9267 100644 --- a/networking/arping.c +++ b/networking/arping.c | |||
@@ -63,8 +63,9 @@ static void set_signal(int signo, void (*handler) (void)) | |||
63 | } | 63 | } |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | static int send_pack(int sock, struct in_addr *src_addr, struct in_addr *dst_addr, | 66 | static int send_pack(int sock, struct in_addr *src_addr, |
67 | struct sockaddr_ll *ME, struct sockaddr_ll *HE) | 67 | struct in_addr *dst_addr, struct sockaddr_ll *ME, |
68 | struct sockaddr_ll *HE) | ||
68 | { | 69 | { |
69 | int err; | 70 | int err; |
70 | struct timeval now; | 71 | struct timeval now; |
@@ -274,7 +275,7 @@ int arping_main(int argc, char **argv) | |||
274 | 275 | ||
275 | setuid(uid); | 276 | setuid(uid); |
276 | 277 | ||
277 | while ((ch = getopt(argc, argv, "h?bfDUAqc:w:s:I")) != EOF) { | 278 | while ((ch = getopt(argc, argv, "h?bfDUAqc:w:s:I:")) != EOF) { |
278 | switch (ch) { | 279 | switch (ch) { |
279 | case 'b': | 280 | case 'b': |
280 | broadcast_only = 1; | 281 | broadcast_only = 1; |
@@ -300,6 +301,13 @@ int arping_main(int argc, char **argv) | |||
300 | timeout = atoi(optarg); | 301 | timeout = atoi(optarg); |
301 | break; | 302 | break; |
302 | case 'I': | 303 | case 'I': |
304 | if (optarg == NULL) | ||
305 | show_usage(); | ||
306 | if (xstrlen(optarg) > IF_NAMESIZE) { | ||
307 | error_msg("Interface name `%s' must be less than %d", optarg, | ||
308 | IF_NAMESIZE); | ||
309 | exit(2); | ||
310 | } | ||
303 | device = optarg; | 311 | device = optarg; |
304 | break; | 312 | break; |
305 | case 'f': | 313 | case 'f': |
@@ -322,10 +330,6 @@ int arping_main(int argc, char **argv) | |||
322 | 330 | ||
323 | target = *argv; | 331 | target = *argv; |
324 | 332 | ||
325 | if (device == NULL) { | ||
326 | error_msg("-I <interface> is required!"); | ||
327 | exit(1); | ||
328 | } | ||
329 | 333 | ||
330 | if (s < 0) { | 334 | if (s < 0) { |
331 | error_msg("socket"); | 335 | error_msg("socket"); |
@@ -338,7 +342,7 @@ int arping_main(int argc, char **argv) | |||
338 | memset(&ifr, 0, sizeof(ifr)); | 342 | memset(&ifr, 0, sizeof(ifr)); |
339 | strncpy(ifr.ifr_name, device, IFNAMSIZ - 1); | 343 | strncpy(ifr.ifr_name, device, IFNAMSIZ - 1); |
340 | if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { | 344 | if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { |
341 | error_msg("unknown interface %s", device); | 345 | error_msg("Interface %s not found", device); |
342 | exit(2); | 346 | exit(2); |
343 | } | 347 | } |
344 | ifindex = ifr.ifr_ifindex; | 348 | ifindex = ifr.ifr_ifindex; |
@@ -348,11 +352,11 @@ int arping_main(int argc, char **argv) | |||
348 | exit(2); | 352 | exit(2); |
349 | } | 353 | } |
350 | if (!(ifr.ifr_flags & IFF_UP)) { | 354 | if (!(ifr.ifr_flags & IFF_UP)) { |
351 | error_msg("Interface \"%s\" is down", device); | 355 | error_msg("Interface %s is down", device); |
352 | exit(2); | 356 | exit(2); |
353 | } | 357 | } |
354 | if (ifr.ifr_flags & (IFF_NOARP | IFF_LOOPBACK)) { | 358 | if (ifr.ifr_flags & (IFF_NOARP | IFF_LOOPBACK)) { |
355 | error_msg("Interface \"%s\" is not ARPable", device); | 359 | error_msg("Interface %s is not ARPable", device); |
356 | exit(dad ? 0 : 2); | 360 | exit(dad ? 0 : 2); |
357 | } | 361 | } |
358 | } | 362 | } |
@@ -388,7 +392,7 @@ int arping_main(int argc, char **argv) | |||
388 | if (setsockopt | 392 | if (setsockopt |
389 | (probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device, | 393 | (probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device, |
390 | strlen(device) + 1) == -1) | 394 | strlen(device) + 1) == -1) |
391 | perror("WARNING: interface is ignored"); | 395 | error_msg("WARNING: interface %s is ignored", device); |
392 | } | 396 | } |
393 | memset(&saddr, 0, sizeof(saddr)); | 397 | memset(&saddr, 0, sizeof(saddr)); |
394 | saddr.sin_family = AF_INET; | 398 | saddr.sin_family = AF_INET; |
@@ -458,6 +462,7 @@ int arping_main(int argc, char **argv) | |||
458 | 462 | ||
459 | { | 463 | { |
460 | struct sigaction sa; | 464 | struct sigaction sa; |
465 | |||
461 | memset(&sa, 0, sizeof(sa)); | 466 | memset(&sa, 0, sizeof(sa)); |
462 | sa.sa_flags = SA_RESTART; | 467 | sa.sa_flags = SA_RESTART; |
463 | 468 | ||