summaryrefslogtreecommitdiff
path: root/iftop.c
diff options
context:
space:
mode:
authorpdw <>2014-01-01 14:37:31 +0000
committerpdw <>2014-01-01 14:37:31 +0000
commita9663192567697bfb217704cd67c34fd32a68389 (patch)
tree519a7c9cbc7d65b17d3c0a017f0de404be448326 /iftop.c
parent59cf360690c99ad5149305ce3600151fa0f1483b (diff)
downloadiftop-a9663192567697bfb217704cd67c34fd32a68389.zip
Patch for text output mode by originally by Patrik Bless, updated by Roman Hoog
Antink <rha@open.ch>
Diffstat (limited to 'iftop.c')
-rw-r--r--iftop.c50
1 files changed, 44 insertions, 6 deletions
diff --git a/iftop.c b/iftop.c
index f0e692f..3c7e58a 100644
--- a/iftop.c
+++ b/iftop.c
@@ -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);