Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/detstats.c | 25 ++++++++++++-------------
src/hostmon.c | 29 +++++++++++++----------------
src/ifstats.c | 20 +++++++++-----------
src/itrafmon.c | 7 +++----
src/serv.c | 37 +++++++++++++++++--------------------
5 files changed, 54 insertions(+), 64 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c
index e61ab3b..5dddc47 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -52,7 +52,7 @@ static void rotate_dstat_log(int s __unused)
signal(SIGUSR1, rotate_dstat_log);
}
-static void writedstatlog(char *ifname, int unit,
+static void writedstatlog(char *ifname,
unsigned long peakactivity, unsigned long peakpps,
unsigned long peakactivity_in, unsigned long peakpps_in,
unsigned long peakactivity_out, unsigned long peakpps_out,
@@ -139,22 +139,22 @@ static void writedstatlog(char *ifname, int unit,
fprintf(fd, "\nAverage rates:\n");
- rate_print(ts->total.proto_total.pc_bytes / nsecs, unit, bps_string,
sizeof(bps_string));
+ rate_print(ts->total.proto_total.pc_bytes / nsecs, options.actmode, bps_string,
sizeof(bps_string));
rate_print_pps(ts->total.proto_total.pc_packets / nsecs, pps_string,
sizeof(pps_string));
fprintf(fd, " Total:\t%s, %s\n", bps_string, pps_string);
- rate_print(ts->total.proto_in.pc_bytes / nsecs, unit, bps_string,
sizeof(bps_string));
+ rate_print(ts->total.proto_in.pc_bytes / nsecs, options.actmode, bps_string,
sizeof(bps_string));
rate_print_pps(ts->total.proto_in.pc_packets / nsecs, pps_string,
sizeof(pps_string));
fprintf(fd, " Incoming:\t%s, %s\n", bps_string, pps_string);
- rate_print(ts->total.proto_out.pc_bytes / nsecs, unit, bps_string,
sizeof(bps_string));
+ rate_print(ts->total.proto_out.pc_bytes / nsecs, options.actmode, bps_string,
sizeof(bps_string));
rate_print_pps(ts->total.proto_out.pc_packets / nsecs, pps_string,
sizeof(pps_string));
fprintf(fd, " Outgoing:\t%s, %s\n", bps_string, pps_string);
- rate_print(peakactivity, unit, bps_string, sizeof(bps_string));
+ rate_print(peakactivity, options.actmode, bps_string, sizeof(bps_string));
rate_print_pps(peakpps, pps_string, sizeof(pps_string));
fprintf(fd, "\nPeak total activity: %s, %s\n", bps_string, pps_string);
- rate_print(peakactivity_in, unit, bps_string, sizeof(bps_string));
+ rate_print(peakactivity_in, options.actmode, bps_string, sizeof(bps_string));
rate_print_pps(peakpps_in, pps_string, sizeof(pps_string));
fprintf(fd, "Peak incoming rate: %s, %s\n", bps_string, pps_string);
- rate_print(peakactivity_out, unit, bps_string, sizeof(bps_string));
+ rate_print(peakactivity_out, options.actmode, bps_string, sizeof(bps_string));
rate_print_pps(peakpps_out, pps_string, sizeof(pps_string));
fprintf(fd, "Peak outgoing rate: %s, %s\n\n", bps_string, pps_string);
}
@@ -412,7 +412,6 @@ void detstats(char *iface, time_t facilitytime, struct filterstate
*ofilter)
char buf[64];
unsigned long activity, activity_in, activity_out;
unsigned long pps, pps_in, pps_out;
- int units = options.actmode;
unsigned long msecs;
wattrset(statwin, BOXATTR);
@@ -439,15 +438,15 @@ void detstats(char *iface, time_t facilitytime, struct filterstate
*ofilter)
start_tv = tv;
wattrset(statwin, HIGHATTR);
- rate_print(activity, units, buf, sizeof(buf));
+ rate_print(activity, options.actmode, buf, sizeof(buf));
mvwprintw(statwin, 14, 19, "%s", buf);
rate_print_pps(pps, buf, sizeof(buf));
mvwprintw(statwin, 15, 19, "%s", buf);
- rate_print(activity_in, units, buf, sizeof(buf));
+ rate_print(activity_in, options.actmode, buf, sizeof(buf));
mvwprintw(statwin, 17, 19, "%s", buf);
rate_print_pps(pps_in, buf, sizeof(buf));
mvwprintw(statwin, 18, 19, "%s", buf);
- rate_print(activity_out, units, buf, sizeof(buf));
+ rate_print(activity_out, options.actmode, buf, sizeof(buf));
mvwprintw(statwin, 20, 19, "%s", buf);
rate_print_pps(pps_out, buf, sizeof(buf));
mvwprintw(statwin, 21, 19, "%s", buf);
@@ -473,7 +472,7 @@ void detstats(char *iface, time_t facilitytime, struct filterstate
*ofilter)
if (logging) {
check_rotate_flag(&logfile);
if ((now - startlog) >= options.logspan) {
- writedstatlog(iface, options.actmode,
+ writedstatlog(iface,
peakactivity, peakpps,
peakactivity_in, peakpps_in,
peakactivity_out, peakpps_out,
@@ -611,7 +610,7 @@ err:
if (logging) {
signal(SIGUSR1, SIG_DFL);
- writedstatlog(iface, options.actmode,
+ writedstatlog(iface,
peakactivity, peakpps, peakactivity_in,
peakpps_in, peakactivity_out, peakpps_out,
&ifcounts, time(NULL) - statbegin,
diff --git a/src/hostmon.c b/src/hostmon.c
index 0753526..bbf993b 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -91,8 +91,7 @@ static void rotate_lanlog(int s __unused)
signal(SIGUSR1, rotate_lanlog);
}
-static void writeethlog(struct ethtabent *list, int unit, unsigned long nsecs,
- FILE * fd)
+static void writeethlog(struct ethtabent *list, unsigned long nsecs, FILE *fd)
{
char atime[TIME_TARGET_MAX];
struct ethtabent *ptmp = list;
@@ -128,18 +127,18 @@ static void writeethlog(struct ethtabent *list, int unit, unsigned
long nsecs,
fprintf(fd, "\tAverage rates: ");
char buf_in[32];
char buf_out[32];
- rate_print(ptmp->un.figs.inbcount / nsecs, unit,
+ rate_print(ptmp->un.figs.inbcount / nsecs, options.actmode,
buf_in, sizeof(buf_in));
- rate_print(ptmp->un.figs.outbcount / nsecs, unit,
+ rate_print(ptmp->un.figs.outbcount / nsecs, options.actmode,
buf_out, sizeof(buf_out));
fprintf(fd, "%s incoming, %s outgoing\n",
buf_in, buf_out);
if (nsecs > 5) {
rate_print(rate_get_average(&ptmp->un.figs.inrate),
- unit, buf_in, sizeof(buf_in));
+ options.actmode, buf_in, sizeof(buf_in));
rate_print(rate_get_average(&ptmp->un.figs.outrate),
- unit, buf_out, sizeof(buf_out));
+ options.actmode, buf_out, sizeof(buf_out));
fprintf(fd,
"\tLast 5-second rates: %s incoming, %s outgoing\n",
buf_in, buf_out);
@@ -153,12 +152,11 @@ static void writeethlog(struct ethtabent *list, int unit, unsigned
long nsecs,
fflush(fd);
}
-static void initethtab(struct ethtab *table, int unit)
+static void initethtab(struct ethtab *table)
{
table->head = table->tail = NULL;
table->firstvisible = table->lastvisible = NULL;
table->count = table->entcount = 0;
- table->units = unit;
table->borderwin = newwin(LINES - 2, COLS, 1, 0);
table->borderpanel = new_panel(table->borderwin);
@@ -189,7 +187,7 @@ static void initethtab(struct ethtab *table, int unit)
wmove(table->borderwin, LINES - 3, 40);
wprintw(table->borderwin, " InRate and OutRate are in %s ",
- dispmode(unit));
+ dispmode(options.actmode));
wattrset(table->tabwin, STDATTR);
tx_colorwin(table->tabwin);
@@ -419,12 +417,12 @@ static void printrates(struct ethtab *table, unsigned int
target_row,
char buf[32];
rate_print_no_units(rate_get_average(&ptmp->un.figs.inrate),
- table->units, buf, sizeof(buf));
+ options.actmode, buf, sizeof(buf));
wmove(table->tabwin, target_row, 32 * COLS / 80);
wprintw(table->tabwin, "%s", buf);
rate_print_no_units(rate_get_average(&ptmp->un.figs.outrate),
- table->units, buf, sizeof(buf));
+ options.actmode, buf, sizeof(buf));
wmove(table->tabwin, target_row, 69 * COLS / 80);
wprintw(table->tabwin, "%s", buf);
}
@@ -815,7 +813,7 @@ void hostmon(time_t facilitytime, char *ifptr, struct filterstate
*ofilter)
hostmonhelp();
- initethtab(&table, options.actmode);
+ initethtab(&table);
/* Ethernet description list */
struct eth_desc *elist = load_eth_desc(ARPHRD_ETHER);
@@ -881,8 +879,8 @@ void hostmon(time_t facilitytime, char *ifptr, struct filterstate
*ofilter)
if (logging) {
check_rotate_flag(&logfile);
if ((now - startlog) >= options.logspan) {
- writeethlog(table.head, options.actmode,
- now - statbegin, logfile);
+ writeethlog(table.head, now - statbegin,
+ logfile);
startlog = now;
}
}
@@ -1052,8 +1050,7 @@ err:
if (logging) {
signal(SIGUSR1, SIG_DFL);
- writeethlog(table.head, options.actmode,
- time(NULL) - statbegin, logfile);
+ writeethlog(table.head, time(NULL) - statbegin, logfile);
writelog(logging, logfile,
"******** LAN traffic monitor stopped ********");
fclose(logfile);
diff --git a/src/ifstats.c b/src/ifstats.c
index 45f620a..8632877 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -75,8 +75,7 @@ static void rotate_gstat_log(int s __unused)
signal(SIGUSR1, rotate_gstat_log);
}
-static void writegstatlog(struct iftab *table, int unit, unsigned long nsecs,
- FILE *fd)
+static void writegstatlog(struct iftab *table, unsigned long nsecs, FILE *fd)
{
struct iflist *ptmp = table->head;
char atime[TIME_TARGET_MAX];
@@ -95,11 +94,11 @@ static void writegstatlog(struct iftab *table, int unit, unsigned long
nsecs,
if (nsecs > 5) {
char buf[64];
- rate_print(ptmp->br / nsecs, unit, buf, sizeof(buf));
+ rate_print(ptmp->br / nsecs, options.actmode, buf, sizeof(buf));
fprintf(fd, ", average activity %s", buf);
- rate_print(ptmp->peakrate, unit, buf, sizeof(buf));
+ rate_print(ptmp->peakrate, options.actmode, buf, sizeof(buf));
fprintf(fd, ", peak activity %s", buf);
- rate_print(rate_get_average(&ptmp->rate), unit, buf, sizeof(buf));
+ rate_print(rate_get_average(&ptmp->rate), options.actmode, buf, sizeof(buf));
fprintf(fd, ", last 5-second average activity %s", buf);
}
fprintf(fd, "\n");
@@ -256,7 +255,7 @@ static void no_ifaces_error(void)
write_error("No active interfaces. Check their status or the /proc
filesystem");
}
-static void updaterates(struct iftab *table, int unit, unsigned long msecs,
+static void updaterates(struct iftab *table, unsigned long msecs,
unsigned int idx)
{
struct iflist *ptmp = table->firstvisible;
@@ -267,7 +266,7 @@ static void updaterates(struct iftab *table, int unit, unsigned long
msecs,
do {
rate_add_rate(&ptmp->rate, ptmp->spanbr, msecs);
rate = rate_get_average(&ptmp->rate);
- rate_print(rate, unit, buf, sizeof(buf));
+ rate_print(rate, options.actmode, buf, sizeof(buf));
wmove(table->statwin, ptmp->index - idx, 63 * COLS / 80);
wprintw(table->statwin, "%s", buf);
@@ -532,7 +531,7 @@ void ifstats(struct filterstate *ofilter, time_t facilitytime)
unsigned long msecs;
msecs = timeval_diff_msec(&tv, &start_tv);
- updaterates(&table, options.actmode, msecs, idx);
+ updaterates(&table, msecs, idx);
printelapsedtime(statbegin, now, LINES - 3, 1,
table.borderwin);
starttime = now;
@@ -541,7 +540,7 @@ void ifstats(struct filterstate *ofilter, time_t facilitytime)
if (logging) {
check_rotate_flag(&logfile);
if ((now - startlog) >= options.logspan) {
- writegstatlog(&table, options.actmode,
+ writegstatlog(&table,
time(NULL) - statbegin,
logfile);
startlog = now;
@@ -654,8 +653,7 @@ err:
if (logging) {
signal(SIGUSR1, SIG_DFL);
- writegstatlog(&table, options.actmode,
- time(NULL) - statbegin, logfile);
+ writegstatlog(&table, time(NULL) - statbegin, logfile);
writelog(logging, logfile,
"******** General interface statistics stopped ********");
fclose(logfile);
diff --git a/src/itrafmon.c b/src/itrafmon.c
index adedeca..8188f3e 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -530,14 +530,14 @@ static void update_flowrate(struct tcptable *table, unsigned long
msecs)
}
}
-static void print_flowrate(struct tcptableent *entry, WINDOW *win, int mode)
+static void print_flowrate(struct tcptableent *entry, WINDOW *win)
{
wattrset(win, IPSTATLABELATTR);
mvwprintw(win, 0, COLS * 47 / 80, "TCP flow rate: ");
wattrset(win, IPSTATATTR);
char buf[32];
- rate_print(rate_get_average(&entry->rate), mode, buf, sizeof(buf));
+ rate_print(rate_get_average(&entry->rate), options.actmode, buf, sizeof(buf));
mvwprintw(win, 0, COLS * 52 / 80 + 13, "%s", buf);
}
@@ -778,8 +778,7 @@ void ipmon(struct filterstate *ofilter, time_t facilitytime, char
*ifptr)
if (rate_msecs > 1000) {
update_flowrate(&table, rate_msecs);
if (table.barptr != NULL) {
- print_flowrate(table.barptr, statwin,
- options.actmode);
+ print_flowrate(table.barptr, statwin);
} else {
wattrset(statwin, IPSTATATTR);
mvwprintw(statwin, 0, statx,
diff --git a/src/serv.c b/src/serv.c
index 94e9775..66c22d3 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -93,8 +93,7 @@ static void rotate_serv_log(int s __unused)
signal(SIGUSR1, rotate_serv_log);
}
-static void writeutslog(struct portlistent *list, unsigned long nsecs,
- int units, FILE *fd)
+static void writeutslog(struct portlistent *list, unsigned long nsecs, FILE *fd)
{
char atime[TIME_TARGET_MAX];
struct portlistent *ptmp = list;
@@ -119,7 +118,7 @@ static void writeutslog(struct portlistent *list, unsigned long
nsecs,
ptmp->serv_count.proto_total.pc_packets,
ptmp->serv_count.proto_total.pc_bytes);
- rate_print(ptmp->serv_count.proto_total.pc_bytes / secs, units,
+ rate_print(ptmp->serv_count.proto_total.pc_bytes / secs, options.actmode,
bps_string, sizeof(bps_string));
fprintf(fd, ", %s", bps_string);
@@ -127,7 +126,7 @@ static void writeutslog(struct portlistent *list, unsigned long
nsecs,
ptmp->serv_count.proto_in.pc_packets,
ptmp->serv_count.proto_in.pc_bytes);
- rate_print(ptmp->serv_count.proto_in.pc_bytes / secs, units,
+ rate_print(ptmp->serv_count.proto_in.pc_bytes / secs, options.actmode,
bps_string, sizeof(bps_string));
fprintf(fd, ", %s", bps_string);
@@ -135,7 +134,7 @@ static void writeutslog(struct portlistent *list, unsigned long
nsecs,
ptmp->serv_count.proto_out.pc_packets,
ptmp->serv_count.proto_out.pc_bytes);
- rate_print(ptmp->serv_count.proto_out.pc_bytes / secs, units,
+ rate_print(ptmp->serv_count.proto_out.pc_bytes / secs, options.actmode,
bps_string, sizeof(bps_string));
fprintf(fd, ", %s", bps_string);
@@ -720,7 +719,7 @@ static void show_portsort_keywin(WINDOW ** win, PANEL ** panel)
doupdate();
}
-static void print_serv_rates(struct portlistent *ple, WINDOW *win, int actmode)
+static void print_serv_rates(struct portlistent *ple, WINDOW *win)
{
char buf[64];
@@ -731,11 +730,11 @@ static void print_serv_rates(struct portlistent *ple, WINDOW *win,
int actmode)
mvwprintw(win, 0, 76, "out");
wattrset(win, IPSTATATTR);
- rate_print(rate_get_average(&ple->rate), actmode, buf, sizeof(buf));
+ rate_print(rate_get_average(&ple->rate), options.actmode, buf, sizeof(buf));
mvwprintw(win, 0, 21, "%s", buf);
- rate_print(rate_get_average(&ple->rate_in), actmode, buf, sizeof(buf));
+ rate_print(rate_get_average(&ple->rate_in), options.actmode, buf, sizeof(buf));
mvwprintw(win, 0, 42, "%s", buf);
- rate_print(rate_get_average(&ple->rate_out), actmode, buf, sizeof(buf));
+ rate_print(rate_get_average(&ple->rate_out), options.actmode, buf, sizeof(buf));
mvwprintw(win, 0, 61, "%s", buf);
}
@@ -902,7 +901,7 @@ void servmon(char *ifname, time_t facilitytime, struct filterstate
*ofilter)
check_rotate_flag(&logfile);
if ((now - startlog) >= options.logspan) {
writeutslog(list.head, now - starttime,
- options.actmode, logfile);
+ logfile);
startlog = now;
}
}
@@ -914,8 +913,7 @@ void servmon(char *ifname, time_t facilitytime, struct filterstate
*ofilter)
/* ... and print the current one */
if (list.barptr != NULL)
- print_serv_rates(list.barptr, statwin,
- options.actmode);
+ print_serv_rates(list.barptr, statwin);
tv_rate = tv;
}
@@ -961,7 +959,7 @@ void servmon(char *ifname, time_t facilitytime, struct filterstate
*ofilter)
printportent(&list, list.barptr, idx);
- print_serv_rates(list.barptr, statwin, options.actmode);
+ print_serv_rates(list.barptr, statwin);
break;
case KEY_DOWN:
if (!list.barptr
@@ -979,7 +977,7 @@ void servmon(char *ifname, time_t facilitytime, struct filterstate
*ofilter)
printportent(&list, list.barptr, idx);
- print_serv_rates(list.barptr, statwin, options.actmode);
+ print_serv_rates(list.barptr, statwin);
break;
case KEY_PPAGE:
case '-':
@@ -993,7 +991,7 @@ void servmon(char *ifname, time_t facilitytime, struct filterstate
*ofilter)
refresh_serv_screen(&list, idx);
- print_serv_rates(list.barptr, statwin, options.actmode);
+ print_serv_rates(list.barptr, statwin);
break;
case KEY_NPAGE:
case ' ':
@@ -1007,7 +1005,7 @@ void servmon(char *ifname, time_t facilitytime, struct filterstate
*ofilter)
refresh_serv_screen(&list, idx);
- print_serv_rates(list.barptr, statwin, options.actmode);
+ print_serv_rates(list.barptr, statwin);
break;
case 12:
case 'l':
@@ -1036,7 +1034,7 @@ void servmon(char *ifname, time_t facilitytime, struct filterstate
*ofilter)
if (list.barptr != NULL) {
list.barptr = list.firstvisible;
list.baridx = 1;
- print_serv_rates(list.barptr, statwin, options.actmode);
+ print_serv_rates(list.barptr, statwin);
}
refresh_serv_screen(&list, idx);
update_panels();
@@ -1084,7 +1082,7 @@ void servmon(char *ifname, time_t facilitytime, struct filterstate
*ofilter)
if ((list.barptr == NULL) && (list.head != NULL)) {
list.barptr = list.head;
list.baridx = 1;
- print_serv_rates(list.barptr, statwin, options.actmode);
+ print_serv_rates(list.barptr, statwin);
}
}
@@ -1093,8 +1091,7 @@ err_close:
err:
if (logging) {
signal(SIGUSR1, SIG_DFL);
- writeutslog(list.head, time(NULL) - starttime,
- options.actmode, logfile);
+ writeutslog(list.head, time(NULL) - starttime, logfile);
writelog(logging, logfile,
"******** TCP/UDP service monitor stopped ********");
fclose(logfile);
--
1.7.8.4