]> git.sur5r.net Git - ngadmin/blob - cli/com_cabletest.c
Cli: refactor, change coding style
[ngadmin] / cli / com_cabletest.c
1
2 #include "commands.h"
3
4
5 bool do_cabletest (int nb, const char **com, 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 (nb < 1) {
14                 printf("Usage: cabletest <port1> [<port2> ...]\n");
15                 goto end;
16         }
17         
18         
19         sa = ngadmin_getCurrentSwitch(nga);
20         if (sa == NULL) {
21                 printf("must be logged\n");
22                 ret = false;
23                 goto end;
24         }
25         
26         ct = malloc(sa->ports * sizeof(struct cabletest));
27         memset(ct, 0, sa->ports * sizeof(struct cabletest));
28         
29         while (k < nb) {
30                 ct[j].port = strtol(com[k++], NULL, 0);
31                 if (ct[j].port >= 1 && ct[j].port <= sa->ports)
32                         j++;
33         }
34         
35         i = ngadmin_cabletest(nga, ct, j);
36         if (i < 0) {
37                 printErrCode(i);
38                 ret = false;
39                 goto end;
40         }
41         
42         for (i = 0; i < j; i++)
43                 printf("port %i: %08X %08X\n", ct[i].port, ct[i].v1, ct[i].v2);
44         
45 end:
46         free(ct);
47         
48         return ret;
49 }
50
51