]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
autodetect interface/phy
authorJohannes Berg <johannes@sipsolutions.net>
Mon, 6 Jul 2009 11:10:39 +0000 (13:10 +0200)
committerJohannes Berg <johannes@sipsolutions.net>
Mon, 6 Jul 2009 11:10:39 +0000 (13:10 +0200)
Try to figure out what the user meant and allow users
to enter e.g. 'iw wlan0 info'. This only works if the
interface or phy exists though.

iw.c

diff --git a/iw.c b/iw.c
index 4bfb24e57deaca1ac040fc7e483ad577a7c37e92..636cd062681db049843d366549bbfaaac0d678cd 100644 (file)
--- a/iw.c
+++ b/iw.c
@@ -168,6 +168,9 @@ static void usage(bool full)
                        continue;
                __usage_cmd(cmd, "\t", full);
        }
+       fprintf(stderr, "\nYou can omit the 'phy' or 'dev' if "
+                       "the identification is unique,\n"
+                       "e.g. \"iw wlan0 info\" or \"iw phy0 info\".\n\n");
 }
 
 static int print_help(struct nl80211_state *state,
@@ -432,9 +435,17 @@ int main(int argc, char **argv)
                } else if (*(*argv + 3) == '#')
                        err = __handle_cmd(&nlstate, II_PHY_IDX, argc, argv, &cmd);
                else
-                       err = 1;
-       } else
-               err = __handle_cmd(&nlstate, II_NONE, argc, argv, &cmd);
+                       goto detect;
+       } else {
+               int idx;
+               enum id_input idby = II_NONE;
+ detect:
+               if ((idx = if_nametoindex(argv[0])) != 0)
+                       idby = II_NETDEV;
+               else if ((idx = phy_lookup(argv[0])) > 0)
+                       idby = II_PHY_NAME;
+               err = __handle_cmd(&nlstate, idby, argc, argv, &cmd);
+       }
 
        if (err == 1) {
                if (cmd)