]> git.sur5r.net Git - ngadmin/blob - cli/com_ports.c
Command functions return int instead of bool
[ngadmin] / cli / com_ports.c
1
2 #include "commands.h"
3
4
5 int do_ports_state (int argc, const char **argv UNUSED, struct ngadmin *nga)
6 {
7         int i, ret = 0;
8         const struct swi_attr *sa;
9         unsigned char *ports = NULL;
10         
11         
12         if (argc > 0) {
13                 printf("this command takes no argument\n");
14                 ret = 1;
15                 goto end;
16         }
17         
18         sa = ngadmin_getCurrentSwitch(nga);
19         if (sa == NULL) {
20                 printf("must be logged\n");
21                 ret = 1;
22                 goto end;
23         }
24         
25         ports = malloc(sa->ports * sizeof(unsigned char));
26         i = ngadmin_getPortsStatus(nga, ports);
27         if (i < 0) {
28                 printErrCode(i);
29                 ret = 1;
30                 goto end;
31         }
32         
33         for (i = 0; i < sa->ports; i++) {
34                 printf("port %i: ", i + 1);
35                 switch (ports[i]) {
36                 
37                 case 0:
38                         printf("down");
39                         break;
40                 
41                 case SPEED_10:
42                         printf("up, 10M");
43                         break;
44                 
45                 case SPEED_100:
46                         printf("up, 100M");
47                         break;
48                 
49                 case SPEED_1000:
50                         printf("up, 1000M");
51                         break;
52                 
53                 default:
54                         printf("unknown (%i)", ports[i]);
55                 }
56                 putchar('\n');
57         }
58         
59 end:
60         free(ports);
61         
62         
63         return ret;
64 }
65
66
67 int do_ports_statistics_reset (int argc, const char **argv UNUSED, struct ngadmin *nga)
68 {
69         int i;
70         
71         
72         if (argc > 0) {
73                 printf("this command takes no argument\n");
74                 return 1;
75         }
76         
77         if (ngadmin_getCurrentSwitch(nga) == NULL) {
78                 printf("must be logged\n");
79                 return 1;
80         }
81         
82         i = ngadmin_resetPortsStatistics(nga);
83         printErrCode(i);
84         
85         return 0;
86 }
87
88
89 int do_ports_statistics_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
90 {
91         int i, ret = 0;
92         const struct swi_attr *sa;
93         struct port_stats *ps = NULL;
94         
95         
96         if (argc > 0) {
97                 printf("this command takes no argument\n");
98                 ret = 1;
99                 goto end;
100         }
101         
102         sa = ngadmin_getCurrentSwitch(nga);
103         if (sa == NULL) {
104                 printf("must be logged\n");
105                 ret = 1;
106                 goto end;
107         }
108         
109         ps = calloc(sa->ports, sizeof(struct port_stats));
110         i = ngadmin_getPortsStatistics(nga, ps);
111         if (i < 0) {
112                 printErrCode(i);
113                 ret = 1;
114                 goto end;
115         }
116         
117         printf("Port\tReceived\tSent\tCRC errors\n");
118         for (i = 0; i < sa->ports; i++)
119                 printf("% 4i%12llu%12llu%14llu\n", i + 1, ps[i].recv, ps[i].sent, ps[i].crc);
120         
121 end:
122         free(ps);
123         
124         return ret;
125 }
126
127