X-Git-Url: https://git.sur5r.net/?p=gsconf;a=blobdiff_plain;f=shell_port.c;h=9ac059d262ef0412c2256b9e01fbd28b59d46330;hp=4e69179b58095fbc1e48779acfdb7a8c69d3b55e;hb=HEAD;hpb=bdf95351d3563e4039ee2cc229452d78b3b6a612 diff --git a/shell_port.c b/shell_port.c index 4e69179..9ac059d 100644 --- a/shell_port.c +++ b/shell_port.c @@ -2,16 +2,16 @@ void shell_port(char ** argv, int elem) { - int n, i; + int n, i, m, o; if (elem == 1) { - + printf(" port [show|diag|mirror] \n"); return; } if (strncmp(argv[1], "show", 4) == 0) { printf("Port\tSpeed\t\tBytes In\t\tBytes Out\n"); for (n = 0; n< 5; n++) { - printf("%i\t%s\t% 8lu\t\t% 8lu\n", n, + printf("%i\t%s\t%8lu\t\t%8lu\n", n, (settings.portStatistics[n].state == 0x05 ? "1000 Mbit/s" : (settings.portStatistics[n].state == 0x04 ? "100 Mbit/s" : (settings.portStatistics[n].state == 0x03 ? "10 Mbit/s": (settings.portStatistics[n].state == 0x00 ? "No Cable": "???")))), settings.portStatistics[n].bytesIn, settings.portStatistics[n].bytesOut @@ -25,7 +25,7 @@ void shell_port(char ** argv, int elem) { n = atoi(argv[2]); - if (n < 1 | n > 5) { + if ((n < 1) | (n > 5)) { printf("Invalid Port\n"); return; } @@ -48,5 +48,47 @@ void shell_port(char ** argv, int elem) { else printf("\033[92mCable is fine!\033[0m\n", settings.portStatistics[n].errorDist); } + } else if (strncmp(argv[1], "mirror", 6) == 0) { + + if (elem == 3) { + if (strncmp(argv[2], "off", 3) == 0) { + password(); + printError(gs105e_mirrorPorts(0, 0)); + return; + + } + } + + if (elem < 4) { + printf("port mirror output input [input.....]\n"); + return; + } + + n = atoi(argv[2]); + + if ((n < 1) | (n > 5)) { + printf("Invalid Port %i\n", n); + return; + } + + o = 0; + + for (m = 3; m < elem; m++) { + i = atoi(argv[m]); + if ((i < 1) | (i > 5)) { + printf("Invalid Port %i\n", i); + return; + } + + if (i == n) { + printf("Output can't be input port!\n"); + return; + } + + o |= (0x80 >> (i - 1)); + } + password(); + printError(gs105e_mirrorPorts(n, o)); + } }