X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=cli%2Fcom_ports.c;h=baa8c8f3a6fe3dcca1c36deae8902e46195553af;hb=342c158724a84d9743b074a83f5146862985bbce;hp=b5202187ed20a8e346e67f9281f739da0d46e32a;hpb=192ea617675b35fe37460a0fbb0c1511c0074fe8;p=ngadmin diff --git a/cli/com_ports.c b/cli/com_ports.c index b520218..baa8c8f 100644 --- a/cli/com_ports.c +++ b/cli/com_ports.c @@ -1,10 +1,9 @@ -#include "common.h" +#include "commands.h" - -static bool do_ports_state (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) { +bool do_ports_state (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; @@ -48,7 +47,27 @@ static bool do_ports_state (const struct TreeNode *tn UNUSED, int nb UNUSED, con -static bool do_ports_stats_show (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) { +bool do_ports_statistics_reset (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) { + + int i; + + + if ( ngadmin_getCurrentSwitch(nga)==NULL ) { + printf("must be logged\n"); + return false; + } + + i=ngadmin_resetPortsStatistics(nga); + printErrCode(i); + + + return true; + +} + + + +bool do_ports_statistics_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; @@ -61,7 +80,7 @@ static bool do_ports_stats_show (const struct TreeNode *tn UNUSED, int nb UNUSED ret=false; goto end; } - + ps=calloc(sa->ports, sizeof(struct port_stats)); if ( (i=ngadmin_getPortsStatistics(nga, ps))<0 ) { printErrCode(i); @@ -69,9 +88,9 @@ static bool do_ports_stats_show (const struct TreeNode *tn UNUSED, int nb UNUSED goto end; } - printf("Port\tReceived\tSent\t\tCRC errors\n"); + printf("Port\tReceived\tSent\tCRC errors\n"); for (i=0; iports; ++i) { - printf("%i\t%8llu\t%8llu\t%8llu\n", i+1, ps[i].recv, ps[i].sent, ps[i].crc); + printf("% 4i%12llu%12llu%14llu\n", i+1, ps[i].recv, ps[i].sent, ps[i].crc); } end: @@ -84,33 +103,3 @@ static bool do_ports_stats_show (const struct TreeNode *tn UNUSED, int nb UNUSED -static bool do_ports_stats_reset (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) { - - int i; - - - if ( ngadmin_getCurrentSwitch(nga)==NULL ) { - printf("must be logged\n"); - return false; - } - - i=ngadmin_resetPortsStatistics(nga); - printErrCode(i); - - - return true; - -} - - - -static const struct TreeNode com_ports_state=COM("state", do_ports_state, false, NULL); - -static const struct TreeNode com_ports_stats_show=COM("show", do_ports_stats_show, false, NULL); -static const struct TreeNode com_ports_stats_reset=COM("reset", do_ports_stats_reset, false, NULL); -static const struct TreeNode com_ports_stats=COM("stats", NULL, false, &com_ports_stats_reset, &com_ports_stats_show, NULL); - -const struct TreeNode com_ports=COM("ports", NULL, false, &com_ports_state, &com_ports_stats, NULL); - - -