]> git.sur5r.net Git - ngadmin/blob - cli/com_cabletest.c
521ada9b8ecbebb9dc55ce3d9b605549b5fdf0c0
[ngadmin] / cli / com_cabletest.c
1
2 #include "commands.h"
3
4
5
6 bool do_cabletest (int nb, const char **com, struct ngadmin *nga) {
7  
8  bool ret=true;
9  const struct swi_attr *sa;
10  struct cabletest *ct=NULL;
11  int i, j=0, k=0;
12  
13  
14  if ( nb<1 ) {
15   printf("Usage: cabletest <port1> [<port2> ...]\n");
16   goto end;
17  }
18  
19  if ( (sa=ngadmin_getCurrentSwitch(nga))==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<nb ) {
29   ct[j].port=strtol(com[k++], NULL, 0);
30   if ( ct[j].port>=1 && ct[j].port<=sa->ports ) ++j;
31  }
32  
33  i=ngadmin_cabletest(nga, ct, j);
34  if ( i<0 ) {
35   printErrCode(i);
36   ret=false;
37   goto end;
38  }
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  
45  
46  end:
47  free(ct);
48  
49  return ret;
50  
51 }
52
53