diff options
author | Kuleshov Aleksey <rndfax@yandex.ru> | 2013-02-04 15:14:20 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-02-04 15:14:20 +0100 |
commit | a8816dafc4b274b17c58df88cabdbf9e2b47f528 (patch) | |
tree | cfe93a4e1e5a874370e741c524575a73c9953189 | |
parent | 6e29d07417c84e69ed0fb375205ae4e62fa236f7 (diff) | |
download | busybox-w32-a8816dafc4b274b17c58df88cabdbf9e2b47f528.tar.gz busybox-w32-a8816dafc4b274b17c58df88cabdbf9e2b47f528.tar.bz2 busybox-w32-a8816dafc4b274b17c58df88cabdbf9e2b47f528.zip |
arp: fix -H/-t handling.
While at it, shrank code.
function old new delta
arp_main 1558 1487 -71
Signed-off-by: Kuleshov Aleksey <rndfax@yandex.ru>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/arp.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/networking/arp.c b/networking/arp.c index 1c99987ae..201bb2aff 100644 --- a/networking/arp.c +++ b/networking/arp.c | |||
@@ -477,28 +477,33 @@ static int arp_show(char *name) | |||
477 | int arp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 477 | int arp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
478 | int arp_main(int argc UNUSED_PARAM, char **argv) | 478 | int arp_main(int argc UNUSED_PARAM, char **argv) |
479 | { | 479 | { |
480 | const char *hw_type = "ether"; | 480 | const char *hw_type; |
481 | const char *protocol; | 481 | const char *protocol; |
482 | unsigned opts; | 482 | unsigned opts; |
483 | 483 | ||
484 | INIT_G(); | 484 | INIT_G(); |
485 | 485 | ||
486 | xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), sockfd); | 486 | xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), sockfd); |
487 | |||
487 | ap = get_aftype(DFLT_AF); | 488 | ap = get_aftype(DFLT_AF); |
488 | if (!ap) | 489 | /* Defaults are always supported */ |
489 | bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); | 490 | //if (!ap) |
491 | // bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family"); | ||
492 | hw = get_hwtype(DFLT_HW); | ||
493 | //if (!hw) | ||
494 | // bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type"); | ||
490 | 495 | ||
491 | opts = getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol, | 496 | opts = getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol, |
492 | &hw_type, &hw_type, &device); | 497 | &hw_type, &hw_type, &device); |
493 | argv += optind; | 498 | argv += optind; |
494 | if (opts & (ARP_OPT_A | ARP_OPT_p)) { | 499 | if (opts & (ARP_OPT_A | ARP_OPT_p)) { |
495 | ap = get_aftype(protocol); | 500 | ap = get_aftype(protocol); |
496 | if (ap == NULL) | 501 | if (!ap) |
497 | bb_error_msg_and_die("%s: unknown %s", protocol, "address family"); | 502 | bb_error_msg_and_die("%s: unknown %s", protocol, "address family"); |
498 | } | 503 | } |
499 | if (opts & (ARP_OPT_A | ARP_OPT_p)) { | 504 | if (opts & (ARP_OPT_H | ARP_OPT_t)) { |
500 | hw = get_hwtype(hw_type); | 505 | hw = get_hwtype(hw_type); |
501 | if (hw == NULL) | 506 | if (!hw) |
502 | bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type"); | 507 | bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type"); |
503 | hw_set = 1; | 508 | hw_set = 1; |
504 | } | 509 | } |
@@ -507,14 +512,6 @@ int arp_main(int argc UNUSED_PARAM, char **argv) | |||
507 | if (ap->af != AF_INET) { | 512 | if (ap->af != AF_INET) { |
508 | bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name); | 513 | bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name); |
509 | } | 514 | } |
510 | |||
511 | /* If no hw type specified get default */ | ||
512 | if (!hw) { | ||
513 | hw = get_hwtype(DFLT_HW); | ||
514 | if (!hw) | ||
515 | bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type"); | ||
516 | } | ||
517 | |||
518 | if (hw->alen <= 0) { | 515 | if (hw->alen <= 0) { |
519 | bb_error_msg_and_die("%s: %s without ARP support", | 516 | bb_error_msg_and_die("%s: %s without ARP support", |
520 | hw->name, "hardware type"); | 517 | hw->name, "hardware type"); |
@@ -528,6 +525,7 @@ int arp_main(int argc UNUSED_PARAM, char **argv) | |||
528 | return arp_set(argv); | 525 | return arp_set(argv); |
529 | return arp_del(argv); | 526 | return arp_del(argv); |
530 | } | 527 | } |
528 | |||
531 | //if (opts & ARP_OPT_a) - default | 529 | //if (opts & ARP_OPT_a) - default |
532 | return arp_show(argv[0]); | 530 | return arp_show(argv[0]); |
533 | } | 531 | } |