There's no point in passing the struct OPTIONS pointer to every other function; this patch make the "struct OPTIONS options" variable global and fixes every reference to it. Entire patch series also makes iptraf-ng code size by 1,5 kB smaller.
Vitezslav Samel (5): make struct OPTIONS options global move options.actmode variable passing one layer down push options.actmode variable passing one more layer down push options.servnames variable down ... push options.mac variable down ...
src/detstats.c | 44 ++++++++++----------- src/detstats.h | 4 +- src/hostmon.c | 48 ++++++++++------------- src/hostmon.h | 4 +- src/ifstats.c | 39 +++++++++---------- src/ifstats.h | 4 +- src/iptraf.c | 39 +++++++++---------- src/itrafmon.c | 98 +++++++++++++++++++++-------------------------- src/itrafmon.h | 4 +- src/options.c | 114 ++++++++++++++++++++++++++++--------------------------- src/options.h | 8 ++- src/othptab.c | 29 +++++--------- src/othptab.h | 6 +-- src/pktsize.c | 18 ++++---- src/pktsize.h | 5 +- src/rate.c | 9 ++-- src/rate.h | 4 +- src/serv.c | 74 +++++++++++++++++------------------- src/serv.h | 4 +- src/servname.c | 6 +- src/servname.h | 3 +- src/tcptable.c | 57 ++++++++++++---------------- src/tcptable.h | 13 +++--- 23 files changed, 290 insertions(+), 344 deletions(-)
There's no point in passing the struct OPTIONS pointer to every other function; this patch make the "struct OPTIONS options" variable global and fixes every reference to it. It also makes iptraf-ng code size by 0,5 kB smaller.
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/detstats.c | 25 ++++++------ src/detstats.h | 4 +- src/hostmon.c | 23 +++++------ src/hostmon.h | 4 +- src/ifstats.c | 25 ++++++------ src/ifstats.h | 4 +- src/iptraf.c | 39 +++++++++---------- src/itrafmon.c | 84 +++++++++++++++++++--------------------- src/itrafmon.h | 4 +- src/options.c | 114 ++++++++++++++++++++++++++++--------------------------- src/options.h | 8 ++- src/othptab.c | 10 ++--- src/pktsize.c | 18 ++++---- src/pktsize.h | 5 +- src/serv.c | 43 ++++++++++----------- src/serv.h | 4 +- src/tcptable.c | 47 +++++++++-------------- src/tcptable.h | 9 ++-- 18 files changed, 221 insertions(+), 249 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c index 44cf812..e61ab3b 100644 --- a/src/detstats.c +++ b/src/detstats.c @@ -251,10 +251,9 @@ static void printdetails(struct ifcounts *ifcounts, WINDOW * win) /* * The detailed interface statistics function */ -void detstats(char *iface, const struct OPTIONS *options, time_t facilitytime, - struct filterstate *ofilter) +void detstats(char *iface, time_t facilitytime, struct filterstate *ofilter) { - int logging = options->logging; + int logging = options.logging;
WINDOW *statwin; PANEL *statpanel; @@ -316,7 +315,7 @@ void detstats(char *iface, const struct OPTIONS *options, time_t facilitytime, return; }
- if ((first_active_facility()) && (options->promisc)) { + if (first_active_facility() && options.promisc) { init_promisc_list(&promisc_list); save_promisc_list(promisc_list); srpromisc(1, promisc_list); @@ -413,7 +412,7 @@ void detstats(char *iface, const struct OPTIONS *options, time_t facilitytime, char buf[64]; unsigned long activity, activity_in, activity_out; unsigned long pps, pps_in, pps_out; - int units = options->actmode; + int units = options.actmode; unsigned long msecs;
wattrset(statwin, BOXATTR); @@ -473,8 +472,8 @@ void detstats(char *iface, const struct OPTIONS *options, time_t facilitytime, } if (logging) { check_rotate_flag(&logfile); - if ((now - startlog) >= options->logspan) { - writedstatlog(iface, options->actmode, + if ((now - startlog) >= options.logspan) { + writedstatlog(iface, options.actmode, peakactivity, peakpps, peakactivity_in, peakpps_in, peakactivity_out, peakpps_out, @@ -485,10 +484,10 @@ void detstats(char *iface, const struct OPTIONS *options, time_t facilitytime, } }
- if (((options->updrate == 0) + if (((options.updrate == 0) && (unow - updtime_usec >= DEFAULT_UPDATE_DELAY)) - || ((options->updrate != 0) - && (now - updtime >= options->updrate))) { + || ((options.updrate != 0) + && (now - updtime >= options.updrate))) { printdetails(&ifcounts, statwin); update_panels(); doupdate(); @@ -534,7 +533,7 @@ void detstats(char *iface, const struct OPTIONS *options, time_t facilitytime, packet_process(&pkt, NULL, NULL, NULL, ofilter, MATCH_OPPOSITE_USECONFIG, - options->v6inv4asv6); + options.v6inv4asv6);
if (pkt_result != PACKET_OK && pkt_result != MORE_FRAGMENTS) @@ -602,7 +601,7 @@ err: rate_destroy(&rate_in); rate_destroy(&rate);
- if ((options->promisc) && (is_last_instance())) { + if (options.promisc && is_last_instance()) { load_promisc_list(&promisc_list); srpromisc(0, promisc_list); destroy_promisc_list(&promisc_list); @@ -612,7 +611,7 @@ err:
if (logging) { signal(SIGUSR1, SIG_DFL); - writedstatlog(iface, options->actmode, + writedstatlog(iface, options.actmode, peakactivity, peakpps, peakactivity_in, peakpps_in, peakactivity_out, peakpps_out, &ifcounts, time(NULL) - statbegin, diff --git a/src/detstats.h b/src/detstats.h index c3dd9c3..c237a4c 100644 --- a/src/detstats.h +++ b/src/detstats.h @@ -1,10 +1,8 @@ #ifndef IPTRAF_NG_DETSTATS_H #define IPTRAF_NG_DETSTATS_H
-#include "options.h" #include "fltselect.h"
-void detstats(char *iface, const struct OPTIONS *options, time_t facilitytime, - struct filterstate *ofilter); +void detstats(char *iface, time_t facilitytime, struct filterstate *ofilter);
#endif /* IPTRAF_NG_DETSTATS_H */ diff --git a/src/hostmon.c b/src/hostmon.c index 092293c..0753526 100644 --- a/src/hostmon.c +++ b/src/hostmon.c @@ -748,10 +748,9 @@ static void sort_hosttab(struct ethtab *list, unsigned int *idx, int command) * The LAN station monitor */
-void hostmon(const struct OPTIONS *options, time_t facilitytime, char *ifptr, - struct filterstate *ofilter) +void hostmon(time_t facilitytime, char *ifptr, struct filterstate *ofilter) { - int logging = options->logging; + int logging = options.logging; struct ethtab table; struct ethtabent *entry;
@@ -804,7 +803,7 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char *ifptr, } }
- if ((first_active_facility()) && (options->promisc)) { + if (first_active_facility() && options.promisc) { init_promisc_list(&promisc_list); save_promisc_list(promisc_list); srpromisc(1, promisc_list); @@ -816,7 +815,7 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char *ifptr,
hostmonhelp();
- initethtab(&table, options->actmode); + initethtab(&table, options.actmode);
/* Ethernet description list */ struct eth_desc *elist = load_eth_desc(ARPHRD_ETHER); @@ -881,15 +880,15 @@ void hostmon(const struct OPTIONS *options, time_t facilitytime, char *ifptr, } if (logging) { check_rotate_flag(&logfile); - if ((now - startlog) >= options->logspan) { - writeethlog(table.head, options->actmode, + if ((now - startlog) >= options.logspan) { + writeethlog(table.head, options.actmode, now - statbegin, logfile); startlog = now; } } - if (((options->updrate != 0) - && (now - updtime >= options->updrate)) - || ((options->updrate == 0) + if (((options.updrate != 0) + && (now - updtime >= options.updrate)) + || ((options.updrate == 0) && (unow - updtime_usec >= DEFAULT_UPDATE_DELAY))) { update_panels(); doupdate(); @@ -1042,7 +1041,7 @@ err_close: close(fd);
err: - if ((options->promisc) && (is_last_instance())) { + if (options.promisc && is_last_instance()) { load_promisc_list(&promisc_list); srpromisc(0, promisc_list); destroy_promisc_list(&promisc_list); @@ -1053,7 +1052,7 @@ err:
if (logging) { signal(SIGUSR1, SIG_DFL); - writeethlog(table.head, options->actmode, + writeethlog(table.head, options.actmode, time(NULL) - statbegin, logfile); writelog(logging, logfile, "******** LAN traffic monitor stopped ********"); diff --git a/src/hostmon.h b/src/hostmon.h index a943b21..ab56101 100644 --- a/src/hostmon.h +++ b/src/hostmon.h @@ -1,11 +1,9 @@ #ifndef IPTRAF_NG_HOSTMON_H #define IPTRAF_NG_HOSTMON_H
-#include "options.h" #include "fltselect.h"
void convmacaddr(char *addr, char *result); -void hostmon(const struct OPTIONS *options, time_t facilitytime, char *ifptr, - struct filterstate *ofilter); +void hostmon(time_t facilitytime, char *ifptr, struct filterstate *ofilter);
#endif /* IPTRAF_NG_HOSTMON_H */ diff --git a/src/ifstats.c b/src/ifstats.c index fbe7dc4..45f620a 100644 --- a/src/ifstats.c +++ b/src/ifstats.c @@ -428,10 +428,9 @@ static void pagegstatwin(struct iftab *table, int direction, unsigned int *idx) * The general interface statistics function */
-void ifstats(const struct OPTIONS *options, struct filterstate *ofilter, - time_t facilitytime) +void ifstats(struct filterstate *ofilter, time_t facilitytime) { - int logging = options->logging; + int logging = options.logging; struct iftab table;
int pkt_result = 0; @@ -474,7 +473,7 @@ void ifstats(const struct OPTIONS *options, struct filterstate *ofilter,
initiftab(&table);
- if ((first_active_facility()) && (options->promisc)) { + if (first_active_facility() && options.promisc) { init_promisc_list(&promisc_list); save_promisc_list(promisc_list); srpromisc(1, promisc_list); @@ -533,7 +532,7 @@ void ifstats(const struct OPTIONS *options, struct filterstate *ofilter, unsigned long msecs;
msecs = timeval_diff_msec(&tv, &start_tv); - updaterates(&table, options->actmode, msecs, idx); + updaterates(&table, options.actmode, msecs, idx); printelapsedtime(statbegin, now, LINES - 3, 1, table.borderwin); starttime = now; @@ -541,16 +540,16 @@ void ifstats(const struct OPTIONS *options, struct filterstate *ofilter, } if (logging) { check_rotate_flag(&logfile); - if ((now - startlog) >= options->logspan) { - writegstatlog(&table, options->actmode, + if ((now - startlog) >= options.logspan) { + writegstatlog(&table, options.actmode, time(NULL) - statbegin, logfile); startlog = now; } } - if (((options->updrate != 0) - && (now - updtime >= options->updrate)) - || ((options->updrate == 0) + if (((options.updrate != 0) + && (now - updtime >= options.updrate)) + || ((options.updrate == 0) && (unow - updtime_usec >= DEFAULT_UPDATE_DELAY))) { update_panels(); doupdate(); @@ -606,7 +605,7 @@ void ifstats(const struct OPTIONS *options, struct filterstate *ofilter, pkt_result = packet_process(&pkt, NULL, NULL, NULL, ofilter, MATCH_OPPOSITE_USECONFIG, - options->v6inv4asv6); + options.v6inv4asv6);
if (pkt_result != PACKET_OK && pkt_result != MORE_FRAGMENTS) @@ -638,7 +637,7 @@ void ifstats(const struct OPTIONS *options, struct filterstate *ofilter, close(fd);
err: - if ((options->promisc) && (is_last_instance())) { + if (options.promisc && is_last_instance()) { load_promisc_list(&promisc_list); srpromisc(0, promisc_list); destroy_promisc_list(&promisc_list); @@ -655,7 +654,7 @@ err:
if (logging) { signal(SIGUSR1, SIG_DFL); - writegstatlog(&table, options->actmode, + writegstatlog(&table, options.actmode, time(NULL) - statbegin, logfile); writelog(logging, logfile, "******** General interface statistics stopped ********"); diff --git a/src/ifstats.h b/src/ifstats.h index 5d4f346..8797fe1 100644 --- a/src/ifstats.h +++ b/src/ifstats.h @@ -1,11 +1,9 @@ #ifndef IPTRAF_NG_IFSTATS_H #define IPTRAF_NG_IFSTATS_H
-#include "options.h" #include "fltselect.h"
void selectiface(char *ifname, int withall, int *aborted); -void ifstats(const struct OPTIONS *options, struct filterstate *ofilter, - time_t facilitytime); +void ifstats(struct filterstate *ofilter, time_t facilitytime);
#endif /* IPTRAF_NG_IFSTATS_H */ diff --git a/src/iptraf.c b/src/iptraf.c index f06375b..e840ba7 100644 --- a/src/iptraf.c +++ b/src/iptraf.c @@ -126,7 +126,7 @@ static void init_break_menu(struct MENU *break_menu) * Get the ball rolling: The program interface routine. */
-static void program_interface(struct OPTIONS *options) +static void program_interface(void) { struct MENU menu; struct MENU break_menu; @@ -194,16 +194,16 @@ static void program_interface(struct OPTIONS *options) else ifptr = NULL;
- ipmon(options, &ofilter, 0, ifptr); + ipmon(&ofilter, 0, ifptr); } break; case 2: - ifstats(options, &ofilter, 0); + ifstats(&ofilter, 0); break; case 3: selectiface(ifname, WITHOUTALL, &aborted); if (!aborted) - detstats(ifname, options, 0, &ofilter); + detstats(ifname, 0, &ofilter); break; case 4: break_row = 1; @@ -215,13 +215,13 @@ static void program_interface(struct OPTIONS *options) case 1: selectiface(ifname, WITHOUTALL, &aborted); if (!aborted) - packet_size_breakdown(options, ifname, + packet_size_breakdown(ifname, 0, &ofilter); break; case 2: selectiface(ifname, WITHOUTALL, &aborted); if (!aborted) - servmon(ifname, options, 0, + servmon(ifname, 0, &ofilter); break; case 4: @@ -236,7 +236,7 @@ static void program_interface(struct OPTIONS *options) ifptr = ifname; else ifptr = NULL; - hostmon(options, 0, ifptr, &ofilter); + hostmon(0, ifptr, &ofilter); } break; case 7: @@ -244,8 +244,8 @@ static void program_interface(struct OPTIONS *options) savefilters(&ofilter); break; case 9: - setoptions(options); - saveoptions(options); + setoptions(); + saveoptions(); break; case 11: about(); @@ -355,7 +355,6 @@ static void handle_internal_command(int argc, char **argv,
int main(int argc, char **argv) { - struct OPTIONS options; int current_log_interval = 0;
if (geteuid() != 0) @@ -451,7 +450,7 @@ int main(int argc, char **argv) exit(1); } #endif - loadoptions(&options); + loadoptions();
/* * If a facility is directly invoked from the command line, check for @@ -547,25 +546,25 @@ int main(int argc, char **argv)
/* simplify */ if (g_opt) - ifstats(&options, &ofilter, facilitytime); + ifstats(&ofilter, facilitytime); else if (i_opt) if (strcmp(i_opt, "all") == 0) - ipmon(&options, &ofilter, facilitytime, NULL); + ipmon(&ofilter, facilitytime, NULL); else - ipmon(&options, &ofilter, facilitytime, i_opt); + ipmon(&ofilter, facilitytime, i_opt); else if (l_opt) if (strcmp(l_opt, "all") == 0) - hostmon(&options, facilitytime, NULL, &ofilter); + hostmon(facilitytime, NULL, &ofilter); else - hostmon(&options, facilitytime, l_opt, &ofilter); + hostmon(facilitytime, l_opt, &ofilter); else if (d_opt) - detstats(d_opt, &options, facilitytime, &ofilter); + detstats(d_opt, facilitytime, &ofilter); else if (s_opt) - servmon(s_opt, &options, facilitytime, &ofilter); + servmon(s_opt, facilitytime, &ofilter); else if (z_opt) - packet_size_breakdown(&options, z_opt, facilitytime, &ofilter); + packet_size_breakdown(z_opt, facilitytime, &ofilter);
- program_interface(&options); + program_interface();
endwin();
diff --git a/src/itrafmon.c b/src/itrafmon.c index 3fe2a51..adedeca 100644 --- a/src/itrafmon.c +++ b/src/itrafmon.c @@ -328,8 +328,7 @@ static unsigned long long qt_getkey(struct tcptableent *entry, int ch) static struct tcptableent *qt_partition(struct tcptable *table, struct tcptableent **low, struct tcptableent **high, int ch, - struct OPTIONS *opts, int logging, - FILE * logfile) + int logging, FILE *logfile) { struct tcptableent *pivot = *low;
@@ -352,8 +351,8 @@ static struct tcptableent *qt_partition(struct tcptable *table, /* * Might as well check out timed out entries here too. */ - if ((opts->timeout > 0) - && ((now - left->lastupdate) / 60 > opts->timeout) + if ((options.timeout > 0) + && ((now - left->lastupdate) / 60 > options.timeout) && (!(left->inclosed))) { left->timedout = left->oth_connection->timedout = 1; @@ -361,7 +360,7 @@ static struct tcptableent *qt_partition(struct tcptable *table,
if (logging) write_timeout_log(logging, logfile, - left, opts); + left); }
left = left->next_entry->next_entry; @@ -371,8 +370,8 @@ static struct tcptableent *qt_partition(struct tcptable *table, /* * Might as well check out timed out entries here too. */ - if ((opts->timeout > 0) - && ((now - right->lastupdate) / 60 > opts->timeout) + if ((options.timeout > 0) + && ((now - right->lastupdate) / 60 > options.timeout) && (!(right->inclosed))) { right->timedout = right->oth_connection->timedout = 1; @@ -380,7 +379,7 @@ static struct tcptableent *qt_partition(struct tcptable *table,
if (logging) write_timeout_log(logging, logfile, - right, opts); + right); } right = right->prev_entry->prev_entry; } @@ -416,8 +415,7 @@ static struct tcptableent *qt_partition(struct tcptable *table, static void quicksort_tcp_entries(struct tcptable *table, struct tcptableent *low, struct tcptableent *high, int ch, - struct OPTIONS *opts, int logging, - FILE *logfile) + int logging, FILE *logfile) { struct tcptableent *pivot;
@@ -426,15 +424,15 @@ static void quicksort_tcp_entries(struct tcptable *table,
if (high->index > low->index) { pivot = - qt_partition(table, &low, &high, ch, opts, logging, logfile); + qt_partition(table, &low, &high, ch, logging, logfile);
if (pivot->prev_entry != NULL) quicksort_tcp_entries(table, low, pivot->prev_entry->prev_entry, ch, - opts, logging, logfile); + logging, logfile);
quicksort_tcp_entries(table, pivot->next_entry->next_entry, - high, ch, opts, logging, logfile); + high, ch, logging, logfile); } }
@@ -444,8 +442,7 @@ static void quicksort_tcp_entries(struct tcptable *table, */
static void sortipents(struct tcptable *table, unsigned long *idx, int ch, - int logging, FILE * logfile, - struct OPTIONS *opts) + int logging, FILE *logfile) { struct tcptableent *tcptmp1; unsigned int idxtmp; @@ -460,7 +457,7 @@ static void sortipents(struct tcptable *table, unsigned long *idx, int ch, return;
quicksort_tcp_entries(table, table->head, table->tail->prev_entry, ch, - opts, logging, logfile); + logging, logfile);
update_panels(); doupdate(); @@ -548,10 +545,9 @@ static void print_flowrate(struct tcptableent *entry, WINDOW *win, int mode) * The IP Traffic Monitor */
-void ipmon(struct OPTIONS *options, struct filterstate *ofilter, - time_t facilitytime, char *ifptr) +void ipmon(struct filterstate *ofilter, time_t facilitytime, char *ifptr) { - int logging = options->logging; + int logging = options.logging;
unsigned int frag_off; struct tcphdr *transpacket; /* IP-encapsulated packet */ @@ -611,7 +607,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, int rvnfd = 0;
int instance_id; - int revlook = options->revlook; + int revlook = options.revlook; int wasempty = 1;
const int statx = COLS * 47 / 80; @@ -635,7 +631,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, } }
- if (options->promisc) { + if (options.promisc) { if (first_active_facility()) { init_promisc_list(&promisc_list); save_promisc_list(promisc_list); @@ -651,7 +647,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, instance_id = adjust_instance_count(ITRAFMONCOUNTFILE, 1);
init_tcp_table(&table); - init_othp_table(&othptbl, options->mac); + init_othp_table(&othptbl, options.mac);
statwin = newwin(1, COLS, LINES - 2, 0); statpanel = new_panel(statwin); @@ -677,7 +673,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, update_panels(); doupdate();
- if (options->servnames) + if (options.servnames) setservent(1);
/* @@ -752,10 +748,10 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, * Automatically clear closed/timed out entries */
- if ((options->closedint != 0) - && ((now - closedint) / 60 >= options->closedint)) { + if ((options.closedint != 0) + && ((now - closedint) / 60 >= options.closedint)) { flushclosedentries(&table, &screen_idx, logging, - logfile, options); + logfile); refreshtcpwin(&table, screen_idx, mode); closedint = now; } @@ -764,9 +760,9 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, * Update screen at configured intervals. */
- if (((options->updrate != 0) - && (now - updtime >= options->updrate)) - || ((options->updrate == 0) + if (((options.updrate != 0) + && (now - updtime >= options.updrate)) + || ((options.updrate == 0) && (unow - updtime_usec >= DEFAULT_UPDATE_DELAY))) { update_panels(); doupdate(); @@ -783,7 +779,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, update_flowrate(&table, rate_msecs); if (table.barptr != NULL) { print_flowrate(table.barptr, statwin, - options->actmode); + options.actmode); } else { wattrset(statwin, IPSTATATTR); mvwprintw(statwin, 0, statx, @@ -932,7 +928,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, if (curwin) break; mode = (mode + 1) % 3; - if ((mode == 1) && (!options->mac)) + if ((mode == 1) && !options.mac) mode = 2; refreshtcpwin(&table, screen_idx, mode); break; @@ -947,7 +943,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, case 'c': case 'C': flushclosedentries(&table, &screen_idx, logging, - logfile, options); + logfile); refreshtcpwin(&table, screen_idx, mode); break; case 's': @@ -972,7 +968,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, update_panels(); doupdate(); sortipents(&table, &screen_idx, ch, logging, - logfile, options); + logfile);
if (table.barptr != NULL) { table.barptr = table.firstvisible; @@ -995,7 +991,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, pkt_result = packet_process(&pkt, &br, &sport, &dport, ofilter, MATCH_OPPOSITE_ALWAYS, - options->v6inv4asv6); + options.v6inv4asv6);
if (pkt_result != PACKET_OK) continue; @@ -1030,7 +1026,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, pkt.pkt_protocol, pkt.pkt_payload, ifname, 0, 0, logging, logfile, - options->servnames, 0); + options.servnames, 0); continue; }
@@ -1043,7 +1039,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, sockaddr_set_port(&saddr, ntohs(sport)); sockaddr_set_port(&daddr, ntohs(dport)); tcpentry = in_table(&table, &saddr, &daddr, ifname, - logging, logfile, options); + logging, logfile, options.timeout);
/* * Add a new entry if it doesn't exist, and, @@ -1062,7 +1058,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, tcpentry = addentry(&table, &saddr, &daddr, pkt_ip_protocol(&pkt), ifname, &revlook, rvnfd, - options->servnames); + options.servnames); if (tcpentry != NULL) { printentry(&table, tcpentry->oth_connection, screen_idx, mode); @@ -1096,13 +1092,13 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, updateentry(&table, tcpentry, transpacket, pkt.pkt_buf, pkt.pkt_hatype, pkt.pkt_len, br, pkt.iphdr->frag_off, - logging, &revlook, rvnfd, options, + logging, &revlook, rvnfd, logfile); else updateentry(&table, tcpentry, transpacket, pkt.pkt_buf, pkt.pkt_hatype, pkt.pkt_len, pkt.pkt_len, 0, logging, - &revlook, rvnfd, options, + &revlook, rvnfd, logfile); /* * Log first packet of a TCP connection except if @@ -1118,7 +1114,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, strcat(msgstring, " (SYN)");
writetcplog(logging, logfile, tcpentry, - pkt.pkt_len, options->mac, + pkt.pkt_len, options.mac, msgstring); }
@@ -1174,7 +1170,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, (char *) transpacket, ifname, &revlook, rvnfd, logging, logfile, - options->servnames, fragment); + options.servnames, fragment);
} else { if (pkt_ip_protocol(&pkt) == IPPROTO_ICMPV6 @@ -1186,7 +1182,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter, IS_IP, pkt_ip_protocol(&pkt), (char *) transpacket, ifname, &revlook, rvnfd, - logging, logfile, options->servnames, + logging, logfile, options.servnames, fragment); } } @@ -1197,13 +1193,13 @@ err: if (get_instance_count(ITRAFMONCOUNTFILE) <= 1) killrvnamed();
- if (options->servnames) + if (options.servnames) endservent();
endprotoent(); close_rvn_socket(rvnfd);
- if ((options->promisc) && (is_last_instance())) { + if (options.promisc && is_last_instance()) { load_promisc_list(&promisc_list); srpromisc(0, promisc_list); destroy_promisc_list(&promisc_list); diff --git a/src/itrafmon.h b/src/itrafmon.h index 0a1503a..fe9bad4 100644 --- a/src/itrafmon.h +++ b/src/itrafmon.h @@ -1,10 +1,8 @@ #ifndef IPTRAF_NG_ITRAFMON_H #define IPTRAF_NG_ITRAFMON_H
-#include "options.h" #include "fltselect.h"
-void ipmon(struct OPTIONS *options, struct filterstate *ofilter, - time_t facilitytime, char *ifptr); +void ipmon(struct filterstate *ofilter, time_t facilitytime, char *ifptr);
#endif /* IPTRAF_NG_ITRAFMON_H */ diff --git a/src/options.c b/src/options.c index fdbc608..d0ead45 100644 --- a/src/options.c +++ b/src/options.c @@ -26,6 +26,8 @@ options.c - implements the configuration section of the utility #define ALLOW_ZERO 1 #define DONT_ALLOW_ZERO 0
+struct OPTIONS options; + static void makeoptionmenu(struct MENU *menu) { tx_initmenu(menu, 20, 40, (LINES - 19) / 2 - 1, (COLS - 40) / 16, @@ -88,44 +90,44 @@ static void printoptonoff(unsigned int option, WINDOW * win) wprintw(win, "Off"); }
-static void indicatesetting(int row, struct OPTIONS *options, WINDOW * win) +static void indicatesetting(int row, WINDOW *win) { wmove(win, row, 30); wattrset(win, HIGHATTR);
switch (row) { case 1: - printoptonoff(options->revlook, win); + printoptonoff(options.revlook, win); break; case 2: - printoptonoff(options->servnames, win); + printoptonoff(options.servnames, win); break; case 3: - printoptonoff(options->promisc, win); + printoptonoff(options.promisc, win); break; case 4: - printoptonoff(options->color, win); + printoptonoff(options.color, win); break; case 5: - printoptonoff(options->logging, win); + printoptonoff(options.logging, win); break; case 6: wmove(win, row, 25); - if (options->actmode == KBITS) + if (options.actmode == KBITS) wprintw(win, " kbits/s"); else wprintw(win, "kbytes/s"); break; case 7: - printoptonoff(options->mac, win); + printoptonoff(options.mac, win); break; case 8: - printoptonoff(options->v6inv4asv6, win); + printoptonoff(options.v6inv4asv6, win); }
}
-void saveoptions(struct OPTIONS *options) +void saveoptions(void) { int fd; int bw; @@ -137,7 +139,7 @@ void saveoptions(struct OPTIONS *options) CONFIGFILE, strerror(errno)); return; } - bw = write(fd, options, sizeof(struct OPTIONS)); + bw = write(fd, &options, sizeof(struct OPTIONS));
if (bw < 0) tui_error(ANYKEY_MSG, "Unable to write config file"); @@ -145,54 +147,54 @@ void saveoptions(struct OPTIONS *options) close(fd); }
-static void setdefaultopts(struct OPTIONS *options) +static void setdefaultopts(void) { - options->revlook = 0; - options->promisc = 0; - options->servnames = 0; - options->color = 1; - options->logging = 0; - options->actmode = KBITS; - options->mac = 0; - options->timeout = 15; - options->logspan = 3600; - options->updrate = 0; - options->closedint = 0; - options->v6inv4asv6 = 1; + options.revlook = 0; + options.promisc = 0; + options.servnames = 0; + options.color = 1; + options.logging = 0; + options.actmode = KBITS; + options.mac = 0; + options.timeout = 15; + options.logspan = 3600; + options.updrate = 0; + options.closedint = 0; + options.v6inv4asv6 = 1; }
-void loadoptions(struct OPTIONS *options) +void loadoptions(void) { int fd;
- setdefaultopts(options); + setdefaultopts(); fd = open(CONFIGFILE, O_RDONLY);
if (fd < 0) return;
- read(fd, options, sizeof(struct OPTIONS)); + read(fd, &options, sizeof(struct OPTIONS));
close(fd); }
-static void updatetimes(struct OPTIONS *options, WINDOW *win) +static void updatetimes(WINDOW *win) { wattrset(win, HIGHATTR); - mvwprintw(win, 10, 25, "%3u mins", options->timeout); - mvwprintw(win, 11, 25, "%3u mins", options->logspan / 60); - mvwprintw(win, 12, 25, "%3u secs", options->updrate); - mvwprintw(win, 13, 25, "%3u mins", options->closedint); + mvwprintw(win, 10, 25, "%3u mins", options.timeout); + mvwprintw(win, 11, 25, "%3u mins", options.logspan / 60); + mvwprintw(win, 12, 25, "%3u secs", options.updrate); + mvwprintw(win, 13, 25, "%3u mins", options.closedint); }
-static void showoptions(struct OPTIONS *options, WINDOW *win) +static void showoptions(WINDOW *win) { int i;
for (i = 1; i <= 8; i++) - indicatesetting(i, options, win); + indicatesetting(i, win);
- updatetimes(options, win); + updatetimes(win); }
static void settimeout(time_t *value, const char *units, int allow_zero, @@ -246,7 +248,7 @@ static void settimeout(time_t *value, const char *units, int allow_zero, doupdate(); }
-void setoptions(struct OPTIONS *options) +void setoptions(void) { int row = 1; int trow = 1; /* row for timer submenu */ @@ -293,7 +295,7 @@ void setoptions(struct OPTIONS *options) mvwprintw(statwin, 11, 2, "Log interval:"); mvwprintw(statwin, 12, 2, "Update interval:"); mvwprintw(statwin, 13, 2, "Closed/idle persist:"); - showoptions(options, statwin); + showoptions(statwin);
do { tx_showmenu(&menu); @@ -301,28 +303,28 @@ void setoptions(struct OPTIONS *options)
switch (row) { case 1: - options->revlook = ~(options->revlook); + options.revlook = ~options.revlook; break; case 2: - options->servnames = ~(options->servnames); + options.servnames = ~options.servnames; break; case 3: - options->promisc = ~(options->promisc); + options.promisc = ~options.promisc; break; case 4: - options->color = ~(options->color); + options.color = ~options.color; break; case 5: - options->logging = ~(options->logging); + options.logging = ~options.logging; break; case 6: - options->actmode = ~(options->actmode); + options.actmode = ~options.actmode; break; case 7: - options->mac = ~(options->mac); + options.mac = ~options.mac; break; case 8: - options->v6inv4asv6 = ~(options->v6inv4asv6); + options.v6inv4asv6 = ~options.v6inv4asv6; break; case 10: maketimermenu(&timermenu); @@ -333,34 +335,34 @@ void setoptions(struct OPTIONS *options)
switch (trow) { case 1: - settimeout(&(options->timeout), + settimeout(&options.timeout, "minutes", DONT_ALLOW_ZERO, &aborted); if (!aborted) - updatetimes(options, statwin); + updatetimes(statwin); break; case 2: - settimeout(&(options->logspan), + settimeout(&options.logspan, "minutes", DONT_ALLOW_ZERO, &aborted); if (!aborted) { - options->logspan = - options->logspan * 60; - updatetimes(options, statwin); + options.logspan = + options.logspan * 60; + updatetimes(statwin); } break; case 3: - settimeout(&options->updrate, "seconds", + settimeout(&options.updrate, "seconds", ALLOW_ZERO, &aborted); if (!aborted) - updatetimes(options, statwin); + updatetimes(statwin); break; case 4: - settimeout(&options->closedint, + settimeout(&options.closedint, "minutes", ALLOW_ZERO, &aborted); if (!aborted) - updatetimes(options, statwin); + updatetimes(statwin); break; } } while (trow != 6); @@ -383,7 +385,7 @@ void setoptions(struct OPTIONS *options) break; }
- indicatesetting(row, options, statwin); + indicatesetting(row, statwin); } while (row != 18);
destroyporttab(ports); diff --git a/src/options.h b/src/options.h index c997f44..b47c243 100644 --- a/src/options.h +++ b/src/options.h @@ -12,8 +12,10 @@ struct OPTIONS {
#define DEFAULT_UPDATE_DELAY 50000 /* usec screen delay if update rate 0 */
-void setoptions(struct OPTIONS *options); -void loadoptions(struct OPTIONS *options); -void saveoptions(struct OPTIONS *options); +extern struct OPTIONS options; + +void setoptions(void); +void loadoptions(void); +void saveoptions(void);
#endif /* IPTRAF_NG_OPTIONS_H */ diff --git a/src/othptab.c b/src/othptab.c index dc4d7a9..1eed363 100644 --- a/src/othptab.c +++ b/src/othptab.c @@ -131,10 +131,8 @@ void process_dest_unreach(struct tcptable *table, char *packet, char *ifname) ip = (struct iphdr *) (packet + 8);
/* - * Timeout checking - * won't be performed either, so we just pass NULL as the pointer - * to the configuration structure. in_table() will recognize this - * and set its internal timeout variable to 0. + * Timeout checking won't be performed either, so we just pass 0 + * as timeout variable. */
if (ip->version == 6) { @@ -148,7 +146,7 @@ void process_dest_unreach(struct tcptable *table, char *packet, char *ifname) sockaddr_make_ipv6(&daddr, &ip6->ip6_dst); sockaddr_set_port(&daddr, ntohs(tcp->dest)); tcpentry = - in_table(table, &saddr, &daddr, ifname, 0, NULL, NULL); + in_table(table, &saddr, &daddr, ifname, 0, NULL, 0); } else { if (ip->protocol != IPPROTO_TCP) return; @@ -159,7 +157,7 @@ void process_dest_unreach(struct tcptable *table, char *packet, char *ifname) sockaddr_make_ipv4(&daddr, ip->daddr); sockaddr_set_port(&daddr, ntohs(tcp->dest)); tcpentry = - in_table(table, &saddr, &daddr, ifname, 0, NULL, NULL); + in_table(table, &saddr, &daddr, ifname, 0, NULL, 0); }
if (tcpentry != NULL) { diff --git a/src/pktsize.c b/src/pktsize.c index b0c411f..ff5604d 100644 --- a/src/pktsize.c +++ b/src/pktsize.c @@ -138,8 +138,8 @@ static void update_size_distrib(unsigned int length, wprintw(win, "%8lu", brackets[i].count); }
-void packet_size_breakdown(struct OPTIONS *options, char *ifname, - time_t facilitytime, struct filterstate *ofilter) +void packet_size_breakdown(char *ifname, time_t facilitytime, + struct filterstate *ofilter) { WINDOW *win; PANEL *panel; @@ -162,7 +162,7 @@ void packet_size_breakdown(struct OPTIONS *options, char *ifname, time_t updtime = 0; unsigned long long updtime_usec = 0;
- int logging = options->logging; + int logging = options.logging; FILE *logfile = NULL;
struct promisc_states *promisc_list; @@ -244,7 +244,7 @@ void packet_size_breakdown(struct OPTIONS *options, char *ifname, gettimeofday(&tv, NULL); now = starttime = startlog = timeint = tv.tv_sec;
- if ((first_active_facility()) && (options->promisc)) { + if (first_active_facility() && options.promisc) { init_promisc_list(&promisc_list); save_promisc_list(promisc_list); srpromisc(1, promisc_list); @@ -270,9 +270,9 @@ void packet_size_breakdown(struct OPTIONS *options, char *ifname, now = tv.tv_sec; unow = tv.tv_sec * 1000000ULL + tv.tv_usec;
- if (((options->updrate != 0) - && (now - updtime >= options->updrate)) - || ((options->updrate == 0) + if (((options.updrate != 0) + && (now - updtime >= options.updrate)) + || ((options.updrate == 0) && (unow - updtime_usec >= DEFAULT_UPDATE_DELAY))) { update_panels(); doupdate(); @@ -286,7 +286,7 @@ void packet_size_breakdown(struct OPTIONS *options, char *ifname, } if (logging) { check_rotate_flag(&logfile); - if ((now - startlog >= options->logspan)) { + if ((now - startlog) >= options.logspan) { write_size_log(brackets, now - starttime, ifname, mtu, logfile); startlog = now; @@ -343,7 +343,7 @@ err: fclose(logfile); }
- if ((options->promisc) && (is_last_instance())) { + if (options.promisc && is_last_instance()) { load_promisc_list(&promisc_list); srpromisc(0, promisc_list); destroy_promisc_list(&promisc_list); diff --git a/src/pktsize.h b/src/pktsize.h index 3a78640..0642bd0 100644 --- a/src/pktsize.h +++ b/src/pktsize.h @@ -1,10 +1,9 @@ #ifndef IPTRAF_NG_PKTSIZE_H #define IPTRAF_NG_PKTSIZE_H
-#include "options.h" #include "fltselect.h"
-void packet_size_breakdown(struct OPTIONS *options, char *iface, - time_t facilitytime, struct filterstate *ofilter); +void packet_size_breakdown(char *iface, time_t facilitytime, + struct filterstate *ofilter);
#endif /* IPTRAF_NG_PKTSIZE_H */ diff --git a/src/serv.c b/src/serv.c index f2470b4..94e9775 100644 --- a/src/serv.c +++ b/src/serv.c @@ -755,10 +755,9 @@ static void update_serv_rates(struct portlist *list, unsigned long msecs) * The TCP/UDP service monitor */
-void servmon(char *ifname, const struct OPTIONS *options, - time_t facilitytime, struct filterstate *ofilter) +void servmon(char *ifname, time_t facilitytime, struct filterstate *ofilter) { - int logging = options->logging; + int logging = options.logging; int pkt_result;
int keymode = 0; @@ -818,7 +817,7 @@ void servmon(char *ifname, const struct OPTIONS *options,
loadaddports(&ports);
- if ((first_active_facility()) && (options->promisc)) { + if (first_active_facility() && options.promisc) { init_promisc_list(&promisc_list); save_promisc_list(promisc_list); srpromisc(1, promisc_list); @@ -840,7 +839,7 @@ void servmon(char *ifname, const struct OPTIONS *options, sortkeyhelp(); stdexitkeyhelp();
- if (options->servnames) + if (options.servnames) setservent(1);
if (logging) { @@ -901,9 +900,9 @@ void servmon(char *ifname, const struct OPTIONS *options, } if (logging) { check_rotate_flag(&logfile); - if ((now - startlog) >= options->logspan) { + if ((now - startlog) >= options.logspan) { writeutslog(list.head, now - starttime, - options->actmode, logfile); + options.actmode, logfile); startlog = now; } } @@ -916,14 +915,14 @@ void servmon(char *ifname, const struct OPTIONS *options, /* ... and print the current one */ if (list.barptr != NULL) print_serv_rates(list.barptr, statwin, - options->actmode); + options.actmode);
tv_rate = tv; }
- if (((options->updrate != 0) - && (now - updtime >= options->updrate)) - || ((options->updrate == 0) + if (((options.updrate != 0) + && (now - updtime >= options.updrate)) + || ((options.updrate == 0) && (unow - updtime_usec >= DEFAULT_UPDATE_DELAY))) { update_panels(); doupdate(); @@ -962,7 +961,7 @@ void servmon(char *ifname, const struct OPTIONS *options,
printportent(&list, list.barptr, idx);
- print_serv_rates(list.barptr, statwin, options->actmode); + print_serv_rates(list.barptr, statwin, options.actmode); break; case KEY_DOWN: if (!list.barptr @@ -980,7 +979,7 @@ void servmon(char *ifname, const struct OPTIONS *options,
printportent(&list, list.barptr, idx);
- print_serv_rates(list.barptr, statwin, options->actmode); + print_serv_rates(list.barptr, statwin, options.actmode); break; case KEY_PPAGE: case '-': @@ -994,7 +993,7 @@ void servmon(char *ifname, const struct OPTIONS *options,
refresh_serv_screen(&list, idx);
- print_serv_rates(list.barptr, statwin, options->actmode); + print_serv_rates(list.barptr, statwin, options.actmode); break; case KEY_NPAGE: case ' ': @@ -1008,7 +1007,7 @@ void servmon(char *ifname, const struct OPTIONS *options,
refresh_serv_screen(&list, idx);
- print_serv_rates(list.barptr, statwin, options->actmode); + print_serv_rates(list.barptr, statwin, options.actmode); break; case 12: case 'l': @@ -1037,7 +1036,7 @@ void servmon(char *ifname, const struct OPTIONS *options, 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, options.actmode); } refresh_serv_screen(&list, idx); update_panels(); @@ -1052,7 +1051,7 @@ void servmon(char *ifname, const struct OPTIONS *options, packet_process(&pkt, &tot_br, &sport, &dport, ofilter, MATCH_OPPOSITE_USECONFIG, - options->v6inv4asv6); + options.v6inv4asv6);
if (pkt_result != PACKET_OK) continue; @@ -1076,7 +1075,7 @@ void servmon(char *ifname, const struct OPTIONS *options, case IPPROTO_UDP: updateportent(&list, ip_protocol, ntohs(sport), ntohs(dport), iplen, idx, ports, - options->servnames); + options.servnames); break; default: /* unknown L4 protocol */ @@ -1085,7 +1084,7 @@ void servmon(char *ifname, const struct OPTIONS *options, 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, options.actmode); } }
@@ -1095,15 +1094,15 @@ err: if (logging) { signal(SIGUSR1, SIG_DFL); writeutslog(list.head, time(NULL) - starttime, - options->actmode, logfile); + options.actmode, logfile); writelog(logging, logfile, "******** TCP/UDP service monitor stopped ********"); fclose(logfile); } - if (options->servnames) + if (options.servnames) endservent();
- if ((options->promisc) && (is_last_instance())) { + if (options.promisc && is_last_instance()) { load_promisc_list(&promisc_list); srpromisc(0, promisc_list); destroy_promisc_list(&promisc_list); diff --git a/src/serv.h b/src/serv.h index 78447ea..51b8d3c 100644 --- a/src/serv.h +++ b/src/serv.h @@ -19,10 +19,8 @@ void loadaddports(struct porttab **table); void destroyporttab(struct porttab *table); void removeaport(struct porttab **table);
-#include "options.h" #include "fltselect.h"
-void servmon(char *iface, const struct OPTIONS *options, - time_t facilitytime, struct filterstate *ofilter); +void servmon(char *iface, time_t facilitytime, struct filterstate *ofilter);
#endif /* IPTRAF_NG_SERV_H */ diff --git a/src/tcptable.c b/src/tcptable.c index 6979505..3812b86 100644 --- a/src/tcptable.c +++ b/src/tcptable.c @@ -435,8 +435,7 @@ void addtoclosedlist(struct tcptable *table, struct tcptableent *entry)
}
-static char *tcplog_flowrate_msg(struct tcptableent *entry, - struct OPTIONS *opts) +static char *tcplog_flowrate_msg(struct tcptableent *entry) { char rateunit[10]; float rate = 0; @@ -445,7 +444,7 @@ static char *tcplog_flowrate_msg(struct tcptableent *entry,
interval = time(NULL) - entry->conn_starttime;
- if (opts->actmode == KBITS) { + if (options.actmode == KBITS) { strcpy(rateunit, "kbits/s");
if (interval > 0) @@ -468,8 +467,7 @@ static char *tcplog_flowrate_msg(struct tcptableent *entry, return message; }
-void write_timeout_log(int logging, FILE * logfile, struct tcptableent *tcpnode, - struct OPTIONS *opts) +void write_timeout_log(int logging, FILE *logfile, struct tcptableent *tcpnode) { char msgstring[MSGSTRING_MAX];
@@ -478,10 +476,10 @@ void write_timeout_log(int logging, FILE * logfile, struct tcptableent *tcpnode, "TCP; Connection %s:%s to %s:%s timed out, %lu packets, %lu bytes, %s; opposite direction %lu packets, %lu bytes, %s", tcpnode->s_fqdn, tcpnode->s_sname, tcpnode->d_fqdn, tcpnode->d_sname, tcpnode->pcount, tcpnode->bcount, - tcplog_flowrate_msg(tcpnode, opts), + tcplog_flowrate_msg(tcpnode), tcpnode->oth_connection->pcount, tcpnode->oth_connection->bcount, - tcplog_flowrate_msg(tcpnode->oth_connection, opts)); + tcplog_flowrate_msg(tcpnode->oth_connection)); writelog(logging, logfile, msgstring); } } @@ -490,18 +488,12 @@ struct tcptableent *in_table(struct tcptable *table, struct sockaddr_storage *saddr, struct sockaddr_storage *daddr, char *ifname, int logging, - FILE *logfile, struct OPTIONS *opts) + FILE *logfile, time_t timeout) { struct tcp_hashentry *hashptr; unsigned int hp;
time_t now; - time_t timeout; - - if (opts != NULL) - timeout = opts->timeout; - else - timeout = 0;
if (table->head == NULL) { return 0; @@ -535,7 +527,7 @@ struct tcptableent *in_table(struct tcptable *table,
if (logging) write_timeout_log(logging, logfile, - hashptr->tcpnode, opts); + hashptr->tcpnode); } hashptr = hashptr->next_entry; } @@ -565,7 +557,7 @@ void updateentry(struct tcptable *table, struct tcptableent *tableentry, struct tcphdr *transpacket, char *packet, int linkproto, unsigned long packetlength, unsigned int bcount, unsigned int fragofs, int logging, int *revlook, int rvnfd, - struct OPTIONS *opts, FILE * logfile) + FILE *logfile) { char msgstring[MSGSTRING_MAX]; char newmacaddr[18]; @@ -589,7 +581,7 @@ void updateentry(struct tcptable *table, struct tcptableent *tableentry, tableentry->psize = packetlength; tableentry->spanbr += bcount;
- if (opts->mac) { + if (options.mac) { memset(newmacaddr, 0, sizeof(newmacaddr));
@@ -665,7 +657,7 @@ void updateentry(struct tcptable *table, struct tcptableent *tableentry,
if (logging) { writetcplog(logging, logfile, tableentry, - tableentry->psize, opts->mac, + tableentry->psize, options.mac, "FIN acknowleged"); } } @@ -714,10 +706,10 @@ void updateentry(struct tcptable *table, struct tcptableent *tableentry, sprintf(msgstring, "FIN sent; %lu packets, %lu bytes, %s", tableentry->pcount, tableentry->bcount, - tcplog_flowrate_msg(tableentry, opts)); + tcplog_flowrate_msg(tableentry));
writetcplog(logging, logfile, tableentry, - tableentry->psize, opts->mac, msgstring); + tableentry->psize, options.mac, msgstring); } } if (transpacket->rst) { @@ -729,13 +721,12 @@ void updateentry(struct tcptable *table, struct tcptableent *tableentry, snprintf(msgstring, MSGSTRING_MAX, "Connection reset; %lu packets, %lu bytes, %s; opposite direction %lu packets, %lu bytes; %s", tableentry->pcount, tableentry->bcount, - tcplog_flowrate_msg(tableentry, opts), + tcplog_flowrate_msg(tableentry), tableentry->oth_connection->pcount, tableentry->oth_connection->bcount, - tcplog_flowrate_msg(tableentry->oth_connection, - opts)); + tcplog_flowrate_msg(tableentry->oth_connection)); writetcplog(logging, logfile, tableentry, - tableentry->psize, opts->mac, msgstring); + tableentry->psize, options.mac, msgstring); } } if (transpacket->psh) @@ -1054,7 +1045,7 @@ static void destroy_tcp_entry(struct tcptable *table, struct tcptableent *ptmp) */
void flushclosedentries(struct tcptable *table, unsigned long *screen_idx, - int logging, FILE * logfile, struct OPTIONS *opts) + int logging, FILE *logfile) { struct tcptableent *ptmp = table->head; struct tcptableent *ctmp = NULL; @@ -1066,15 +1057,15 @@ void flushclosedentries(struct tcptable *table, unsigned long *screen_idx, now = time(NULL); lastupdated = (now - ptmp->lastupdate) / 60;
- if ((ptmp->inclosed) || (lastupdated > opts->timeout)) { + if ((ptmp->inclosed) || (lastupdated > options.timeout)) { ctmp = ptmp; /* * Mark and flush timed out TCP entries. */ - if (lastupdated > opts->timeout) { + if (lastupdated > options.timeout) { if ((!(ptmp->timedout)) && (!(ptmp->inclosed))) { write_timeout_log(logging, logfile, - ptmp, opts); + ptmp); ptmp->timedout = ptmp->oth_connection->timedout = 1; } diff --git a/src/tcptable.h b/src/tcptable.h index 5cfa746..8d656cc 100644 --- a/src/tcptable.h +++ b/src/tcptable.h @@ -104,13 +104,13 @@ struct tcptableent *in_table(struct tcptable *table, struct sockaddr_storage *saddr, struct sockaddr_storage *daddr, char *ifname, int logging, - FILE * logfile, struct OPTIONS *opts); + FILE *logfile, time_t timeout);
void updateentry(struct tcptable *table, struct tcptableent *tableentry, struct tcphdr *transpacket, char *packet, int linkproto, unsigned long packetlength, unsigned int bcount, unsigned int fragofs, int logging, int *revlook, int rvnfd, - struct OPTIONS *opts, FILE * logfile); + FILE *logfile);
void addtoclosedlist(struct tcptable *table, struct tcptableent *tableentry);
@@ -125,10 +125,9 @@ void refreshtcpwin(struct tcptable *table, unsigned int idx, int mode); void destroytcptable(struct tcptable *table);
void flushclosedentries(struct tcptable *table, unsigned long *screen_idx, - int logging, FILE * logfile, struct OPTIONS *opts); + int logging, FILE *logfile);
-void write_timeout_log(int logging, FILE * logfile, struct tcptableent *tcpnode, - struct OPTIONS *opts); +void write_timeout_log(int logging, FILE *logfile, struct tcptableent *tcpnode);
void writetcplog(int logging, FILE *fd, struct tcptableent *entry, unsigned int pktlen, int mac, char *message);
Signed-off-by: Vitezslav Samel vitezslav@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);
... and this is the end: now the options.actmode is used only in places where it is actually used
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/detstats.c | 18 +++++++++--------- src/hostmon.c | 14 ++++++-------- src/ifstats.c | 8 ++++---- src/itrafmon.c | 2 +- src/rate.c | 9 +++++---- src/rate.h | 4 ++-- src/serv.c | 12 ++++++------ 7 files changed, 33 insertions(+), 34 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c index 5dddc47..efe7d1c 100644 --- a/src/detstats.c +++ b/src/detstats.c @@ -139,22 +139,22 @@ static void writedstatlog(char *ifname,
fprintf(fd, "\nAverage rates:\n");
- rate_print(ts->total.proto_total.pc_bytes / nsecs, options.actmode, bps_string, sizeof(bps_string)); + rate_print(ts->total.proto_total.pc_bytes / nsecs, 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, options.actmode, bps_string, sizeof(bps_string)); + rate_print(ts->total.proto_in.pc_bytes / nsecs, 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, options.actmode, bps_string, sizeof(bps_string)); + rate_print(ts->total.proto_out.pc_bytes / nsecs, 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, options.actmode, bps_string, sizeof(bps_string)); + rate_print(peakactivity, 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, options.actmode, bps_string, sizeof(bps_string)); + rate_print(peakactivity_in, 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, options.actmode, bps_string, sizeof(bps_string)); + rate_print(peakactivity_out, 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); } @@ -438,15 +438,15 @@ void detstats(char *iface, time_t facilitytime, struct filterstate *ofilter) start_tv = tv;
wattrset(statwin, HIGHATTR); - rate_print(activity, options.actmode, buf, sizeof(buf)); + rate_print(activity, 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, options.actmode, buf, sizeof(buf)); + rate_print(activity_in, 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, options.actmode, buf, sizeof(buf)); + rate_print(activity_out, buf, sizeof(buf)); mvwprintw(statwin, 20, 19, "%s", buf); rate_print_pps(pps_out, buf, sizeof(buf)); mvwprintw(statwin, 21, 19, "%s", buf); diff --git a/src/hostmon.c b/src/hostmon.c index bbf993b..341a4a2 100644 --- a/src/hostmon.c +++ b/src/hostmon.c @@ -127,18 +127,16 @@ static void writeethlog(struct ethtabent *list, unsigned long nsecs, FILE *fd) fprintf(fd, "\tAverage rates: "); char buf_in[32]; char buf_out[32]; - rate_print(ptmp->un.figs.inbcount / nsecs, options.actmode, - buf_in, sizeof(buf_in)); - rate_print(ptmp->un.figs.outbcount / nsecs, options.actmode, - buf_out, sizeof(buf_out)); + rate_print(ptmp->un.figs.inbcount / nsecs, buf_in, sizeof(buf_in)); + rate_print(ptmp->un.figs.outbcount / nsecs, 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), - options.actmode, buf_in, sizeof(buf_in)); + buf_in, sizeof(buf_in)); rate_print(rate_get_average(&ptmp->un.figs.outrate), - options.actmode, buf_out, sizeof(buf_out)); + buf_out, sizeof(buf_out)); fprintf(fd, "\tLast 5-second rates: %s incoming, %s outgoing\n", buf_in, buf_out); @@ -417,12 +415,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), - options.actmode, buf, sizeof(buf)); + 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), - options.actmode, buf, sizeof(buf)); + buf, sizeof(buf)); wmove(table->tabwin, target_row, 69 * COLS / 80); wprintw(table->tabwin, "%s", buf); } diff --git a/src/ifstats.c b/src/ifstats.c index 8632877..35a5e18 100644 --- a/src/ifstats.c +++ b/src/ifstats.c @@ -94,11 +94,11 @@ static void writegstatlog(struct iftab *table, unsigned long nsecs, FILE *fd) if (nsecs > 5) { char buf[64];
- rate_print(ptmp->br / nsecs, options.actmode, buf, sizeof(buf)); + rate_print(ptmp->br / nsecs, buf, sizeof(buf)); fprintf(fd, ", average activity %s", buf); - rate_print(ptmp->peakrate, options.actmode, buf, sizeof(buf)); + rate_print(ptmp->peakrate, buf, sizeof(buf)); fprintf(fd, ", peak activity %s", buf); - rate_print(rate_get_average(&ptmp->rate), options.actmode, buf, sizeof(buf)); + rate_print(rate_get_average(&ptmp->rate), buf, sizeof(buf)); fprintf(fd, ", last 5-second average activity %s", buf); } fprintf(fd, "\n"); @@ -266,7 +266,7 @@ static void updaterates(struct iftab *table, unsigned long msecs, do { rate_add_rate(&ptmp->rate, ptmp->spanbr, msecs); rate = rate_get_average(&ptmp->rate); - rate_print(rate, options.actmode, buf, sizeof(buf)); + rate_print(rate, buf, sizeof(buf)); wmove(table->statwin, ptmp->index - idx, 63 * COLS / 80); wprintw(table->statwin, "%s", buf);
diff --git a/src/itrafmon.c b/src/itrafmon.c index 8188f3e..fe1771a 100644 --- a/src/itrafmon.c +++ b/src/itrafmon.c @@ -537,7 +537,7 @@ static void print_flowrate(struct tcptableent *entry, WINDOW *win) wattrset(win, IPSTATATTR);
char buf[32]; - rate_print(rate_get_average(&entry->rate), options.actmode, buf, sizeof(buf)); + rate_print(rate_get_average(&entry->rate), buf, sizeof(buf)); mvwprintw(win, 0, COLS * 52 / 80 + 13, "%s", buf); }
diff --git a/src/rate.c b/src/rate.c index 98c4cf2..7b08852 100644 --- a/src/rate.c +++ b/src/rate.c @@ -2,6 +2,7 @@ /* For authors and contributors see the AUTHORS file */
#include "iptraf-ng-compat.h" +#include "options.h" #include "rate.h"
void rate_init(struct rate *rate) @@ -66,14 +67,14 @@ unsigned long rate_get_average(struct rate *rate) return 0UL; }
-int rate_print(unsigned long rate, int dispmode, char *buf, unsigned n) +int rate_print(unsigned long rate, char *buf, unsigned n) { char *suffix[] = { "k", "M", "G", "T", "P", "E", "Z", "Y" }; unsigned n_suffix = ARRAY_SIZE(suffix);
int chars;
- if (dispmode == KBITS) { + if (options.actmode == KBITS) { unsigned long tmp = rate; unsigned int i = 0; unsigned long divider = 1000; @@ -105,11 +106,11 @@ int rate_print(unsigned long rate, int dispmode, char *buf, unsigned n) return chars; }
-int rate_print_no_units(unsigned long rate, int dispmode, char *buf, unsigned n) +int rate_print_no_units(unsigned long rate, char *buf, unsigned n) { int chars;
- if (dispmode == KBITS) { + if (options.actmode == KBITS) { chars = snprintf(buf, n, "%8.1f", (double)rate * 8 / 1000); } else { chars = snprintf(buf, n, "%8.1f", (double)rate / 1024); diff --git a/src/rate.h b/src/rate.h index 266dd28..871d8e5 100644 --- a/src/rate.h +++ b/src/rate.h @@ -29,8 +29,8 @@ void rate_destroy(struct rate *rate); void rate_add_rate(struct rate *rate, unsigned long bytes, unsigned long msecs); unsigned long rate_get_average(struct rate *rate); -int rate_print(unsigned long rate, int dispmode, char *buf, unsigned n); -int rate_print_no_units(unsigned long rate, int dispmode, char *buf, unsigned n); +int rate_print(unsigned long rate, char *buf, unsigned n); +int rate_print_no_units(unsigned long rate, char *buf, unsigned n); int rate_print_pps(unsigned long rate, char *buf, unsigned n);
#endif /* IPTRAF_NG_RATE_H */ diff --git a/src/serv.c b/src/serv.c index 66c22d3..738c7ec 100644 --- a/src/serv.c +++ b/src/serv.c @@ -118,7 +118,7 @@ static void writeutslog(struct portlistent *list, unsigned long nsecs, FILE *fd) ptmp->serv_count.proto_total.pc_packets, ptmp->serv_count.proto_total.pc_bytes);
- rate_print(ptmp->serv_count.proto_total.pc_bytes / secs, options.actmode, + rate_print(ptmp->serv_count.proto_total.pc_bytes / secs, bps_string, sizeof(bps_string)); fprintf(fd, ", %s", bps_string);
@@ -126,7 +126,7 @@ static void writeutslog(struct portlistent *list, unsigned long nsecs, FILE *fd) ptmp->serv_count.proto_in.pc_packets, ptmp->serv_count.proto_in.pc_bytes);
- rate_print(ptmp->serv_count.proto_in.pc_bytes / secs, options.actmode, + rate_print(ptmp->serv_count.proto_in.pc_bytes / secs, bps_string, sizeof(bps_string)); fprintf(fd, ", %s", bps_string);
@@ -134,7 +134,7 @@ static void writeutslog(struct portlistent *list, unsigned long nsecs, FILE *fd) ptmp->serv_count.proto_out.pc_packets, ptmp->serv_count.proto_out.pc_bytes);
- rate_print(ptmp->serv_count.proto_out.pc_bytes / secs, options.actmode, + rate_print(ptmp->serv_count.proto_out.pc_bytes / secs, bps_string, sizeof(bps_string)); fprintf(fd, ", %s", bps_string);
@@ -730,11 +730,11 @@ static void print_serv_rates(struct portlistent *ple, WINDOW *win) mvwprintw(win, 0, 76, "out");
wattrset(win, IPSTATATTR); - rate_print(rate_get_average(&ple->rate), options.actmode, buf, sizeof(buf)); + rate_print(rate_get_average(&ple->rate), buf, sizeof(buf)); mvwprintw(win, 0, 21, "%s", buf); - rate_print(rate_get_average(&ple->rate_in), options.actmode, buf, sizeof(buf)); + rate_print(rate_get_average(&ple->rate_in), buf, sizeof(buf)); mvwprintw(win, 0, 42, "%s", buf); - rate_print(rate_get_average(&ple->rate_out), options.actmode, buf, sizeof(buf)); + rate_print(rate_get_average(&ple->rate_out), buf, sizeof(buf)); mvwprintw(win, 0, 61, "%s", buf); }
... to places where it is actually used
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/itrafmon.c | 16 ++++++---------- src/othptab.c | 9 +++------ src/othptab.h | 3 +-- src/serv.c | 14 ++++++-------- src/servname.c | 6 +++--- src/servname.h | 3 +-- src/tcptable.c | 6 +++--- src/tcptable.h | 2 +- 8 files changed, 24 insertions(+), 35 deletions(-)
diff --git a/src/itrafmon.c b/src/itrafmon.c index fe1771a..a048374 100644 --- a/src/itrafmon.c +++ b/src/itrafmon.c @@ -1024,8 +1024,7 @@ void ipmon(struct filterstate *ofilter, time_t facilitytime, char *ifptr) NOT_IP, pkt.pkt_protocol, pkt.pkt_payload, ifname, 0, - 0, logging, logfile, - options.servnames, 0); + 0, logging, logfile, 0); continue; }
@@ -1056,8 +1055,7 @@ void ipmon(struct filterstate *ofilter, time_t facilitytime, char *ifptr) wasempty = (table.head == NULL); tcpentry = addentry(&table, &saddr, &daddr, pkt_ip_protocol(&pkt), - ifname, &revlook, rvnfd, - options.servnames); + ifname, &revlook, rvnfd); if (tcpentry != NULL) { printentry(&table, tcpentry->oth_connection, screen_idx, mode); @@ -1166,10 +1164,9 @@ void ipmon(struct filterstate *ofilter, time_t facilitytime, char *ifptr) } add_othp_entry(&othptbl, &pkt, &saddr, &daddr, IS_IP, pkt_ip_protocol(&pkt), - (char *) transpacket, - ifname, &revlook, rvnfd, - logging, logfile, - options.servnames, fragment); + (char *) transpacket, ifname, + &revlook, rvnfd, logging, logfile, + fragment);
} else { if (pkt_ip_protocol(&pkt) == IPPROTO_ICMPV6 @@ -1180,8 +1177,7 @@ void ipmon(struct filterstate *ofilter, time_t facilitytime, char *ifptr) add_othp_entry(&othptbl, &pkt, &saddr, &daddr, IS_IP, pkt_ip_protocol(&pkt), (char *) transpacket, ifname, - &revlook, rvnfd, - logging, logfile, options.servnames, + &revlook, rvnfd, logging, logfile, fragment); } } diff --git a/src/othptab.c b/src/othptab.c index 1eed363..e75f07d 100644 --- a/src/othptab.c +++ b/src/othptab.c @@ -173,8 +173,7 @@ struct othptabent *add_othp_entry(struct othptable *table, struct pkt_hdr *pkt, int protocol, char *packet2, char *ifname, int *rev_lookup, int rvnfd, - int logging, FILE * logfile, - int servnames, int fragment) + int logging, FILE *logfile, int fragment) { struct othptabent *new_entry; struct othptabent *temp; @@ -215,12 +214,10 @@ struct othptabent *add_othp_entry(struct othptable *table, struct pkt_hdr *pkt, new_entry->un.icmp6.code = ((struct icmp6_hdr *) packet2)->icmp6_code; } else if (protocol == IPPROTO_UDP) { - servlook(servnames, - ntohs(((struct udphdr *) packet2)->source), + servlook(ntohs(((struct udphdr *) packet2)->source), IPPROTO_UDP, new_entry->un.udp.s_sname, 10); - servlook(servnames, - ntohs(((struct udphdr *) packet2)->dest), + servlook(ntohs(((struct udphdr *) packet2)->dest), IPPROTO_UDP, new_entry->un.udp.d_sname, 10); } else if (protocol == IPPROTO_OSPFIGP) { diff --git a/src/othptab.h b/src/othptab.h index 153d013..0143c81 100644 --- a/src/othptab.h +++ b/src/othptab.h @@ -128,8 +128,7 @@ struct othptabent *add_othp_entry(struct othptable *table, struct pkt_hdr *pkt, int protocol, char *packet2, char *ifname, int *rev_lookup, int rvnamedon, - int logging, FILE * logfile, - int servnames, int fragment); + int logging, FILE *logfile, int fragment);
void printothpentry(struct othptable *table, struct othptabent *entry, unsigned int screen_idx, int logging, FILE * logfile); diff --git a/src/serv.c b/src/serv.c index 738c7ec..1491ae5 100644 --- a/src/serv.c +++ b/src/serv.c @@ -190,7 +190,7 @@ static void initportlist(struct portlist *list)
static struct portlistent *addtoportlist(struct portlist *list, unsigned int protocol, - unsigned int port, int servnames) + unsigned int port) { struct portlistent *ptemp;
@@ -218,7 +218,7 @@ static struct portlistent *addtoportlist(struct portlist *list, * Obtain appropriate service name */
- servlook(servnames, port, protocol, ptemp->servname, 10); + servlook(port, protocol, ptemp->servname, 10);
memset(&ptemp->serv_count, 0, sizeof(ptemp->serv_count));
@@ -349,8 +349,7 @@ static void destroyportlist(struct portlist *list)
static void updateportent(struct portlist *list, unsigned int protocol, unsigned int sport, unsigned int dport, int br, - unsigned int idx, struct porttab *ports, - int servnames) + unsigned int idx, struct porttab *ports) { struct portlistent *sport_listent = NULL; struct portlistent *dport_listent = NULL; @@ -364,7 +363,7 @@ static void updateportent(struct portlist *list, unsigned int protocol,
if (!sport_listent) sport_listent = - addtoportlist(list, protocol, sport, servnames); + addtoportlist(list, protocol, sport);
if (sport_listent == NULL) return; @@ -378,7 +377,7 @@ static void updateportent(struct portlist *list, unsigned int protocol,
if (!dport_listent) dport_listent = - addtoportlist(list, protocol, dport, servnames); + addtoportlist(list, protocol, dport);
if (dport_listent == NULL) return; @@ -1072,8 +1071,7 @@ void servmon(char *ifname, time_t facilitytime, struct filterstate *ofilter) case IPPROTO_TCP: case IPPROTO_UDP: updateportent(&list, ip_protocol, ntohs(sport), - ntohs(dport), iplen, idx, ports, - options.servnames); + ntohs(dport), iplen, idx, ports); break; default: /* unknown L4 protocol */ diff --git a/src/servname.c b/src/servname.c index 658a1c0..989c395 100644 --- a/src/servname.c +++ b/src/servname.c @@ -9,15 +9,15 @@ servname.c - lookup module for TCP and UDP service names based on ***/
#include "iptraf-ng-compat.h" +#include "options.h"
-void servlook(int servnames, in_port_t port, unsigned int protocol, - char *target, int maxlen) +void servlook(in_port_t port, unsigned int protocol, char *target, int maxlen) { static struct servent *sve;
memset(target, 0, maxlen + 1);
- if (servnames) { + if (options.servnames) { if (protocol == IPPROTO_TCP) sve = getservbyport(htons(port), "tcp"); else diff --git a/src/servname.h b/src/servname.h index 7fc4fed..eae53bb 100644 --- a/src/servname.h +++ b/src/servname.h @@ -7,7 +7,6 @@ servname.h - function prototype for service lookup
***/
-void servlook(int servnames, in_port_t port, unsigned int protocol, - char *target, int maxlen); +void servlook(in_port_t port, unsigned int protocol, char *target, int maxlen);
#endif /* IPTRAF_NG_SERVNAME_H */ diff --git a/src/tcptable.c b/src/tcptable.c index 3812b86..8a08d1d 100644 --- a/src/tcptable.c +++ b/src/tcptable.c @@ -227,7 +227,7 @@ struct tcptableent *addentry(struct tcptable *table, struct sockaddr_storage *saddr, struct sockaddr_storage *daddr, int protocol, char *ifname, - int *rev_lookup, int rvnfd, int servnames) + int *rev_lookup, int rvnfd) { struct tcptableent *new_entry; struct closedlist *ctemp; @@ -356,8 +356,8 @@ struct tcptableent *addentry(struct tcptable *table, new_entry->d_fqdn, sizeof(new_entry->d_fqdn), rvnfd);
/* set port service names (where applicable) */ - servlook(servnames, sockaddr_get_port(saddr), IPPROTO_TCP, new_entry->s_sname, 10); - servlook(servnames, sockaddr_get_port(daddr), IPPROTO_TCP, new_entry->d_sname, 10); + servlook(sockaddr_get_port(saddr), IPPROTO_TCP, new_entry->s_sname, 10); + servlook(sockaddr_get_port(daddr), IPPROTO_TCP, new_entry->d_sname, 10);
strcpy(new_entry->oth_connection->s_sname, new_entry->d_sname); strcpy(new_entry->oth_connection->d_sname, new_entry->s_sname); diff --git a/src/tcptable.h b/src/tcptable.h index 8d656cc..cc32fae 100644 --- a/src/tcptable.h +++ b/src/tcptable.h @@ -98,7 +98,7 @@ struct tcptableent *addentry(struct tcptable *table, struct sockaddr_storage *saddr, struct sockaddr_storage *daddr, int protocol, char *ifname, - int *rev_lookup, int rvnamedon, int servnames); + int *rev_lookup, int rvnamedon);
struct tcptableent *in_table(struct tcptable *table, struct sockaddr_storage *saddr,
... to place where it is actually used
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/itrafmon.c | 5 ++--- src/othptab.c | 10 ++++------ src/othptab.h | 3 +-- src/tcptable.c | 10 +++++----- src/tcptable.h | 2 +- 5 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/src/itrafmon.c b/src/itrafmon.c index a048374..d902407 100644 --- a/src/itrafmon.c +++ b/src/itrafmon.c @@ -647,7 +647,7 @@ void ipmon(struct filterstate *ofilter, time_t facilitytime, char *ifptr) instance_id = adjust_instance_count(ITRAFMONCOUNTFILE, 1);
init_tcp_table(&table); - init_othp_table(&othptbl, options.mac); + init_othp_table(&othptbl);
statwin = newwin(1, COLS, LINES - 2, 0); statpanel = new_panel(statwin); @@ -1111,8 +1111,7 @@ void ipmon(struct filterstate *ofilter, time_t facilitytime, char *ifptr) strcat(msgstring, " (SYN)");
writetcplog(logging, logfile, tcpentry, - pkt.pkt_len, options.mac, - msgstring); + pkt.pkt_len, msgstring); }
if ((revlook) diff --git a/src/othptab.c b/src/othptab.c index e75f07d..142c9c2 100644 --- a/src/othptab.c +++ b/src/othptab.c @@ -86,7 +86,7 @@ static void writeothplog(int logging, FILE *fd, char *protname, } }
-void init_othp_table(struct othptable *table, int mac) +void init_othp_table(struct othptable *table) { unsigned int winht; unsigned int wintop; @@ -117,8 +117,6 @@ void init_othp_table(struct othptable *table, int mac) tx_stdwinset(table->othpwin); getmaxyx(table->borderwin, table->obmaxy, obmaxx); table->oimaxy = table->obmaxy - 2; - - table->mac = mac; }
void process_dest_unreach(struct tcptable *table, char *packet, char *ifname) @@ -183,7 +181,7 @@ struct othptabent *add_othp_entry(struct othptable *table, struct pkt_hdr *pkt, new_entry->is_ip = is_ip; new_entry->fragment = fragment;
- if ((table->mac) || (!is_ip)) { + if (options.mac || !is_ip) { if (pkt->pkt_hatype == ARPHRD_ETHER) { convmacaddr((char *) pkt->ethhdr->h_source, new_entry->smacaddr); convmacaddr((char *) pkt->ethhdr->h_dest, new_entry->dmacaddr); @@ -718,7 +716,7 @@ void printothpentry(struct othptable *table, struct othptabent *entry,
strcat(msgstring, scratchpad);
- if (((entry->smacaddr)[0] != '\0') && (table->mac)) { + if (((entry->smacaddr)[0] != '\0') && options.mac) { snprintf(scratchpad, MSGSTRING_MAX, " (src HWaddr %s)", entry->smacaddr); strcat(msgstring, scratchpad); @@ -736,7 +734,7 @@ void printothpentry(struct othptable *table, struct othptabent *entry,
if (logging) writeothplog(logging, logfile, protname, description, - additional, 1, table->mac, entry); + additional, 1, options.mac, entry); }
void refresh_othwindow(struct othptable *table) diff --git a/src/othptab.h b/src/othptab.h index 0143c81..1987ea7 100644 --- a/src/othptab.h +++ b/src/othptab.h @@ -82,7 +82,6 @@ struct othptable { int htstat; unsigned int obmaxy; /* number of lines in the border window */ unsigned int oimaxy; /* number of lines inside the border */ - int mac; WINDOW *othpwin; PANEL *othppanel; WINDOW *borderwin; @@ -117,7 +116,7 @@ struct ospfhdr { u_short ospf_authtype; };
-void init_othp_table(struct othptable *table, int mac); +void init_othp_table(struct othptable *table);
void process_dest_unreach(struct tcptable *table, char *packet, char *ifname);
diff --git a/src/tcptable.c b/src/tcptable.c index 8a08d1d..d88dc6b 100644 --- a/src/tcptable.c +++ b/src/tcptable.c @@ -657,7 +657,7 @@ void updateentry(struct tcptable *table, struct tcptableent *tableentry,
if (logging) { writetcplog(logging, logfile, tableentry, - tableentry->psize, options.mac, + tableentry->psize, "FIN acknowleged"); } } @@ -709,7 +709,7 @@ void updateentry(struct tcptable *table, struct tcptableent *tableentry, tcplog_flowrate_msg(tableentry));
writetcplog(logging, logfile, tableentry, - tableentry->psize, options.mac, msgstring); + tableentry->psize, msgstring); } } if (transpacket->rst) { @@ -726,7 +726,7 @@ void updateentry(struct tcptable *table, struct tcptableent *tableentry, tableentry->oth_connection->bcount, tcplog_flowrate_msg(tableentry->oth_connection)); writetcplog(logging, logfile, tableentry, - tableentry->psize, options.mac, msgstring); + tableentry->psize, msgstring); } } if (transpacket->psh) @@ -1167,12 +1167,12 @@ void flushclosedentries(struct tcptable *table, unsigned long *screen_idx, }
void writetcplog(int logging, FILE *fd, struct tcptableent *entry, - unsigned int pktlen, int mac, char *message) + unsigned int pktlen, char *message) { char msgbuf[MSGSTRING_MAX];
if (logging) { - if (mac) { + if (options.mac) { snprintf(msgbuf, MSGSTRING_MAX, "TCP; %s; %u bytes; from %s:%s to %s:%s (source MAC addr %s); %s", entry->ifname, pktlen, entry->s_fqdn, diff --git a/src/tcptable.h b/src/tcptable.h index cc32fae..d0f5253 100644 --- a/src/tcptable.h +++ b/src/tcptable.h @@ -130,7 +130,7 @@ void flushclosedentries(struct tcptable *table, unsigned long *screen_idx, void write_timeout_log(int logging, FILE *logfile, struct tcptableent *tcpnode);
void writetcplog(int logging, FILE *fd, struct tcptableent *entry, - unsigned int pktlen, int mac, char *message); + unsigned int pktlen, char *message);
void write_tcp_unclosed(int logging, FILE *fd, struct tcptable *table);
Vitezslav Samel vitezslav@samel.cz writes:
There's no point in passing the struct OPTIONS pointer to every other function; this patch make the "struct OPTIONS options" variable global and fixes every reference to it. Entire patch series also makes iptraf-ng code size by 1,5 kB smaller.
Vitezslav Samel (5): make struct OPTIONS options global move options.actmode variable passing one layer down push options.actmode variable passing one more layer down push options.servnames variable down ... push options.mac variable down ...
src/detstats.c | 44 ++++++++++----------- src/detstats.h | 4 +- src/hostmon.c | 48 ++++++++++------------- src/hostmon.h | 4 +- src/ifstats.c | 39 +++++++++---------- src/ifstats.h | 4 +- src/iptraf.c | 39 +++++++++---------- src/itrafmon.c | 98 +++++++++++++++++++++-------------------------- src/itrafmon.h | 4 +- src/options.c | 114 ++++++++++++++++++++++++++++--------------------------- src/options.h | 8 ++- src/othptab.c | 29 +++++--------- src/othptab.h | 6 +-- src/pktsize.c | 18 ++++---- src/pktsize.h | 5 +- src/rate.c | 9 ++-- src/rate.h | 4 +- src/serv.c | 74 +++++++++++++++++------------------- src/serv.h | 4 +- src/servname.c | 6 +- src/servname.h | 3 +- src/tcptable.c | 57 ++++++++++++---------------- src/tcptable.h | 13 +++--- 23 files changed, 290 insertions(+), 344 deletions(-)
honestly, I will squash them into one.
On Fri, Aug 24, 2012 at 02:27:58PM +0200, Nikola Pajkovsky wrote:
Vitezslav Samel vitezslav@samel.cz writes:
There's no point in passing the struct OPTIONS pointer to every other function; this patch make the "struct OPTIONS options" variable global and fixes every reference to it. Entire patch series also makes iptraf-ng code size by 1,5 kB smaller.
Vitezslav Samel (5): make struct OPTIONS options global move options.actmode variable passing one layer down push options.actmode variable passing one more layer down push options.servnames variable down ... push options.mac variable down ...
src/detstats.c | 44 ++++++++++----------- src/detstats.h | 4 +- src/hostmon.c | 48 ++++++++++------------- src/hostmon.h | 4 +- src/ifstats.c | 39 +++++++++---------- src/ifstats.h | 4 +- src/iptraf.c | 39 +++++++++---------- src/itrafmon.c | 98 +++++++++++++++++++++-------------------------- src/itrafmon.h | 4 +- src/options.c | 114 ++++++++++++++++++++++++++++--------------------------- src/options.h | 8 ++- src/othptab.c | 29 +++++--------- src/othptab.h | 6 +-- src/pktsize.c | 18 ++++---- src/pktsize.h | 5 +- src/rate.c | 9 ++-- src/rate.h | 4 +- src/serv.c | 74 +++++++++++++++++------------------- src/serv.h | 4 +- src/servname.c | 6 +- src/servname.h | 3 +- src/tcptable.c | 57 ++++++++++++---------------- src/tcptable.h | 13 +++--- 23 files changed, 290 insertions(+), 344 deletions(-)
honestly, I will squash them into one.
Please, DON'T do this next time. Don't you think there's a reason for it? This makes "git bisect" much much more friendly. When you bisect down to this rather large commit, how would you find a bug in it?
The first patch was so big because I couldn't make it smaller, the others are small and much more readable and finding a bug is a fun.
I spent rather a big time in separating those patches so PLEASE don't waste my time.
Thanks, Vita
On Fri, Aug 24, 2012 at 02:27:58PM +0200, Nikola Pajkovsky wrote:
Vitezslav Samel vitezslav@samel.cz writes:
There's no point in passing the struct OPTIONS pointer to every other function; this patch make the "struct OPTIONS options" variable global and fixes every reference to it. Entire patch series also makes iptraf-ng code size by 1,5 kB smaller.
Vitezslav Samel (5): make struct OPTIONS options global move options.actmode variable passing one layer down push options.actmode variable passing one more layer down push options.servnames variable down ... push options.mac variable down ...
src/detstats.c | 44 ++++++++++----------- src/detstats.h | 4 +- src/hostmon.c | 48 ++++++++++------------- src/hostmon.h | 4 +- src/ifstats.c | 39 +++++++++---------- src/ifstats.h | 4 +- src/iptraf.c | 39 +++++++++---------- src/itrafmon.c | 98 +++++++++++++++++++++-------------------------- src/itrafmon.h | 4 +- src/options.c | 114 ++++++++++++++++++++++++++++--------------------------- src/options.h | 8 ++- src/othptab.c | 29 +++++--------- src/othptab.h | 6 +-- src/pktsize.c | 18 ++++---- src/pktsize.h | 5 +- src/rate.c | 9 ++-- src/rate.h | 4 +- src/serv.c | 74 +++++++++++++++++------------------- src/serv.h | 4 +- src/servname.c | 6 +- src/servname.h | 3 +- src/tcptable.c | 57 ++++++++++++---------------- src/tcptable.h | 13 +++--- 23 files changed, 290 insertions(+), 344 deletions(-)
honestly, I will squash them into one.
Honestly, I didn't sent you the squashed patch, so you can't put my Signed-off-by: line on it (From: is possible, but not Signed-off-by:)
Vita
iptraf-ng@lists.fedorahosted.org