X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2Fstat.c;h=7ebe726a926bc266899692df6468de6358ade8e1;hb=refs%2Ftags%2Fupstream%2F1.5.pre1;hp=56f46953428170f43f1eff1a0dc935e8cde0533d;hpb=67fc54773e1504698e80c9cb83977bde32665350;p=ap-utils.git diff --git a/lib/stat.c b/lib/stat.c index 56f4695..7ebe726 100644 --- a/lib/stat.c +++ b/lib/stat.c @@ -25,13 +25,13 @@ #include #include #include "ap-utils.h" -#include "ap-curses.h" -#define QHELP _("Q - quit to menu. Other key - force update.") -#define SELECT _("select() function error. Press any key.") +#define ETH_STAT _("Ethernet Statistics") +#define W_STAT _("Wireless Statistics") extern WINDOW *main_sub; extern short ap_type; +extern int wait_mode; void EthStat() { @@ -46,10 +46,8 @@ void EthStat() 0x07, 0x02, 0x00 }; char message[1024]; - int j; varbind varbinds[2]; - fd_set rds; - struct timeval timeout; + int i; if (ap_type == ATMEL12350) { EthRx[5] = 0xE0; @@ -58,10 +56,12 @@ void EthStat() EthTx[6] = 0x3E; } - print_title(_("Ethernet Statistics")); - print_help(QHELP); + print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, ETH_STAT); noecho(); + if (wait_mode == WAIT_TIMEOUT) + print_help(QT_HELP); + varbinds[0].oid = EthRx; varbinds[0].len_oid = sizeof(EthRx); varbinds[1].oid = EthTx; @@ -75,12 +75,18 @@ void EthStat() varbinds[1].len_val = 0; varbinds[1].type = NULL_VALUE; + if (wait_mode == WAIT_FOREVER) + print_help(WAIT_RET); + if (snmp(varbinds, 2, GET) <= 0) { print_helperr(ERR_RET); getch(); goto quit; } + if (wait_mode == WAIT_FOREVER) + print_help(QT_HELP); + if (varbinds[0].len_val == 64) { if (EthRxStat) free(EthRxStat); @@ -175,30 +181,23 @@ void EthStat() mvwaddstr(main_sub, 18, 2, message); wrefresh(main_sub); - timeout.tv_sec = 1; - timeout.tv_usec = 0; - FD_ZERO(&rds); - FD_SET(0, &rds); - - /* wait up to timeout until anything is avail. for reading on stdin */ - j = select(1, &rds, NULL, NULL, &timeout); - - /* error occured */ - if (j == -1) { - print_helperr(SELECT); - getch(); - break; - } - - /* not timed out => anything avail. for reading in &rds */ - if (j != 0) { - j = getc(stdin); - if (j == 'q' || j == 'Q') - break; + i = wait_key(); + if (i == -1) + goto quit; + switch((char) i) { + case 'q': + case 'Q': + goto quit; + case 't': + case 'T': + wait_mode = (wait_mode == WAIT_FOREVER ? + WAIT_TIMEOUT : WAIT_FOREVER); + print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, + ETH_STAT); } - /* j = 0 => timeout => continue looping */ + /* either timeout for user input (i == 0) or invalid key => continue */ } quit: @@ -208,7 +207,7 @@ void EthStat() free(EthTxStat); wclear(main_sub); - print_title(""); + print_top(NULL, NULL); clear_main(0); return; } @@ -222,20 +221,20 @@ void WirelessStat() 0x00 }; char message[80]; - int j; + int i; varbind varbinds[1]; - fd_set rds; - struct timeval timeout; if (ap_type == ATMEL12350) { Wireless[5] = 0xE0; Wireless[6] = 0x3E; } - print_title(_("Wireless Statistics")); - print_help(QHELP); + print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, W_STAT); noecho(); + if (wait_mode == WAIT_TIMEOUT) + print_help(QT_HELP); + varbinds[0].oid = Wireless; varbinds[0].len_oid = sizeof(Wireless); @@ -244,12 +243,18 @@ void WirelessStat() varbinds[0].len_val = 0; varbinds[0].type = NULL_VALUE; + if (wait_mode == WAIT_FOREVER) + print_help(WAIT_RET); + if (snmp(varbinds, 1, GET) <= 0) { print_helperr(ERR_RET); getch(); goto quit; } + if (wait_mode == WAIT_FOREVER) + print_help(QT_HELP); + if (varbinds[0].len_val == 88 || varbinds[0].len_val == 104) { /* * 88 ... using traditional ATMEL 12350 MIB @@ -326,6 +331,7 @@ void WirelessStat() sprintf(message, "InvalidPLCP %10u", swap4(WirelessStat->InvalidPLCP)); mvwaddstr(main_sub, 15, 1, message); + /* ATMEL12350 MIB 'VERNET' modification has in addition the following */ if (varbinds[0].len_val == 104) { mvwaddstr(main_sub, 16, 1, "TransmittedPackets:"); @@ -344,37 +350,30 @@ void WirelessStat() } wrefresh(main_sub); - timeout.tv_sec = 1; - timeout.tv_usec = 0; - FD_ZERO(&rds); - FD_SET(0, &rds); - - /* wait up to timeout until anything is avail. for reading on stdin */ - j = select(1, &rds, NULL, NULL, &timeout); - - /* error occured */ - if (j == -1) { - print_helperr(SELECT); - getch(); - break; - } - - /* not timed out => anything avail. for reading in &rds */ - if (j != 0) { - j = getc(stdin); - if (j == 'q' || j == 'Q') - break; + i = wait_key(); + if (i == -1) + goto quit; + switch((char) i) { + case 'q': + case 'Q': + goto quit; + case 't': + case 'T': + wait_mode = (wait_mode == WAIT_FOREVER ? + WAIT_TIMEOUT : WAIT_FOREVER); + print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, + W_STAT); } - /* j = 0 => timeout => continue looping */ + /* either timeout for user input (i == 0) or invalid key => continue */ } quit: if (WirelessStat) free(WirelessStat); wclear(main_sub); - print_title(""); + print_top(NULL, NULL); clear_main(0); } @@ -415,17 +414,17 @@ void nwn_wireless_stat() { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x05, 0x01, 0x06, 0x01 }; char message[80]; - int j; - fd_set rds; - struct timeval timeout; + int i; varbind varbinds[16]; curs_set(0); - print_title(_("Wireless Statistics")); - print_help(QHELP); + print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, W_STAT); noecho(); + if (wait_mode == WAIT_TIMEOUT) + print_help(QT_HELP); + varbinds[0].oid = oid_dot11TransmittedFragmentCount; varbinds[0].len_oid = sizeof(oid_dot11TransmittedFragmentCount); varbinds[1].oid = oid_dot11MulticastTransmittedFrameCount; @@ -460,17 +459,24 @@ void nwn_wireless_stat() varbinds[15].len_oid = sizeof(oid_dot11WEPExcludedCount); while (1) { - for (j = 0; j < 16; j++) { - varbinds[j].value = oid_dot11TransmittedFragmentCount; - varbinds[j].len_val = 0; - varbinds[j].type = 0x05; + for (i = 0; i < 16; i++) { + varbinds[i].value = oid_dot11TransmittedFragmentCount; + varbinds[i].len_val = 0; + varbinds[i].type = 0x05; } + + if (wait_mode == WAIT_FOREVER) + print_help(WAIT_RET); + if (snmp(varbinds, 16, GET) <= 0) { print_helperr(ERR_RET); getch(); goto quit; } + if (wait_mode == WAIT_FOREVER) + print_help(QT_HELP); + sprintf(message, "FragmentTx %10lu FragmentRx %10lu", (long) swap4(*varbinds[0].value), (long) swap4(*varbinds[9].value)); mvwaddstr(main_sub, 1, 1, message); @@ -504,34 +510,28 @@ void nwn_wireless_stat() mvwaddstr(main_sub, 10, 1, message); wrefresh(main_sub); - timeout.tv_sec = 1; - timeout.tv_usec = 0; - FD_ZERO(&rds); - FD_SET(0, &rds); - - /* wait up to timeout until anything is avail. for reading on stdin */ - j = select(1, &rds, NULL, NULL, &timeout); - - /* error occured */ - if (j == -1) { - print_helperr(SELECT); - getch(); - break; - } - - /* not timed out => anything avail. for reading in &rds */ - if (j != 0) { - j = getc(stdin); - if (j == 'q' || j == 'Q') - break; + i = wait_key(); + if (i == -1) + goto quit; + switch((char) i) { + case 'q': + case 'Q': + goto quit; + case 't': + case 'T': + wait_mode = (wait_mode == WAIT_FOREVER ? + WAIT_TIMEOUT : WAIT_FOREVER); + print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, + W_STAT); } - /* j = 0 => timeout => continue looping */ + /* either timeout for user input (i == 0) or invalid key => continue */ } quit: wclear(main_sub); - print_title(""); + print_top(NULL, NULL); clear_main(0); } +