From de65eda001b33bea52c943e091b52e338144579b Mon Sep 17 00:00:00 2001 From: pdw <> Date: Tue, 2 Apr 2002 21:30:03 +0000 Subject: [PATCH] Minor cosmetic changes to UI. --- CHANGES | 10 +++++++++- Makefile | 2 +- ui.c | 36 +++++++++++++++++++++--------------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/CHANGES b/CHANGES index abeba87..3c6bf87 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,14 @@ Change log for iftop $Id$ -0.1 +0.2 02/04/02 + +Added -n option to analyse traffic flows across a network boundary. +Added cummulative traffic totals. +Graphs now optional. +UI more responsive to key presses. +Auto-sizing bar graph scale. + +0.1 29/3/02 First release. diff --git a/Makefile b/Makefile index 52581ca..bbebd8f 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ uninstall: %.o: %.c Makefile $(CC) $(CFLAGS) -c -o $@ $< -clean: nodepend +clean: rm -f *~ *.o core iftop tarball: depend $(SRCS) $(HDRS) $(TXTS) diff --git a/ui.c b/ui.c index 4abf4b1..946e1a0 100644 --- a/ui.c +++ b/ui.c @@ -58,15 +58,15 @@ int screen_line_compare(void* a, void* b) { return 1; } -void readable_size(float n, char* buf, int bsize, int ksize) { +void readable_size(float n, char* buf, int bsize, int ksize, int bytes) { if(n >= 100000) { - snprintf(buf, bsize, " %4.1fM", n / (ksize * ksize)); + snprintf(buf, bsize, " %4.1f%s", n / (ksize * ksize), bytes ? "MB" : "M"); } else if(n >= 1000) { - snprintf(buf, bsize, " %4.1fK", n / ksize); + snprintf(buf, bsize, " %4.1f%s", n / ksize, bytes ? "KB" : "K" ); } else { - snprintf(buf, bsize, " %4.0fb", n ); + snprintf(buf, bsize, " %4.0f%s", n, bytes ? "B" : "b"); } } @@ -103,7 +103,7 @@ static void draw_bar_scale(int* y) { for (i = 1; i <= scale[rateidx].max; i *= scale[rateidx].interval) { char s[40], *p; int x; - readable_size(i, s, sizeof s, 1000); + readable_size(i, s, sizeof s, 1000, 0); p = s + strspn(s, " "); x = get_bar_length(i); mvaddch(*y + 1, x, ACS_BTEE); @@ -134,10 +134,10 @@ void draw_line_totals(int y, host_pair_line* line) { for(j = 0; j < HISTORY_DIVISIONS; j++) { t = history_length(j); - readable_size(8 * line->sent[j] / t, buf, 10, 1024); + readable_size(8 * line->sent[j] / t, buf, 10, 1024, 0); mvaddstr(y, x, buf); - readable_size(8 * line->recv[j] / t, buf, 10, 1024); + readable_size(8 * line->recv[j] / t, buf, 10, 1024, 0); mvaddstr(y+1, x, buf); x += 8; } @@ -264,6 +264,11 @@ void ui_print() { attroff(A_REVERSE); addstr(options.dnsresolution ? " name resolution off " : " name resolution on "); + attron(A_REVERSE); + addstr(" B "); + attroff(A_REVERSE); + addstr(options.showbars ? " bar graphs off " + : " bar graphs on "); draw_bar_scale(&y); @@ -314,31 +319,32 @@ void ui_print() { mvaddstr(y, 0, "total: "); mvaddstr(y+1, 0, " peak: "); - readable_size((totals.recv[0] + totals.sent[0]) * 8 / RESOLUTION, line, 10, 1024); + readable_size((totals.recv[0] + totals.sent[0]) * 8 / RESOLUTION, line, 10, 1024, 0); mvaddstr(y, 8, line); - readable_size(peaktotal * 8 / RESOLUTION, line, 10, 1024); + readable_size(peaktotal * 8 / RESOLUTION, line, 10, 1024, 0); mvaddstr(y+1, 8, line); - readable_size((peakrecv + peaksent) * 8 / RESOLUTION, line, 10, 1024); + readable_size((peakrecv + peaksent) * 8 / RESOLUTION, line, 10, 1024, 0); mvaddstr(y+1, 8, line); mvaddstr(y, 18, "TX: "); mvaddstr(y+1, 18, "RX: "); - readable_size(history_totals.total_sent / RESOLUTION, line, 10, 1024); + /* Cummulative totals */ + readable_size(history_totals.total_sent, line, 10, 1024, 1); mvaddstr(y, 22, line); - readable_size(history_totals.total_recv / RESOLUTION, line, 10, 1024); + readable_size(history_totals.total_recv, line, 10, 1024, 1); mvaddstr(y+1, 22, line); + /* Peak traffic */ mvaddstr(y, 33, "peaks: "); - /* mvaddstr(y+1, 24, "recv: "); */ - readable_size(peaksent * 8 / RESOLUTION, line, 10, 1024); + readable_size(peaksent * 8 / RESOLUTION, line, 10, 1024, 0); mvaddstr(y, 39, line); - readable_size(peakrecv * 8 / RESOLUTION, line, 10, 1024); + readable_size(peakrecv * 8 / RESOLUTION, line, 10, 1024, 0); mvaddstr(y+1, 39, line); mvaddstr(y, COLS - 8 * HISTORY_DIVISIONS - 8, "totals:");