Commit f9220018 authored by Bruno Randolf's avatar Bruno Randolf

move each window into a separate file

parent ed8a751c
......@@ -19,8 +19,12 @@
NAME=horst
DEBUG=0
PCAP=0
OBJS=protocol_parser.o main.o capture.o display.o network.o util.o \
ieee80211_util.o listsort.o wext.o
OBJS=main.o capture.o protocol_parser.o network.o wext.o \
util.o ieee80211_util.o listsort.o \
display.o display-main.o display-filter.o display-help.o \
display-statistics.o display-essid.o display-history.o \
display-spectrum.o
LIBS=-lncurses -lm
CFLAGS+=-Wall -DDO_DEBUG=$(DEBUG) -g
......
/******************* ESSID *******************/
#include <stdlib.h>
#include "display.h"
#include "main.h"
#include "util.h"
void
update_essid_win(WINDOW *win)
{
int i;
int line = 1;
struct essid_info* e;
struct node_info* node;
werase(win);
wattron(win, WHITE);
wattroff(win, A_BOLD);
box(win, 0 , 0);
print_centered(win, 0, COLS, " ESSIDs ");
mvwprintw(win, line++, 3, "NO. MODE SOURCE (BSSID) TSF (BINT) CH SNR E IP");
list_for_each_entry(e, &essids.list, list) {
if (line > LINES-3)
break;
wattron(win, WHITE | A_BOLD);
mvwprintw(win, line, 2, "ESSID '%s'", e->essid );
if (e->split > 0) {
wattron(win, RED);
wprintw(win, " *** SPLIT ***");
}
else
wattron(win, GREEN);
line++;
i = 1;
list_for_each_entry(node, &e->nodes, essid_nodes) {
if (line > LINES-3)
break;
if (node->last_seen > (the_time.tv_sec - conf.node_timeout / 2))
wattron(win, A_BOLD);
else
wattroff(win, A_BOLD);
mvwprintw(win, line, 3, "%2d. %s %s", i++,
node->wlan_mode == WLAN_MODE_AP ? "AP " : "IBSS",
ether_sprintf(node->last_pkt.wlan_src));
wprintw(win, " (%s)", ether_sprintf(node->wlan_bssid));
wprintw(win, " %016llx", node->wlan_tsf);
wprintw(win, " (%d)", node->wlan_bintval);
if (node->wlan_bintval < 1000)
wprintw(win, " ");
wprintw(win, " %2d", node->wlan_channel);
wprintw(win, " %2ddB", node->phy_snr);
wprintw(win, " %s", node->wlan_wep ? "W" : " ");
if (node->pkt_types & PKT_TYPE_IP)
wprintw(win, " %s", ip_sprintf(node->ip_src));
line++;
}
}
wnoutrefresh(win);
}
/******************* FILTER *******************/
#include <stdlib.h>
#include "display.h"
#include "main.h"
#include "util.h"
#define CHECKED(_x) (conf.filter_pkt & (_x)) ? '*' : ' '
#define CHECK_ETHER(_mac) MAC_NOT_EMPTY(_mac) ? '*' : ' '
#define CHECK_FILTER_EN(_i) conf.filtermac_enabled[_i] ? '*' : ' '
#define MAC_COL 30
extern WINDOW *filter_win;
void
update_filter_win(void)
{
int l, i;
box(filter_win, 0 , 0);
print_centered(filter_win, 0, 57, " Edit Packet Filter ");
mvwprintw(filter_win, 2, 2, "Show these Packet Types");
l = 4;
wattron(filter_win, A_BOLD);
mvwprintw(filter_win, l++, 2, "m: [%c] MANAGEMENT FRAMES", CHECKED(PKT_TYPE_MGMT));
wattroff(filter_win, A_BOLD);
mvwprintw(filter_win, l++, 2, "b: [%c] Beacons", CHECKED(PKT_TYPE_BEACON));
mvwprintw(filter_win, l++, 2, "p: [%c] Probe Req/Resp", CHECKED(PKT_TYPE_PROBE));
mvwprintw(filter_win, l++, 2, "a: [%c] Association", CHECKED(PKT_TYPE_ASSOC));
mvwprintw(filter_win, l++, 2, "u: [%c] Authentication", CHECKED(PKT_TYPE_AUTH));
l++;
wattron(filter_win, A_BOLD);
mvwprintw(filter_win, l++, 2, "c: [%c] CONTROL FRAMES", CHECKED(PKT_TYPE_CTRL));
wattroff(filter_win, A_BOLD);
mvwprintw(filter_win, l++, 2, "r: [%c] CTS/RTS", CHECKED(PKT_TYPE_CTS | PKT_TYPE_RTS));
mvwprintw(filter_win, l++, 2, "k: [%c] ACK", CHECKED(PKT_TYPE_ACK));
l++;
wattron(filter_win, A_BOLD);
mvwprintw(filter_win, l++, 2, "d: [%c] DATA FRAMES", CHECKED(PKT_TYPE_DATA));
wattroff(filter_win, A_BOLD);
mvwprintw(filter_win, l++, 2, "n: [%c] Null Data", CHECKED(PKT_TYPE_NULL));
mvwprintw(filter_win, l++, 2, "R: [%c] ARP", CHECKED(PKT_TYPE_ARP));
mvwprintw(filter_win, l++, 2, "P: [%c] ICMP/PING", CHECKED(PKT_TYPE_ICMP));
mvwprintw(filter_win, l++, 2, "I: [%c] IP", CHECKED(PKT_TYPE_IP));
mvwprintw(filter_win, l++, 2, "U: [%c] UDP", CHECKED(PKT_TYPE_UDP));
mvwprintw(filter_win, l++, 2, "T: [%c] TCP", CHECKED(PKT_TYPE_TCP));
mvwprintw(filter_win, l++, 2, "O: [%c] OLSR", CHECKED(PKT_TYPE_OLSR));
mvwprintw(filter_win, l++, 2, "B: [%c] BATMAN", CHECKED(PKT_TYPE_BATMAN));
l = 4;
wattron(filter_win, A_BOLD);
mvwprintw(filter_win, l++, MAC_COL, "BSSID");
wattroff(filter_win, A_BOLD);
mvwprintw(filter_win, l++, MAC_COL, "s: [%c] %s",
CHECK_ETHER(conf.filterbssid), ether_sprintf(conf.filterbssid));
l++;
mvwprintw(filter_win, l++, MAC_COL, "Show only these");
wattron(filter_win, A_BOLD);
mvwprintw(filter_win, l++, MAC_COL, "Source MAC ADDRESSES");
wattroff(filter_win, A_BOLD);
for (i = 0; i < MAX_FILTERMAC; i++) {
mvwprintw(filter_win, l++, MAC_COL, "%d: [%c] %s", i+1,
CHECK_FILTER_EN(i), ether_sprintf(conf.filtermac[i]));
}
l++;
wattron(filter_win, A_BOLD);
mvwprintw(filter_win, l++, MAC_COL, "o: [%c] All Filters Off", conf.filter_off ? '*' : ' ' );
wattroff(filter_win, A_BOLD);
print_centered(filter_win, 24, 57, "[ Press key or ENTER ]");
wrefresh(filter_win);
}
void
filter_input(int c)
{
char buf[18];
int i;
switch (c) {
case 'm':
TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_MGMT);
if (conf.filter_pkt & PKT_TYPE_MGMT)
conf.filter_pkt |= PKT_TYPE_ALL_MGMT;
else
conf.filter_pkt &= ~PKT_TYPE_ALL_MGMT;
break;
case 'b': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_BEACON); break;
case 'p': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_PROBE); break;
case 'a': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ASSOC); break;
case 'u': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_AUTH); break;
case 'c':
TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_CTRL);
if (conf.filter_pkt & PKT_TYPE_CTRL)
conf.filter_pkt |= PKT_TYPE_ALL_CTRL;
else
conf.filter_pkt &= ~PKT_TYPE_ALL_CTRL;
break;
case 'r': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_CTS | PKT_TYPE_RTS); break;
case 'k': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ACK); break;
case 'd':
TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_DATA);
if (conf.filter_pkt & PKT_TYPE_DATA)
conf.filter_pkt |= PKT_TYPE_ALL_DATA;
else
conf.filter_pkt &= ~PKT_TYPE_ALL_DATA;
break;
case 'n': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_NULL); break;
case 'R': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ARP); break;
case 'P': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ICMP); break;
case 'I': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_IP); break;
case 'U': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_UDP); break;
case 'T': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_TCP); break;
case 'O': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_OLSR|PKT_TYPE_OLSR_LQ|PKT_TYPE_OLSR_GW); break;
case 'B': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_BATMAN); break;
case 'q': case 'Q':
finish_all(0);
case 'f': case 'F': case '\r': case KEY_ENTER:
delwin(filter_win);
filter_win = NULL;
update_display(NULL, NULL);
return;
case 's':
echo();
print_centered(filter_win, 24, 57, "[ Enter new BSSID and ENTER ]");
mvwgetnstr(filter_win, 5, MAC_COL + 7, buf, 17);
noecho();
convert_string_to_mac(buf, conf.filterbssid);
break;
case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
i = c - '1';
if (MAC_NOT_EMPTY(conf.filtermac[i]) && conf.filtermac_enabled[i]) {
conf.filtermac_enabled[i] = 0;
}
else {
echo();
print_centered(filter_win, 24, 57, "[ Enter new MAC %d and ENTER ]", i+1);
mvwgetnstr(filter_win, 9 + i, MAC_COL + 7, buf, 17);
noecho();
/* just enable old MAC if user pressed return only */
if (*buf == '\0' && MAC_NOT_EMPTY(conf.filtermac[i]))
conf.filtermac_enabled[i] = 1;
else {
convert_string_to_mac(buf, conf.filtermac[i]);
if (MAC_NOT_EMPTY(conf.filtermac[i]))
conf.filtermac_enabled[i] = true;
}
}
break;
case 'o':
conf.filter_off = conf.filter_off ? 0 : 1;
break;
default:
return;
}
/* convenience: */
/* if one of the individual mgmt frames is deselected we dont want to see all mgmt frames */
if ((conf.filter_pkt & PKT_TYPE_ALL_MGMT) != PKT_TYPE_ALL_MGMT)
conf.filter_pkt = conf.filter_pkt & ~PKT_TYPE_MGMT;
/* same for ctl */
if ((conf.filter_pkt & PKT_TYPE_ALL_CTRL) != PKT_TYPE_ALL_CTRL)
conf.filter_pkt = conf.filter_pkt & ~PKT_TYPE_CTRL;
/* same for data */
if ((conf.filter_pkt & PKT_TYPE_ALL_DATA) != PKT_TYPE_ALL_DATA)
conf.filter_pkt = conf.filter_pkt & ~PKT_TYPE_DATA;
/* recalculate filter flag */
conf.do_macfilter = 0;
for (i = 0; i < MAX_FILTERMAC; i++) {
if (conf.filtermac_enabled[i])
conf.do_macfilter = 1;
}
update_filter_win();
}
/******************* HELP *******************/
#include <stdlib.h>
#include "display.h"
#include "main.h"
#include "util.h"
void
update_help_win(WINDOW *win)
{
int i, l;
char c;
werase(win);
wattron(win, WHITE);
box(win, 0 , 0);
print_centered(win, 0, COLS, " Help ");
print_centered(win, 2, COLS, "HORST - Horsts OLSR Radio Scanning Tool");
print_centered(win, 3, COLS, "Version " VERSION " (build date " __DATE__ " " __TIME__ ")");
mvwprintw(win, 5, 2, "(C) 2005-2010 Bruno Randolf, Licensed under the GPLv2");
mvwprintw(win, 7, 2, "Known IEEE802.11 Packet Types:");
l = 9;
/* this is weird but it works */
mvwprintw(win, l++, 2, "MANAGEMENT FRAMES");
for (i = 0x00; i <= 0xD0; i = i + 0x10) {
c = get_packet_type_char(i);
if (c != '?')
mvwprintw(win, l++, 4, "%c %s", c, get_packet_type_name(i));
}
l = 9;
mvwprintw(win, l++, 25, "CONTROL FRAMES");
for (i = 0xa4; i <= 0xF4; i = i + 0x10) {
c = get_packet_type_char(i);
if (c != '?')
mvwprintw(win, l++, 27, "%c %s", c, get_packet_type_name(i));
}
l = 9;
mvwprintw(win, l++, 50, "DATA FRAMES");
for (i = 0x08; i <+ 0xF8; i = i + 0x10) {
c = get_packet_type_char(i);
if (c != '?')
mvwprintw(win, l++, 52, "%c %s", c, get_packet_type_name(i));
}
mvwprintw(win, ++l, 2, "For more info read the README or check http://br1.einfach.org/horst/");
wrefresh(win);
}
/******************* HISTORY *******************/
#include <stdlib.h>
#include "display.h"
#include "main.h"
#include "util.h"
#define SIGN_POS LINES-17
#define TYPE_POS SIGN_POS+1
#define RATE_POS LINES-2
void
update_history_win(WINDOW *win)
{
int i;
int col = COLS-2;
int sig, noi, rat;
if (col > MAX_HISTORY)
col = 4 + MAX_HISTORY;
werase(win);
wattron(win, WHITE);
box(win, 0 , 0);
print_centered(win, 0, COLS, " Signal/Noise/Rate History ");
mvwhline(win, SIGN_POS, 1, ACS_HLINE, col);
mvwhline(win, SIGN_POS+2, 1, ACS_HLINE, col);
mvwvline(win, 1, 4, ACS_VLINE, LINES-3);
mvwprintw(win, 1, 1, "dBm");
mvwprintw(win, normalize_db(30, SIGN_POS), 1, "-30");
mvwprintw(win, normalize_db(40, SIGN_POS), 1, "-40");
mvwprintw(win, normalize_db(50, SIGN_POS), 1, "-50");
mvwprintw(win, normalize_db(60, SIGN_POS), 1, "-60");
mvwprintw(win, normalize_db(70, SIGN_POS), 1, "-70");
mvwprintw(win, normalize_db(80, SIGN_POS), 1, "-80");
mvwprintw(win, normalize_db(90, SIGN_POS), 1, "-90");
mvwprintw(win, SIGN_POS-1, 1, "-99");
wattron(win, GREEN);
mvwprintw(win, 1, col-6, "Signal");
wattron(win, RED);
mvwprintw(win, 2, col-5, "Noise");
wattron(win, CYAN);
mvwprintw(win, TYPE_POS, 1, "TYP");
mvwprintw(win, 3, col-11, "Packet Type");
wattron(win, A_BOLD);
wattron(win, BLUE);
mvwprintw(win, 4, col-4, "Rate");
mvwprintw(win, RATE_POS-12, 1, "54M");
mvwprintw(win, RATE_POS-11, 1, "48M");
mvwprintw(win, RATE_POS-10, 1, "36M");
mvwprintw(win, RATE_POS-9, 1, "24M");
mvwprintw(win, RATE_POS-8, 1, "18M");
mvwprintw(win, RATE_POS-7, 1, "12M");
mvwprintw(win, RATE_POS-6, 1, "11M");
mvwprintw(win, RATE_POS-5, 1, " 9M");
mvwprintw(win, RATE_POS-4, 1, " 6M");
mvwprintw(win, RATE_POS-3, 1, "5.M");
mvwprintw(win, RATE_POS-2, 1, " 2M");
mvwprintw(win, RATE_POS-1, 1, " 1M");
wattroff(win, A_BOLD);
i = hist.index - 1;
while (col > 4 && hist.signal[i] != 0)
{
sig = normalize_db(-hist.signal[i], SIGN_POS);
if (hist.noise[i])
noi = normalize_db(-hist.noise[i], SIGN_POS);
wattron(win, ALLGREEN);
mvwvline(win, sig, col, ACS_BLOCK, SIGN_POS-sig);
if (hist.noise[i]) {
wattron(win, ALLRED);
mvwvline(win, noi, col, '=', SIGN_POS-noi);
}
wattron(win, CYAN);
mvwprintw(win, TYPE_POS, col, "%c", \
get_packet_type_char(hist.type[i]));
if (hist.retry[i])
mvwprintw(win, TYPE_POS+1, col, "r");
switch (hist.rate[i]/2) {
case 54: rat = 12; break;
case 48: rat = 11; break;
case 36: rat = 10; break;
case 24: rat = 9; break;
case 18: rat = 8; break;
case 12: rat = 7; break;
case 11: rat = 6; break;
case 9: rat = 5; break;
case 6: rat = 4; break;
case 5: rat = 3; break;
case 2: rat = 2; break;
case 1: rat = 1; break;
default: rat = 0;
}
wattron(win, A_BOLD);
wattron(win, BLUE);
mvwvline(win, RATE_POS - rat, col, 'x', rat);
wattroff(win, A_BOLD);
i--;
col--;
if (i < 0)
i = MAX_HISTORY-1;
}
wnoutrefresh(win);
}
This diff is collapsed.
/******************* SPECTRUM ANALYZER *******************/
#include <stdlib.h>
#include "display.h"
#include "main.h"
#include "util.h"
#define CH_SPACE 5
#define SPEC_HEIGHT (LINES - 11)
#define SPEC_POS_Y 7
#define SPEC_POS_X 6
void
update_spectrum_win(WINDOW *win)
{
int i, sig, sig_avg, siga;
struct chan_node *cn;
const char *id;
werase(win);
wattron(win, WHITE);
box(win, 0 , 0);
print_centered(win, 0, COLS, " Spectrum Analyzer ");
mvwprintw(win, 2, 2, "Current Channel:");
mvwprintw(win, 2, 19, "%d ", channels[conf.current_channel].chan);
mvwprintw(win, 3, 2, "c: [%c] Automatically Change Channel", conf.do_change_channel ? '*' : ' ');
mvwprintw(win, 4, 2, "d: Channel Dwell Time: %d ms", conf.channel_time/1000);
mvwprintw(win, 5, 2, "m: Manually Enter Channel: ");
mvwprintw(win, SPEC_POS_Y+1, 1, "dBm");
for(i = -30; i > -100; i -= 10) {
sig = normalize_db(-i, SPEC_HEIGHT);
mvwprintw(win, SPEC_POS_Y+sig, 1, "%d", i);
}
mvwhline(win, LINES-4, 1, ACS_HLINE, COLS-2);
mvwvline(win, SPEC_POS_Y, 4, ACS_VLINE, LINES-SPEC_POS_Y-2);
for (i = 0; i < conf.num_channels; i++) {
sig_avg = iir_average_get(spectrum[i].signal_avg);
mvwprintw(win, 7, SPEC_POS_X+CH_SPACE*i, "%d", spectrum[i].num_nodes);
mvwprintw(win, 8, SPEC_POS_X+CH_SPACE*i, "%d", spectrum[i].signal);
if (spectrum[i].packets > 8)
mvwprintw(win, 9, SPEC_POS_X+CH_SPACE*i, "%d", sig_avg);
mvwprintw(win, LINES-3, SPEC_POS_X+CH_SPACE*i, "%02d", channels[i].chan);
if (spectrum[i].signal != 0) {
sig = normalize_db(-spectrum[i].signal, SPEC_HEIGHT);
wattron(win, ALLGREEN);
mvwvline(win, SPEC_POS_Y+sig, SPEC_POS_X+CH_SPACE*i, ACS_BLOCK,
SPEC_HEIGHT - sig);
mvwvline(win, SPEC_POS_Y+sig, SPEC_POS_X+CH_SPACE*i+1, ACS_BLOCK,
SPEC_HEIGHT - sig);
}
if (spectrum[i].packets > 8 && sig_avg != 0) {
siga = normalize_db(-sig_avg, SPEC_HEIGHT);
if (siga > 1) {
wattron(win, A_BOLD);
mvwvline(win, SPEC_POS_Y+siga, SPEC_POS_X+CH_SPACE*i, '=',
SPEC_HEIGHT - siga);
wattroff(win, A_BOLD);
}
}
wattroff(win, ALLGREEN);
/* show nodes */
list_for_each_entry(cn, &spectrum[i].nodes, chan_list) {
if (cn->packets >= 8)
sig = normalize_db(-iir_average_get(cn->sig_avg), SPEC_HEIGHT);
else
sig = normalize_db(-cn->sig, SPEC_HEIGHT);
if (cn->node->ip_src)
id = ip_sprintf_short(cn->node->ip_src);
else
id = ether_sprintf_short(cn->node->last_pkt.wlan_src);
mvwprintw(win, SPEC_POS_Y+sig, SPEC_POS_X+CH_SPACE*i, "%s", id);
}
}
wnoutrefresh(win);
}
int
spectrum_input(WINDOW *win, int c)
{
char buf[6];
int x;
switch (c) {
case 'c': case 'C':
conf.do_change_channel = conf.do_change_channel ? 0 : 1;
break;
case 'm': case 'M':
conf.do_change_channel = 0;
echo();
curs_set(1);
mvwgetnstr(win, 5, 29, buf, 2);
curs_set(0);
noecho();
sscanf(buf, "%d", &x);
if (x > 0)
change_channel(x);
break;
case 'd': case 'D':
echo();
curs_set(1);
mvwgetnstr(win, 4, 25, buf, 6);
curs_set(0);
noecho();
sscanf(buf, "%d", &x);
conf.channel_time = x*1000;
break;
default:
return 0; /* didn't handle input */
}
return 1;
}
/******************* STATISTICS *******************/
#include <stdlib.h>
#include "display.h"
#include "main.h"
#include "util.h"
#define STAT_PACK_POS 9
#define STAT_BYTE_POS (STAT_PACK_POS + 9)
#define STAT_BPP_POS (STAT_BYTE_POS + 9)
#define STAT_PP_POS (STAT_BPP_POS + 6)
#define STAT_BP_POS (STAT_PP_POS + 6)
#define STAT_AIR_POS (STAT_BP_POS + 6)
#define STAT_AIRG_POS (STAT_AIR_POS + 6)
void
update_statistics_win(WINDOW *win)
{
int i;
int line;
int bps, dps;
float duration;
werase(win);
wattron(win, WHITE);
box(win, 0 , 0);
print_centered(win, 0, COLS, " Packet Statistics ");
if (stats.packets == 0) {
wnoutrefresh(win);
return; /* avoid floating point exceptions */
}
mvwprintw(win, 2, 2, "Packets: %d",stats.packets );
mvwprintw(win, 3, 2, "Bytes: %s (%d)", kilo_mega_ize(stats.bytes), stats.bytes );
mvwprintw(win, 4, 2, "Average: ~%d B/Pkt", stats.bytes/stats.packets);
get_per_second(stats.bytes, stats.duration, &bps, &dps);
bps = bps * 8;
mvwprintw(win, 2, 40, "Total bit/sec: %s (%d)", kilo_mega_ize(bps), bps);
wattron(win, A_BOLD);
mvwprintw(win, 3, 40, "Total Usage: %3.1f%% (%d)", dps * 1.0 / 10000, dps ); /* usec in % */
wattroff(win, A_BOLD);
line = 6;
mvwprintw(win, line, STAT_PACK_POS, " Packets");
mvwprintw(win, line, STAT_BYTE_POS, " Bytes");
mvwprintw(win, line, STAT_BPP_POS, "~B/P");
mvwprintw(win, line, STAT_PP_POS, "Pkts%%");
mvwprintw(win, line, STAT_BP_POS, "Byte%%");
wattron(win, A_BOLD);
mvwprintw(win, line, STAT_AIR_POS, "Usage%%");
mvwprintw(win, line++, 2, "RATE");
wattroff(win, A_BOLD);
mvwhline(win, line++, 2, '-', COLS-4);
for (i = 1; i < MAX_RATES; i++) {
if (stats.packets_per_rate[i] > 0) {
wattron(win, A_BOLD);
mvwprintw(win, line, 2, "%3dM", i/2);
wattroff(win, A_BOLD);
mvwprintw(win, line, STAT_PACK_POS, "%8d",
stats.packets_per_rate[i]);
mvwprintw(win, line, STAT_BYTE_POS, "%8s",
kilo_mega_ize(stats.bytes_per_rate[i]));
mvwprintw(win, line, STAT_BPP_POS, "%4d",
stats.bytes_per_rate[i] / stats.packets_per_rate[i]);
mvwprintw(win, line, STAT_PP_POS, "%2.1f",
stats.packets_per_rate[i] * 100.0 / stats.packets);
mvwprintw(win, line, STAT_BP_POS, "%2.1f",
stats.bytes_per_rate[i] * 100.0 / stats.bytes);
wattron(win, A_BOLD);
duration = stats.duration_per_rate[i] * 100.0 / stats.duration;
mvwprintw(win, line, STAT_AIR_POS, "%2.1f", duration);
mvwhline(win, line, STAT_AIRG_POS, '*',
normalize(duration, 100, COLS - STAT_AIRG_POS - 2));
wattroff(win, A_BOLD);
line++;
}
}
line++;
mvwprintw(win, line, STAT_PACK_POS, " Packets");
mvwprintw(win, line, STAT_BYTE_POS, " Bytes");
mvwprintw(win, line, STAT_BPP_POS, "~B/P");
mvwprintw(win, line, STAT_PP_POS, "Pkts%%");
mvwprintw(win, line, STAT_BP_POS, "Byte%%");
wattron(win, A_BOLD);
mvwprintw(win, line, STAT_AIR_POS, "Usage%%");
mvwprintw(win, line++, 2, "TYPE");
wattroff(win, A_BOLD);
mvwhline(win, line++, 2, '-', COLS - 4);
for (i = 0; i < MAX_FSTYPE; i++) {
if (stats.packets_per_type[i] > 0) {
wattron(win, A_BOLD);
mvwprintw(win, line, 2, "%s", get_packet_type_name(i));
wattroff(win, A_BOLD);
mvwprintw(win, line, STAT_PACK_POS, "%8d",
stats.packets_per_type[i]);
mvwprintw(win, line, STAT_BYTE_POS, "%8s",
kilo_mega_ize(stats.bytes_per_type[i]));
mvwprintw(win, line, STAT_BPP_POS, "%4d",
stats.bytes_per_type[i] / stats.packets_per_type[i]);
mvwprintw(win, line, STAT_PP_POS, "%2.1f",
stats.packets_per_type[i] * 100.0 / stats.packets);
mvwprintw(win, line, STAT_BP_POS, "%2.1f",
stats.bytes_per_type[i] * 100.0 / stats.bytes);
wattron(win, A_BOLD);
if (stats.duration > 0)
duration = stats.duration_per_type[i] * 100.0 / stats.duration;
else
duration = 100.0;
mvwprintw(win, line, STAT_AIR_POS, "%2.1f", duration);
mvwhline(win, line, STAT_AIRG_POS, '*',
normalize(duration, 100, COLS - STAT_AIRG_POS - 2));
wattroff(win, A_BOLD);
line++;
}
}
wnoutrefresh(win);
}
This diff is collapsed.
......@@ -20,9 +20,32 @@
#ifndef _DISPLAY_H_
#define _DISPLAY_H_
#include <curses.h>
#define WHITE COLOR_PAIR(1)
#define GREEN COLOR_PAIR(2)
#define RED COLOR_PAIR(3)
#define CYAN COLOR_PAIR(4)
#define BLUE COLOR_PAIR(5)
#define BLACKONWHITE COLOR_PAIR(6)
#define MAGENTA COLOR_PAIR(7)
#define ALLGREEN COLOR_PAIR(8)
#define ALLRED COLOR_PAIR(9)
#define ALLBLUE COLOR_PAIR(10)
#define ALLCYAN COLOR_PAIR(11)
#define YELLOW COLOR_PAIR(12)
#define ALLYELLOW COLOR_PAIR(13)
#define WHITEONRED COLOR_PAIR(14)
struct packet_info;
struct node_info;
void
get_per_second(unsigned int bytes, unsigned int duration, int *bps, int *dps);