X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2Fstat.c;h=e5a340e704ea05c802c59965214dd982c48fea76;hb=17cd5711411f45df26b33c51288780627b7377e2;hp=56f46953428170f43f1eff1a0dc935e8cde0533d;hpb=67fc54773e1504698e80c9cb83977bde32665350;p=ap-utils.git diff --git a/lib/stat.c b/lib/stat.c index 56f4695..e5a340e 100644 --- a/lib/stat.c +++ b/lib/stat.c @@ -25,67 +25,73 @@ #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, poll_delay; void EthStat() { - struct EthernetRxStatistics *EthRxStat = NULL; - struct EthernetTxStatistics *EthTxStat = NULL; + struct EthRxStatistics_s *EthRxStat = NULL; + struct EthTxStatistics_s *EthTxStat = NULL; - char EthRx[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, - 0x07, 0x01, 0x00 + char EthRxStatistics[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x07, 0x01, 0x00 }; - - char EthTx[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, - 0x07, 0x02, 0x00 + char EthTxStatistics[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 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; - EthRx[6] = 0x3E; - EthTx[5] = 0xE0; - EthTx[6] = 0x3E; + EthRxStatistics[5] = 0xE0; + EthRxStatistics[6] = 0x3E; + EthTxStatistics[5] = 0xE0; + EthTxStatistics[6] = 0x3E; } - print_title(_("Ethernet Statistics")); - print_help(QHELP); + print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, ETH_STAT); noecho(); - varbinds[0].oid = EthRx; - varbinds[0].len_oid = sizeof(EthRx); - varbinds[1].oid = EthTx; - varbinds[1].len_oid = sizeof(EthTx); + if (wait_mode == WAIT_TIMEOUT) + print_help(QT_HELP); + + varbinds[0].oid = EthRxStatistics; + varbinds[0].len_oid = sizeof(EthRxStatistics); + varbinds[1].oid = EthTxStatistics; + varbinds[1].len_oid = sizeof(EthTxStatistics); while (1) { -// varbinds[0].value = EthTx; +// varbinds[0].value = EthRxStatistics; varbinds[0].len_val = 0; varbinds[0].type = NULL_VALUE; -// varbinds[1].value = EthTx; +// varbinds[1].value = EthTxStatistics; varbinds[1].len_val = 0; varbinds[1].type = NULL_VALUE; - if (snmp(varbinds, 2, GET) <= 0) { + if (wait_mode == WAIT_FOREVER) + print_help(WAIT_RET); + + if (snmp(varbinds, 2, GET) < 2) { 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); EthRxStat = - (struct EthernetRxStatistics *) malloc(varbinds[0]. + (struct EthRxStatistics_s *) malloc(varbinds[0]. len_val); memcpy(EthRxStat, varbinds[0].value, varbinds[0].len_val); } else { @@ -98,7 +104,7 @@ void EthStat() if (EthTxStat) free(EthTxStat); EthTxStat = - (struct EthernetTxStatistics *) malloc(varbinds[1]. + (struct EthTxStatistics_s *) malloc(varbinds[1]. len_val); memcpy(EthTxStat, varbinds[1].value, varbinds[1].len_val); } else { @@ -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(poll_delay); + 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,57 +207,63 @@ void EthStat() free(EthTxStat); wclear(main_sub); - print_title(""); + print_top(NULL, NULL); clear_main(0); return; } void WirelessStat() { - struct WirelessStatistics *WirelessStat = NULL; + struct wirelessStatistics_s *WirelessStat = NULL; - char Wireless[] = - { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x03, 0x01, - 0x00 + char wirelessStatistics[] = { + 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x03, 0x01, 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; + wirelessStatistics[5] = 0xE0; + wirelessStatistics[6] = 0x3E; } - print_title(_("Wireless Statistics")); - print_help(QHELP); + print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, W_STAT); noecho(); - varbinds[0].oid = Wireless; - varbinds[0].len_oid = sizeof(Wireless); + if (wait_mode == WAIT_TIMEOUT) + print_help(QT_HELP); + + varbinds[0].oid = wirelessStatistics; + varbinds[0].len_oid = sizeof(wirelessStatistics); while (1) { - varbinds[0].value = Wireless; + varbinds[0].value = wirelessStatistics; 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 - * 104 .. using functionally enhanced ATMEL 12350 MIB by VERNET + * 104 .. using functionally enhanced ATMEL 12350 MIB by EZYNET */ if (WirelessStat) free(WirelessStat); WirelessStat = - (struct WirelessStatistics *) malloc(varbinds[0].len_val); + (struct wirelessStatistics_s *) malloc(varbinds[0].len_val); memcpy(WirelessStat, varbinds[0].value, varbinds[0].len_val); } else { print_helperr @@ -326,7 +331,8 @@ void WirelessStat() sprintf(message, "InvalidPLCP %10u", swap4(WirelessStat->InvalidPLCP)); mvwaddstr(main_sub, 15, 1, message); - /* ATMEL12350 MIB 'VERNET' modification has in addition the following */ + + /* ATMEL12350 MIB EZYNET modification has in addition the following */ if (varbinds[0].len_val == 104) { mvwaddstr(main_sub, 16, 1, "TransmittedPackets:"); sprintf(message, "* at 11 Mbps %10u", @@ -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(poll_delay); + 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 (snmp(varbinds, 16, GET) <= 0) { + + if (wait_mode == WAIT_FOREVER) + print_help(WAIT_RET); + + if (snmp(varbinds, 16, GET) < 16) { 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(poll_delay); + 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); } +