There are only 'struct *counter' in ifstats.h left, so rename
ifstats.h to counters.h, move update_*_counter() from detstats.c
to the new counters.c (and rename update_counter() to
update_pkt_counter()) and make all the needed changes to make
it compile.
This change allow us to use 'struct pkt_counter' in other files too.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/Makefile.am | 3 ++-
src/counters.c | 23 +++++++++++++++++++++++
src/counters.h | 19 +++++++++++++++++++
src/detstats.c | 26 +++-----------------------
src/ifstats.c | 1 -
src/ifstats.h | 21 ---------------------
src/promisc.c | 1 -
7 files changed, 47 insertions(+), 47 deletions(-)
create mode 100644 src/counters.c
create mode 100644 src/counters.h
delete mode 100644 src/ifstats.h
diff --git a/src/Makefile.am b/src/Makefile.am
index b5caa47..0b89a81 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,7 +31,6 @@ LIB_H += parse-options.h
LIB_H += packet.h
LIB_H += tcptable.h
LIB_H += othptab.h
-LIB_H += ifstats.h
LIB_H += deskman.h
LIB_H += hostmon.h
LIB_H += fltedit.h
@@ -64,6 +63,7 @@ LIB_H += attrs.h
LIB_H += fltdefs.h
LIB_H += logvars.h
LIB_H += list.h
+LIB_H += counters.h
LIB_C += error.c
LIB_C += log.c
@@ -99,6 +99,7 @@ LIB_C += deskman.c
LIB_C += hostmon.c
LIB_C += fltedit.c
LIB_C += cidr.c
+LIB_C += counters.c
iptraf_ng_SOURCES = \
$(TUI_C) $(TUI_H) \
diff --git a/src/counters.c b/src/counters.c
new file mode 100644
index 0000000..f3281ec
--- /dev/null
+++ b/src/counters.c
@@ -0,0 +1,23 @@
+/* For terms of usage/redistribution/modification see the LICENSE file */
+/* For authors and contributors see the AUTHORS file */
+
+#include "counters.h"
+
+void update_pkt_counter(struct pkt_counter *count, int bytes)
+{
+ if (count) {
+ count->pc_packets++;
+ count->pc_bytes += bytes;
+ }
+}
+
+void update_proto_counter(struct proto_counter *proto_counter, int outgoing, int bytes)
+{
+ if (proto_counter) {
+ update_pkt_counter(&proto_counter->proto_total, bytes);
+ if (outgoing)
+ update_pkt_counter(&proto_counter->proto_out, bytes);
+ else
+ update_pkt_counter(&proto_counter->proto_in, bytes);
+ }
+}
diff --git a/src/counters.h b/src/counters.h
new file mode 100644
index 0000000..e1dfbab
--- /dev/null
+++ b/src/counters.h
@@ -0,0 +1,19 @@
+#ifndef IPTRAF_NG_COUNTERS_H
+#define IPTRAF_NG_COUNTERS_H
+
+struct pkt_counter {
+ unsigned long long pc_packets;
+ unsigned long long pc_bytes;
+};
+
+struct proto_counter {
+ struct pkt_counter proto_total;
+ struct pkt_counter proto_in;
+ struct pkt_counter proto_out;
+};
+
+void update_pkt_counter(struct pkt_counter *count, int bytes);
+void update_proto_counter(struct proto_counter *proto_counter, int outgoing,
+ int bytes);
+
+#endif /* IPTRAF_NG_COUNTERS_H */
diff --git a/src/detstats.c b/src/detstats.c
index cf68002..b9cfe49 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -10,7 +10,7 @@ detstats.c - the interface statistics module
#include "iptraf-ng-compat.h"
#include "tui/tui.h"
-#include "ifstats.h"
+#include "counters.h"
#include "ifaces.h"
#include "isdntab.h"
#include "fltdefs.h"
@@ -266,26 +266,6 @@ static void printdetails(struct ifcounts *ifcounts, WINDOW * win)
mvwprintw(win, 19, 68, "%8lu", ifcounts->bad.pc_packets);
}
-static void update_counter(struct pkt_counter *count, int bytes)
-{
- if (count) {
- count->pc_packets++;
- count->pc_bytes += bytes;
- }
-}
-
-static void update_proto_counter(struct proto_counter *proto_counter, int outgoing, int
bytes)
-{
- if (proto_counter) {
- update_counter(&proto_counter->proto_total, bytes);
- if (outgoing)
- update_counter(&proto_counter->proto_out, bytes);
- else
- update_counter(&proto_counter->proto_in, bytes);
- }
-}
-
-
/*
* The detailed interface statistics function
*/
@@ -573,7 +553,7 @@ void detstats(char *iface, const struct OPTIONS *options, time_t
facilitytime,
outgoing = (pkt.pkt_pkttype == PACKET_OUTGOING);
update_proto_counter(&ifcounts.total, outgoing, framelen);
if (pkt.pkt_pkttype == PACKET_BROADCAST) {
- update_counter(&ifcounts.bcast, framelen);
+ update_pkt_counter(&ifcounts.bcast, framelen);
}
update_proto_counter(&span, outgoing, framelen);
@@ -582,7 +562,7 @@ void detstats(char *iface, const struct OPTIONS *options, time_t
facilitytime,
switch(pkt.pkt_protocol) {
case ETH_P_IP:
if (pkt_result == CHECKSUM_ERROR) {
- update_counter(&ifcounts.bad, framelen);
+ update_pkt_counter(&ifcounts.bad, framelen);
continue;
}
diff --git a/src/ifstats.c b/src/ifstats.c
index b81de1b..bcf4e74 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -10,7 +10,6 @@ ifstats.c - the interface statistics module
#include "iptraf-ng-compat.h"
#include "tui/tui.h"
-#include "ifstats.h"
#include "ifaces.h"
#include "isdntab.h"
#include "fltdefs.h"
diff --git a/src/ifstats.h b/src/ifstats.h
deleted file mode 100644
index ce3800f..0000000
--- a/src/ifstats.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef IPTRAF_NG_IFSTATS_H
-#define IPTRAF_NG_IFSTATS_H
-
-/***
-
-ifstats.h - structure definitions for interface counts
-
-***/
-
-struct pkt_counter {
- unsigned long long pc_packets;
- unsigned long long pc_bytes;
-};
-
-struct proto_counter {
- struct pkt_counter proto_total;
- struct pkt_counter proto_in;
- struct pkt_counter proto_out;
-};
-
-#endif /* IPTRAF_NG_IFSTATS_H */
diff --git a/src/promisc.c b/src/promisc.c
index 1dc96df..a0f5364 100644
--- a/src/promisc.c
+++ b/src/promisc.c
@@ -10,7 +10,6 @@ promisc.c - handles the promiscuous mode flag for the Ethernet/FDDI/
#include "iptraf-ng-compat.h"
-#include "ifstats.h"
#include "ifaces.h"
#include "error.h"
#include "promisc.h"
--
1.7.8.4