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