[git commit] arp: fix -H/-t handling.

Denys Vlasenko vda.linux at googlemail.com
Mon Feb 4 14:14:20 UTC 2013


commit: http://git.busybox.net/busybox/commit/?id=a8816dafc4b274b17c58df88cabdbf9e2b47f528
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

While at it, shrank code.
function                                             old     new   delta
arp_main                                            1558    1487     -71

Signed-off-by: Kuleshov Aleksey <rndfax at yandex.ru>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/arp.c |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/networking/arp.c b/networking/arp.c
index 1c99987..201bb2a 100644
--- a/networking/arp.c
+++ b/networking/arp.c
@@ -477,28 +477,33 @@ static int arp_show(char *name)
 int arp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int arp_main(int argc UNUSED_PARAM, char **argv)
 {
-	const char *hw_type = "ether";
+	const char *hw_type;
 	const char *protocol;
 	unsigned opts;
 
 	INIT_G();
 
 	xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), sockfd);
+
 	ap = get_aftype(DFLT_AF);
-	if (!ap)
-		bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family");
+	/* Defaults are always supported */
+	//if (!ap)
+	//	bb_error_msg_and_die("%s: %s not supported", DFLT_AF, "address family");
+	hw = get_hwtype(DFLT_HW);
+	//if (!hw)
+	//	bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type");
 
 	opts = getopt32(argv, "A:p:H:t:i:adnDsv", &protocol, &protocol,
 				 &hw_type, &hw_type, &device);
 	argv += optind;
 	if (opts & (ARP_OPT_A | ARP_OPT_p)) {
 		ap = get_aftype(protocol);
-		if (ap == NULL)
+		if (!ap)
 			bb_error_msg_and_die("%s: unknown %s", protocol, "address family");
 	}
-	if (opts & (ARP_OPT_A | ARP_OPT_p)) {
+	if (opts & (ARP_OPT_H | ARP_OPT_t)) {
 		hw = get_hwtype(hw_type);
-		if (hw == NULL)
+		if (!hw)
 			bb_error_msg_and_die("%s: unknown %s", hw_type, "hardware type");
 		hw_set = 1;
 	}
@@ -507,14 +512,6 @@ int arp_main(int argc UNUSED_PARAM, char **argv)
 	if (ap->af != AF_INET) {
 		bb_error_msg_and_die("%s: kernel only supports 'inet'", ap->name);
 	}
-
-	/* If no hw type specified get default */
-	if (!hw) {
-		hw = get_hwtype(DFLT_HW);
-		if (!hw)
-			bb_error_msg_and_die("%s: %s not supported", DFLT_HW, "hardware type");
-	}
-
 	if (hw->alen <= 0) {
 		bb_error_msg_and_die("%s: %s without ARP support",
 				hw->name, "hardware type");
@@ -528,6 +525,7 @@ int arp_main(int argc UNUSED_PARAM, char **argv)
 			return arp_set(argv);
 		return arp_del(argv);
 	}
+
 	//if (opts & ARP_OPT_a) - default
 	return arp_show(argv[0]);
 }


More information about the busybox-cvs mailing list