]> git.sur5r.net Git - ngadmin/blobdiff - cli/src/admin.c
Merge branch 'autotools'
[ngadmin] / cli / src / admin.c
index dbd30bbaeaf260fca48659de9cdf1fec1e376473..73ea79c7a3cc143a8cdcb5a48cadb70d857de0ca 100644 (file)
@@ -21,8 +21,6 @@
 #define MAXCOM 32
 
 
-int main_loop_continue;
-
 
 static const struct TreeNode* getSubCom (char **com, int n, int *t)
 {
@@ -115,6 +113,7 @@ static char** my_completion (const char *text, int start, int end UNUSED)
 #endif /* HAVE_LIBREADLINE */
 
 
+int main_loop_continue;
 static struct ngadmin *nga;
 static sigjmp_buf jmpbuf;
 static struct termios orig_term;
@@ -133,7 +132,7 @@ NORET static void handler (int sig)
                current_term.c_lflag |= ECHO;
                tcsetattr(STDIN_FILENO, TCSANOW, &current_term);
                
-               if (!batch)
+               if (!batch && main_loop_continue)
                        siglongjmp(jmpbuf, 1);
        
        default:
@@ -159,7 +158,7 @@ static int pre_login (const struct ether_addr *mac, int retries)
                err = ngadmin_scan(nga);
                if (err < 0) {
                        printErrCode(err);
-                       continue;
+                       return err;
                }
                
                /* search switch with requested MAC */
@@ -199,9 +198,9 @@ int main (int argc, char **argv)
                {"batch", no_argument, NULL, 'a'},
                {"keep-broadcasting", no_argument, NULL, 'b'},
                {"force-interface", no_argument, NULL, 'f'},
-               {"global-broadcast", no_argument, NULL, 'g'},
                {"help", no_argument, NULL, 'h'},
                {"interface", required_argument, NULL, 'i'},
+               {"local-broadcast", no_argument, NULL, 'l'},
                {"mac", required_argument, NULL, 'm'},
                {"password", required_argument, NULL, 'p'},
                {"retries", required_argument, NULL, 'r'},
@@ -211,7 +210,7 @@ int main (int argc, char **argv)
        char *line, *com[MAXCOM];
        const char *iface = "eth0", *password = NULL;
        float timeout = 0.f;
-       bool kb = false, force = false, global = false;
+       bool kb = false, force = false, global = true;
        struct timeval tv;
        const struct TreeNode *cur, *next;
        struct ether_addr *mac = NULL;
@@ -228,7 +227,7 @@ int main (int argc, char **argv)
        
        opterr = 0;
        
-       while ((n = getopt_long(argc, argv, "abfghi:m:p:r:t:", opts, NULL)) != -1) {
+       while ((n = getopt_long(argc, argv, "abfhi:lm:p:r:t:", opts, NULL)) != -1) {
                switch (n) {
                
                case 'a':
@@ -243,10 +242,6 @@ int main (int argc, char **argv)
                        force = true;
                        break;
                
-               case 'g':
-                       global = true;
-                       break;
-               
                case 'h':
                        printf("usage: %s [-a] [-b] [-f] [-g] [-i <interface>] [-m <MAC>] [-p <password>]\n", argv[0]);
                        goto end;
@@ -255,6 +250,10 @@ int main (int argc, char **argv)
                        iface = optarg;
                        break;
                
+               case 'l':
+                       global = false;
+                       break;
+               
                case 'm':
                        mac = ether_aton(optarg);
                        if (mac == NULL) {
@@ -306,13 +305,13 @@ int main (int argc, char **argv)
        }
        
        
-       if (kb && ngadmin_setKeepBroadcasting(nga, true) != ERR_OK)
+       if (ngadmin_setKeepBroadcasting(nga, kb) != ERR_OK)
                goto end;
        
        if (force && ngadmin_forceInterface(nga) != ERR_OK)
                goto end;
        
-       if (global && ngadmin_useGlobalBroadcast(nga, true) != ERR_OK)
+       if (ngadmin_useGlobalBroadcast(nga, global) != ERR_OK)
                goto end;
        
        /* non-TTY inputs are automatically set to batch mode */
@@ -329,7 +328,13 @@ int main (int argc, char **argv)
        if (mac != NULL && pre_login(mac, retries) != 0)
                goto end;
        
-       if (!batch) {
+       if (batch) {
+               /* in batch mode, we must be logged to continue */
+               if (ngadmin_getCurrentSwitch(nga) == NULL) {
+                       printf("must be logged\n");
+                       goto end;
+               }
+       } else {
 #ifdef HAVE_LIBREADLINE
                /* initialize readline functions */
                rl_attempted_completion_function = my_completion;
@@ -340,7 +345,6 @@ int main (int argc, char **argv)
        }
        
        main_loop_continue = 1;
-       
        while (main_loop_continue) {
                /* read user input */
                line = NULL;