1) we are always printing to the last line of the given window, so get
this value in here and don't pass it as arg to this function
2) compute elapsed time before calling printelapsedtime() and pass it as
one arg only
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/detstats.c | 2 +-
src/hostmon.c | 3 +--
src/ifstats.c | 2 +-
src/itrafmon.c | 3 +--
src/pktsize.c | 3 +--
src/serv.c | 2 +-
src/timer.c | 12 ++++--------
src/timer.h | 2 +-
8 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c
index f70dae4..7df10b6 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -621,7 +621,7 @@ void detstats(char *iface, time_t facilitytime)
ifrates_show(&ifrates, statwin);
wattrset(statwin, BOXATTR);
- printelapsedtime(starttime, now.tv_sec, LINES - 3, 1, statwin);
+ printelapsedtime(now.tv_sec - starttime, 1, statwin);
dropped += packet_get_dropped(fd);
print_packet_drops(dropped, statwin, LINES - 3, 49);
diff --git a/src/hostmon.c b/src/hostmon.c
index aa769ef..5b6049d 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -989,8 +989,7 @@ void hostmon(time_t facilitytime, char *ifptr)
updateethrates(&table, msecs);
print_visible_rates(&table);
- printelapsedtime(starttime, now.tv_sec, LINES - 3, 15,
- table.borderwin);
+ printelapsedtime(now.tv_sec - starttime, 15, table.borderwin);
dropped += packet_get_dropped(fd);
print_packet_drops(dropped, table.borderwin, LINES - 3, 49);
diff --git a/src/ifstats.c b/src/ifstats.c
index 4e8482f..7b1151b 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -582,7 +582,7 @@ void ifstats(time_t facilitytime)
updaterates(&table, msecs);
showrates(&table);
- printelapsedtime(starttime, now.tv_sec, LINES - 3, 1, table.borderwin);
+ printelapsedtime(now.tv_sec - starttime, 1, table.borderwin);
dropped += packet_get_dropped(fd);
print_packet_drops(dropped, table.borderwin, LINES - 3, 49);
diff --git a/src/itrafmon.c b/src/itrafmon.c
index 393d07a..b40b77b 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -709,8 +709,7 @@ void ipmon(time_t facilitytime, char *ifptr)
print_flowrate(&table);
/* print timer at bottom of screen */
- printelapsedtime(starttime, now.tv_sec, othptbl.obmaxy - 1, 15,
- othptbl.borderwin);
+ printelapsedtime(now.tv_sec - starttime, 15, othptbl.borderwin);
dropped += packet_get_dropped(fd);
print_packet_drops(dropped, othptbl.borderwin, othptbl.obmaxy - 1, 40);
diff --git a/src/pktsize.c b/src/pktsize.c
index 668b103..1ebd58d 100644
--- a/src/pktsize.c
+++ b/src/pktsize.c
@@ -268,8 +268,7 @@ void packet_size_breakdown(char *ifname, time_t facilitytime)
updtime = tv;
}
if (now - timeint >= 5) {
- printelapsedtime(starttime, now, LINES - 3, 1,
- borderwin);
+ printelapsedtime(now - starttime, 1, borderwin);
dropped += packet_get_dropped(fd);
print_packet_drops(dropped, borderwin, LINES - 3, 49);
timeint = now;
diff --git a/src/serv.c b/src/serv.c
index f8ea1d5..69bdc65 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -985,7 +985,7 @@ void servmon(char *ifname, time_t facilitytime)
/* ... and print the current one */
print_serv_rates(&list);
- printelapsedtime(starttime, now.tv_sec, LINES - 4, 20, list.borderwin);
+ printelapsedtime(now.tv_sec - starttime, 20, list.borderwin);
dropped += packet_get_dropped(fd);
print_packet_drops(dropped, list.borderwin, LINES - 4, 49);
diff --git a/src/timer.c b/src/timer.c
index 08fed75..557d50e 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -10,16 +10,12 @@ timer.c - module to display the elapsed time since a facility
#include "iptraf-ng-compat.h"
-void printelapsedtime(time_t start, time_t now, int y, int x, WINDOW * win)
+void printelapsedtime(time_t elapsed, int x, WINDOW *win)
{
- time_t elapsed;
- unsigned int hours;
- unsigned int mins;
+ unsigned int hours = elapsed / 3600;
+ unsigned int mins = (elapsed % 3600) / 60;
- elapsed = now - start;
-
- hours = elapsed / 3600;
- mins = (elapsed % 3600) / 60;
+ int y = getmaxy(win) - 1;
mvwprintw(win, y, x, " Elapsed time: %3u:%02u ", hours, mins);
}
diff --git a/src/timer.h b/src/timer.h
index 24bbf9d..965ef84 100644
--- a/src/timer.h
+++ b/src/timer.h
@@ -1,6 +1,6 @@
#ifndef IPTRAF_NG_TIMER_H
#define IPTRAF_NG_TIMER_H
-void printelapsedtime(time_t start, time_t now, int y, int x, WINDOW * win);
+void printelapsedtime(time_t elapsed, int x, WINDOW *win);
#endif /* IPTRAF_NG_TIMER_H */
--
1.9.1