From ba1bdd7a8eb764383bbeef3827acb5f1af61a797 Mon Sep 17 00:00:00 2001 From: pdw <> Date: Fri, 25 Oct 2002 12:53:36 +0000 Subject: [PATCH] Added "freeze order" option. Talk about feature creep :-) --- Makefile | 2 +- options.c | 1 + options.h | 1 + ui.c | 39 +++++++++++++++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 5599d9b..bb66f3e 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ # $Id$ # -VERSION = 0.10pre2 +VERSION = 0.10pre3 # C compiler to use. #CC = gcc diff --git a/options.c b/options.c index 922f077..fff1c10 100644 --- a/options.c +++ b/options.c @@ -97,6 +97,7 @@ static void set_defaults() { options.bandwidth_in_bytes = 0; options.sort = OPTION_SORT_DIV2; options.screenfilter = NULL; + options.freezeorder = 0; } static void die(char *msg) { diff --git a/options.h b/options.h index 31934d2..19be78a 100644 --- a/options.h +++ b/options.h @@ -50,6 +50,7 @@ typedef struct { option_sort_t sort; char* screenfilter; + int freezeorder; } options_t; diff --git a/ui.c b/ui.c index 0422cde..450147c 100644 --- a/ui.c +++ b/ui.c @@ -47,6 +47,7 @@ " 1/2/3 - sort by 1st/2nd/3rd column\n"\ " < - sort by source name\n"\ " > - sort by dest name\n"\ +" o - freeze current order\n"\ "\n"\ "iftop, version " IFTOP_VERSION @@ -292,7 +293,7 @@ void screen_list_init() { sorted_list_initialise(&screen_list); } -void screen_data_clear() { +void screen_list_clear() { sorted_list_node* nn = NULL; peaksent = peakrecv = peaktotal = 0; while((nn = sorted_list_next_item(&screen_list, nn)) != NULL) { @@ -337,6 +338,18 @@ void make_screen_list() { } } +/* + * Zeros all data in the screen hash, but does not remove items. + */ +void screen_hash_clear() { + hash_node_type* n = NULL; + while(hash_next_item(screen_hash, &n) == HASH_STATUS_OK) { + host_pair_line* hpl = (host_pair_line*)n->rec; + memset(hpl->recv, 0, sizeof(hpl->recv)); + memset(hpl->sent, 0, sizeof(hpl->sent)); + } +} + void analyse_data() { hash_node_type* n = NULL; @@ -346,7 +359,13 @@ void analyse_data() { memset(&totals, 0, sizeof totals); - screen_data_clear(); + if(options.freezeorder) { + screen_hash_clear(); + } + else { + screen_list_clear(); + hash_delete_all(screen_hash); + } while(hash_next_item(history, &n) == HASH_STATUS_OK) { history_type* d = (history_type*)n->rec; @@ -356,6 +375,7 @@ void analyse_data() { int tsent, trecv; tsent = trecv = 0; + ap = *(addr_pair*)n->key; /* Aggregate hosts, if required */ @@ -399,9 +419,10 @@ void analyse_data() { } - make_screen_list(); + if(!options.freezeorder) { + make_screen_list(); + } - hash_delete_all(screen_hash); calculate_totals(); @@ -750,6 +771,16 @@ void ui_loop() { case 'P': options.paused = !options.paused; break; + case 'o': + if(options.freezeorder) { + options.freezeorder = 0; + showhelp("Order unfrozen"); + } + else { + options.freezeorder = 1; + showhelp("Order frozen"); + } + break; case '1': options.sort = OPTION_SORT_DIV1; showhelp("Sort by col 1");