]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
make iw usable for mere mortals
authorAndrew Lutomirski <luto@myrealbox.com>
Thu, 20 Dec 2007 17:50:07 +0000 (18:50 +0100)
committerJohannes Berg <johannes@sipsolutions.net>
Thu, 20 Dec 2007 17:50:07 +0000 (18:50 +0100)
iw currently works, but the error handling is a bit off, many error
messages are absent, and the help text is flat-out wrong.  This
partially fixes the above and should make it possible for noobs to add
and remove interfaces without reading the entire source.

Signed-Off-By: Andy Lutomirski <luto@myrealbox.com>
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
interface.c
iw.c

index b54a66cd29cc90e5d0bc759e0c5fa2398f77e4e4..efc2d93280a21b55c16899f2c874e1db14d21c9e 100644 (file)
@@ -55,7 +55,7 @@ static int get_if_type(int *argc, char ***argv, enum nl80211_iftype *type)
 static int handle_interface_add(struct nl80211_state *state,
                                char *phy, char *dev, int argc, char **argv)
 {
-       char *name = argv[0];
+       char *name;
        enum nl80211_iftype type;
        int tpset, err;
        struct nl_msg *msg;
@@ -65,14 +65,15 @@ static int handle_interface_add(struct nl80211_state *state,
                return -1;
        }
 
+       name = argv[0];
        argc--;
        argv++;
 
-       if (argc) {
-               tpset = get_if_type(&argc, &argv, &type);
-               if (tpset < 0)
-                       return -1;
-       }
+       tpset = get_if_type(&argc, &argv, &type);
+       if (tpset == 0)
+               fprintf(stderr, "you must specify an interface type\n");
+       if (tpset <= 0)
+               return -1;
 
        if (argc) {
                fprintf(stderr, "too many arguments\n");
@@ -150,8 +151,10 @@ int handle_interface(struct nl80211_state *state,
 {
        char *cmd = argv[0];
 
-       if (argc < 1)
+       if (argc < 1) {
+               fprintf(stderr, "you must specify an interface command\n");
                return -1;
+       }
 
        argc--;
        argv++;
diff --git a/iw.c b/iw.c
index c2b53ee236fc3244eb65cdc587b26fe37fd181e5..469bf0e064e612bdf2aa161db35174dd043e8161 100644 (file)
--- a/iw.c
+++ b/iw.c
@@ -92,8 +92,11 @@ static int get_phy_or_dev(int *argc, char ***argv, char **name)
 
 void usage(char *argv0)
 {
-       fprintf(stderr, "Usage: %s [options] {dev <phydev>} {interface <interface> } {COMMAND}\n"
-                       "where COMMAND := { add | del }\n", argv0);
+       fprintf(stderr, "Usage: %s dev <phydev> interface <COMMAND> [OPTIONS]\n"
+                       "where COMMAND := { add | del }\n"
+                       "\n"
+                       "For add, OPTIONS := <name> type <type>\n"
+                       "For del, OPTIONS should be blank and phydev is the interface to delete.\n", argv0);
 }
 
 int main(int argc, char **argv)