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(a)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 | 89 +++++++++++++++++++++----------------------
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, 224 insertions(+), 251 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c
index 44cf812..195ee3f 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..527ad4f 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..66ab444 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 4c64cac..d9a04a7 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -327,8 +327,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;
@@ -351,8 +350,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;
@@ -360,7 +359,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;
@@ -370,8 +369,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;
@@ -379,7 +378,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;
}
@@ -415,8 +414,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;
@@ -425,15 +423,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);
}
}
@@ -443,8 +441,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;
@@ -459,7 +456,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();
@@ -547,10 +544,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 */
@@ -610,7 +606,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;
@@ -634,7 +630,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);
@@ -650,7 +646,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);
@@ -676,7 +672,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
update_panels();
doupdate();
- if (options->servnames)
+ if (options.servnames)
setservent(1);
/*
@@ -751,10 +747,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;
}
@@ -763,9 +759,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();
@@ -782,7 +778,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,
@@ -931,7 +927,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;
@@ -946,7 +942,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':
@@ -971,7 +967,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;
@@ -994,7 +990,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;
@@ -1024,7 +1020,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,
ntohs(sport),
ntohs(dport),
ifname, logging,
- logfile, options);
+ logfile, options.timeout);
} else {
tcpentry =
in_table(&table, 0, 0,
@@ -1052,7 +1048,8 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
(uint8_t *) &pkt.ip6_hdr->
ip6_dst.s6_addr,
ntohs(sport), ntohs(dport),
- ifname, logging, logfile, options);
+ ifname, logging, logfile,
+ options.timeout);
}
/*
@@ -1077,7 +1074,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
NULL, NULL, sport, dport,
pkt_ip_protocol(&pkt),
ifname, &revlook, rvnfd,
- options->servnames);
+ options.servnames);
else
tcpentry =
addentry(&table, 0, 0,
@@ -1085,7 +1082,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
(uint8_t *) &pkt.ip6_hdr->ip6_dst.s6_addr,
sport, dport, pkt_ip_protocol(&pkt),
ifname, &revlook, rvnfd,
- options->servnames);
+ options.servnames);
if (tcpentry != NULL) {
printentry(&table, tcpentry->oth_connection, screen_idx,
mode);
@@ -1119,13 +1116,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
@@ -1141,7 +1138,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);
}
@@ -1198,7 +1195,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
@@ -1211,7 +1208,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);
}
}
@@ -1222,13 +1219,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..6683d26 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 1d223ce..23c4118 100644
--- a/src/othptab.c
+++ b/src/othptab.c
@@ -130,10 +130,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) {
@@ -144,7 +142,7 @@ void process_dest_unreach(struct tcptable *table, char *packet, char *ifname)
tcpentry =
in_table(table, 0, 0, ip6->ip6_src.s6_addr,
ip6->ip6_dst.s6_addr, ntohs(tcp->source),
- ntohs(tcp->dest), ifname, 0, NULL, NULL);
+ ntohs(tcp->dest), ifname, 0, NULL, 0);
} else {
if (ip->protocol != IPPROTO_TCP)
return;
@@ -152,7 +150,7 @@ void process_dest_unreach(struct tcptable *table, char *packet, char *ifname)
tcpentry =
in_table(table, ip->saddr, ip->daddr, NULL, NULL,
ntohs(tcp->source), ntohs(tcp->dest), ifname, 0,
- NULL, NULL);
+ NULL, 0);
}
if (tcpentry != NULL) {
diff --git a/src/pktsize.c b/src/pktsize.c
index b0c411f..d164cc5 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 c6a5521..9a1ab2e 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 ff85c9b..aa4a3dc 100644
--- a/src/tcptable.c
+++ b/src/tcptable.c
@@ -441,8 +441,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;
@@ -451,7 +450,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)
@@ -474,8 +473,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];
@@ -484,10 +482,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);
}
}
@@ -496,22 +494,16 @@ struct tcptableent *in_table(struct tcptable *table, unsigned long saddr,
unsigned long daddr, uint8_t * s6addr,
uint8_t * d6addr, unsigned int sport,
unsigned int dport, 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;
int sfree = 0;
int dfree = 0;
- if (opts != NULL)
- timeout = opts->timeout;
- else
- timeout = 0;
-
if (table->head == NULL) {
return 0;
}
@@ -557,7 +549,7 @@ struct tcptableent *in_table(struct tcptable *table, unsigned long saddr,
if (logging)
write_timeout_log(logging, logfile,
- hashptr->tcpnode, opts);
+ hashptr->tcpnode);
}
hashptr = hashptr->next_entry;
}
@@ -592,7 +584,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];
@@ -616,7 +608,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));
@@ -692,7 +684,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");
}
}
@@ -741,10 +733,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) {
@@ -756,13 +748,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)
@@ -1081,7 +1072,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;
@@ -1093,15 +1084,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 8b3b931..d9f2d46 100644
--- a/src/tcptable.h
+++ b/src/tcptable.h
@@ -108,13 +108,13 @@ struct tcptableent *in_table(struct tcptable *table, unsigned long saddr,
unsigned long daddr, uint8_t * s6addr,
uint8_t * d6addr, unsigned int sport,
unsigned int dport, 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);
@@ -129,10 +129,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);
--
1.7.8.4