... instead of memset(struct, 0, sizeof(struct)).
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/counters.c | 17 +++++++++++++++++
src/counters.h | 3 +++
src/detstats.c | 9 +++++----
src/serv.c | 4 ++--
4 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/src/counters.c b/src/counters.c
index 89dc0cd..f71880c 100644
--- a/src/counters.c
+++ b/src/counters.c
@@ -1,6 +1,8 @@
/* For terms of usage/redistribution/modification see the LICENSE file */
/* For authors and contributors see the AUTHORS file */
+#include "iptraf-ng-compat.h"
+
#include "counters.h"
void pkt_counter_update(struct pkt_counter *count, int bytes)
@@ -11,6 +13,12 @@ void pkt_counter_update(struct pkt_counter *count, int bytes)
}
}
+void pkt_counter_reset(struct pkt_counter *count)
+{
+ if (count)
+ memset(count, 0, sizeof(*count));
+}
+
void proto_counter_update(struct proto_counter *proto_counter, int outgoing, int bytes)
{
if (proto_counter) {
@@ -21,3 +29,12 @@ void proto_counter_update(struct proto_counter *proto_counter, int
outgoing, int
pkt_counter_update(&proto_counter->proto_in, bytes);
}
}
+
+void proto_counter_reset(struct proto_counter *proto_counter)
+{
+ if (proto_counter) {
+ pkt_counter_reset(&proto_counter->proto_total);
+ pkt_counter_reset(&proto_counter->proto_out);
+ pkt_counter_reset(&proto_counter->proto_in);
+ }
+}
diff --git a/src/counters.h b/src/counters.h
index ab4cec6..1746d0c 100644
--- a/src/counters.h
+++ b/src/counters.h
@@ -13,7 +13,10 @@ struct proto_counter {
};
void pkt_counter_update(struct pkt_counter *count, int bytes);
+void pkt_counter_reset(struct pkt_counter *count);
+
void proto_counter_update(struct proto_counter *proto_counter, int outgoing,
int bytes);
+void proto_counter_reset(struct proto_counter *proto_counter);
#endif /* IPTRAF_NG_COUNTERS_H */
diff --git a/src/detstats.c b/src/detstats.c
index bb5ce32..e560f67 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -351,8 +351,8 @@ void detstats(char *iface, time_t facilitytime)
update_panels();
doupdate();
- memset(&span, 0, sizeof(span));
- memset(&span_bcast, 0, sizeof(span_bcast));
+ proto_counter_reset(&span);
+ pkt_counter_reset(&span_bcast);
rate_alloc(&rate, 5);
rate_alloc(&rate_in, 5);
rate_alloc(&rate_out, 5);
@@ -426,8 +426,9 @@ void detstats(char *iface, time_t facilitytime)
rate_add_rate(&pps_rate_bcast, span_bcast.pc_packets, msecs);
pps_bcast = rate_get_average(&pps_rate_bcast);
- memset(&span, 0, sizeof(span));
- memset(&span_bcast, 0, sizeof(span_bcast));
+ proto_counter_reset(&span);
+ pkt_counter_reset(&span_bcast);
+
starttime = now;
start_tv = tv;
diff --git a/src/serv.c b/src/serv.c
index 7e27b84..0907495 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -215,7 +215,7 @@ static struct portlistent *addtoportlist(struct portlist *list,
servlook(port, protocol, ptemp->servname, 10);
- memset(&ptemp->serv_count, 0, sizeof(ptemp->serv_count));
+ proto_counter_reset(&ptemp->serv_count);
list->count++;
ptemp->idx = list->count;
@@ -774,7 +774,7 @@ static void update_serv_rates(struct portlist *list, unsigned long
msecs)
rate_add_rate(&ple->rate_in, ple->span.proto_in.pc_bytes, msecs);
rate_add_rate(&ple->rate_out, ple->span.proto_out.pc_bytes, msecs);
- memset(&ple->span, 0, sizeof(ple->span));
+ proto_counter_reset(&ple->span);
}
}
--
1.9.1