aboutsummaryrefslogtreecommitdiff
path: root/networking/ip.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2007-04-10 18:43:27 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2007-04-10 18:43:27 +0000
commite87d7955f8130040a575f2f48962471a27ccc964 (patch)
tree149be152e5af1468e88859842a4a7b59ab0a4773 /networking/ip.c
parent51f7ab6162a1be2e52d7b2ccc53acb6700769d0b (diff)
downloadbusybox-e87d7955f8130040a575f2f48962471a27ccc964.tar.gz
- rewrite the ip applet to be less bloaty
- mark libiproute's matches() as deprecated. Convert to index_in_(sub)str_array()! text data bss dec hex filename 314 0 0 314 13a ip.o.orig 200 0 0 200 c8 ip.o Using a smallint for the key would save another byte.
Diffstat (limited to 'networking/ip.c')
-rw-r--r--networking/ip.c70
1 files changed, 48 insertions, 22 deletions
diff --git a/networking/ip.c b/networking/ip.c
index d51689542..dc9ca1f91 100644
--- a/networking/ip.c
+++ b/networking/ip.c
@@ -10,6 +10,7 @@
* Changes:
*
* Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
+ * Bernhard Fischer rewrote to use index_in_substr_array
*/
#include "busybox.h"
@@ -17,31 +18,56 @@
#include "libiproute/utils.h"
#include "libiproute/ip_common.h"
+static int ATTRIBUTE_NORETURN ip_print_help(int ATTRIBUTE_UNUSED ac, char ATTRIBUTE_UNUSED **av)
+{
+ bb_show_usage();
+}
int ip_main(int argc, char **argv);
int ip_main(int argc, char **argv)
{
- ip_parse_common_args(&argc, &argv);
-
- if (argc <= 1)
- bb_show_usage();
+ const char * const keywords[] = {
+ USE_FEATURE_IP_ADDRESS("address",)
+ USE_FEATURE_IP_ROUTE("route",)
+ USE_FEATURE_IP_LINK("link",)
+ USE_FEATURE_IP_TUNNEL("tunnel", "tunl",)
+ USE_FEATURE_IP_RULE("rule",)
+ NULL
+ };
+ enum {
+ USE_FEATURE_IP_ADDRESS(IP_addr,)
+ USE_FEATURE_IP_ROUTE(IP_route,)
+ USE_FEATURE_IP_LINK(IP_link,)
+ USE_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,)
+ USE_FEATURE_IP_RULE(IP_rule,)
+ IP_none
+ };
+ int (*ip_func)(int argc, char **argv) = ip_print_help;
- if (ENABLE_FEATURE_IP_ADDRESS && matches(argv[1], "address") == 0) {
- return do_ipaddr(argc-2, argv+2);
- }
- if (ENABLE_FEATURE_IP_ROUTE && matches(argv[1], "route") == 0) {
- return do_iproute(argc-2, argv+2);
- }
- if (ENABLE_FEATURE_IP_LINK && matches(argv[1], "link") == 0) {
- return do_iplink(argc-2, argv+2);
- }
- if (ENABLE_FEATURE_IP_TUNNEL
- && (matches(argv[1], "tunnel") == 0 || strcmp(argv[1], "tunl") == 0)
- ) {
- return do_iptunnel(argc-2, argv+2);
- }
- if (ENABLE_FEATURE_IP_RULE && matches(argv[1], "rule") == 0) {
- return do_iprule(argc-2, argv+2);
+ ip_parse_common_args(&argc, &argv);
+ if (argc > 1) {
+ int key = index_in_substr_array(keywords, argv[1]);
+ argc -= 2;
+ argv += 2;
+#if ENABLE_FEATURE_IP_ADDRESS
+ if (key == IP_addr)
+ ip_func = do_ipaddr;
+#endif
+#if ENABLE_FEATURE_IP_ROUTE
+ if (key == IP_route)
+ ip_func = do_iproute;
+#endif
+#if ENABLE_FEATURE_IP_LINK
+ if (key == IP_link)
+ ip_func = do_iplink;
+#endif
+#if ENABLE_FEATURE_IP_TUNNEL
+ if (key == IP_tunnel || key == IP_tunl)
+ ip_func = do_iptunnel;
+#endif
+#if ENABLE_FEATURE_IP_RULE
+ if (key == IP_rule)
+ ip_func = do_iprule;
+#endif
}
-
- bb_show_usage();
+ return (ip_func(argc, argv));
}