Patch for text output mode by originally by Patrik Bless, updated by Roman Hoog

Antink <rha@open.ch>
This commit is contained in:
pdw
2014-01-01 14:37:31 +00:00
parent 59cf360690
commit a966319256
9 changed files with 522 additions and 377 deletions

50
iftop.c
View File

@@ -32,7 +32,9 @@
#include "iftop.h"
#include "addr_hash.h"
#include "resolver.h"
#include "ui_common.h"
#include "ui.h"
#include "tui.h"
#include "options.h"
#ifdef DLT_LINUX_SLL
#include "sll.h"
@@ -65,6 +67,7 @@ extern options_t options;
hash_type* history;
history_type history_totals;
time_t last_timestamp;
time_t first_timestamp;
int history_pos = 0;
int history_len = 1;
pthread_mutex_t tick_mutex;
@@ -141,12 +144,27 @@ void tick(int print) {
t = time(NULL);
if(t - last_timestamp >= RESOLUTION) {
analyse_data();
ui_print();
if (options.no_curses) {
if (!options.timed_output || options.timed_output && t - first_timestamp >= options.timed_output) {
tui_print();
if (options.timed_output) {
finish(SIGINT);
}
}
}
else {
ui_print();
}
history_rotate();
last_timestamp = t;
}
else {
ui_tick(print);
if (options.no_curses) {
tui_tick(print);
}
else {
ui_tick(print);
}
}
pthread_mutex_unlock(&tick_mutex);
@@ -247,6 +265,8 @@ static void handle_ip_packet(struct ip* iptr, int hw_dir)
memset(&ap, '\0', sizeof(ap));
tick(0);
if( (IP_V(iptr) ==4 && options.netfilter == 0)
|| (IP_V(iptr) == 6 && options.netfilter6 == 0) ) {
/*
@@ -570,8 +590,6 @@ static void handle_eth_packet(unsigned char* args, const struct pcap_pkthdr* pkt
ether_type = ntohs(eptr->ether_type);
payload = packet + sizeof(struct ether_header);
tick(0);
if(ether_type == ETHERTYPE_8021Q) {
struct vlan_8021q_header* vptr;
vptr = (struct vlan_8021q_header*)payload;
@@ -784,11 +802,31 @@ int main(int argc, char **argv) {
init_history();
ui_init();
if (options.no_curses) {
tui_init();
}
else {
ui_init();
}
pthread_create(&thread, NULL, (void*)&packet_loop, NULL);
ui_loop();
/* Keep the starting time (used for timed termination) */
first_timestamp = time(NULL);
if (options.no_curses) {
if (options.timed_output) {
while(!foad) {
sleep(1);
}
}
else {
tui_loop();
}
}
else {
ui_loop();
}
pthread_cancel(thread);