]> git.sur5r.net Git - ngadmin/blob - cli/src/com_ports.c
Fix size of printed numbers
[ngadmin] / cli / src / 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: %s\n", i + 1, safeStr(getSpeedStr(ports[i])));
35         
36 end:
37         free(ports);
38         
39         
40         return ret;
41 }
42
43
44 int do_ports_statistics_reset (int argc, const char **argv UNUSED, struct ngadmin *nga)
45 {
46         int i;
47         
48         
49         if (argc > 0) {
50                 printf("this command takes no argument\n");
51                 return 1;
52         }
53         
54         if (ngadmin_getCurrentSwitch(nga) == NULL) {
55                 printf("must be logged\n");
56                 return 1;
57         }
58         
59         i = ngadmin_resetPortsStatistics(nga);
60         printErrCode(i);
61         
62         return 0;
63 }
64
65
66 int do_ports_statistics_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
67 {
68         int i, ret = 0;
69         const struct swi_attr *sa;
70         struct port_stats *ps = NULL;
71         
72         
73         if (argc > 0) {
74                 printf("this command takes no argument\n");
75                 ret = 1;
76                 goto end;
77         }
78         
79         sa = ngadmin_getCurrentSwitch(nga);
80         if (sa == NULL) {
81                 printf("must be logged\n");
82                 ret = 1;
83                 goto end;
84         }
85         
86         ps = calloc(sa->ports, sizeof(struct port_stats));
87         i = ngadmin_getPortsStatistics(nga, ps);
88         if (i < 0) {
89                 printErrCode(i);
90                 ret = 1;
91                 goto end;
92         }
93         
94         printf("Port             Received                 Sent           CRC errors\n");
95         for (i = 0; i < sa->ports; i++)
96                 printf("% 4i%21llu%21llu%21llu\n", i + 1, ps[i].recv, ps[i].sent, ps[i].crc);
97         
98 end:
99         free(ps);
100         
101         return ret;
102 }
103
104