]> git.sur5r.net Git - ngadmin/blob - cli/com_cabletest.c
Let commands handle themselves absence of arguments
[ngadmin] / cli / com_cabletest.c
1
2 #include "commands.h"
3
4
5 bool do_cabletest (int argc, const char **argv, struct ngadmin *nga)
6 {
7         bool ret = true;
8         const struct swi_attr *sa;
9         struct cabletest *ct = NULL;
10         int i, j=0, k=0;
11         
12         
13         if (argc < 1) {
14                 printf("usage: cabletest <port1> [<port2> ...]\n");
15                 goto end;
16         }
17         
18         sa = ngadmin_getCurrentSwitch(nga);
19         if (sa == NULL) {
20                 printf("must be logged\n");
21                 ret = false;
22                 goto end;
23         }
24         
25         ct = malloc(sa->ports * sizeof(struct cabletest));
26         memset(ct, 0, sa->ports * sizeof(struct cabletest));
27         
28         while (k < argc) {
29                 ct[j].port = strtol(argv[k++], NULL, 0);
30                 if (ct[j].port >= 1 && ct[j].port <= sa->ports)
31                         j++;
32         }
33         
34         i = ngadmin_cabletest(nga, ct, j);
35         if (i < 0) {
36                 printErrCode(i);
37                 ret = false;
38                 goto end;
39         }
40         
41         for (i = 0; i < j; i++)
42                 printf("port %i: %08X %08X\n", ct[i].port, ct[i].v1, ct[i].v2);
43         
44 end:
45         free(ct);
46         
47         return ret;
48 }
49
50