diff options
author | shemminger <shemminger> | 2005-11-22 17:30:43 +0000 |
---|---|---|
committer | shemminger <shemminger> | 2005-11-22 17:30:43 +0000 |
commit | ede723964a065992bf9d0dbe3f780e65ca917872 (patch) | |
tree | 084fce5fdff96a2883397b601c8f99172de05fbb /ip/ip.c | |
parent | 991d2c0d56fe1b3b1a0fc8ab52ef8e7cd71892ef (diff) |
Add ip command aliases and better matching
Diffstat (limited to 'ip/ip.c')
-rw-r--r-- | ip/ip.c | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -62,13 +62,15 @@ static const struct cmd { const char *cmd; int (*func)(int argc, char **argv); } cmds[] = { - { "addr", do_ipaddr }, - { "maddr", do_multiaddr }, + { "address", do_ipaddr }, + { "maddress", do_multiaddr }, { "route", do_iproute }, { "rule", do_iprule }, - { "neigh", do_ipneigh }, + { "neighbor", do_ipneigh }, + { "neighbour", do_ipneigh }, { "link", do_iplink }, { "tunnel", do_iptunnel }, + { "tunl", do_iptunnel }, { "monitor", do_ipmonitor }, { "xfrm", do_xfrm }, { "mroute", do_multiroute }, @@ -78,14 +80,25 @@ static const struct cmd { static int do_cmd(const char *argv0, int argc, char **argv) { - const struct cmd *c; + const struct cmd *c, *m = NULL; + + for (c = cmds; c->cmd; ++c) { + if (matches(argv0, c->cmd) == 0) { + if (m && m->func != c->func) { + fprintf(stderr, + "Ambiguious command \"%s\" matches both %s and %s\n", + argv0, m->cmd, c->cmd); + return -1; + } + m = c; + } + } - for (c = cmds; c->cmd; ++c) - if (matches(argv0, c->cmd) == 0) - return c->func(argc-1, argv+1); + if (m) + return m->func(argc-1, argv+1); fprintf(stderr, "Object \"%s\" is unknown, try \"ip help\".\n", argv0); - exit(-1); + return -1; } static int batch(const char *name) |