summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2003-01-24 08:54:10 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2003-01-24 08:54:10 +0000
commitfae7f597349d2dadcde2c1f26438ae8e98751a2b (patch)
tree4ebb5c0fa5a118ac1ebc1aed4bb5207cf981416f /sbin
parent2a9f52bd4c35096196c9b3c75130216154497727 (diff)
bring in 3 yet unused helper functions before I lose 'em again
Diffstat (limited to 'sbin')
-rw-r--r--sbin/pfctl/pfctl_qstats.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/sbin/pfctl/pfctl_qstats.c b/sbin/pfctl/pfctl_qstats.c
index 1bb690de29c..e25925b289e 100644
--- a/sbin/pfctl/pfctl_qstats.c
+++ b/sbin/pfctl/pfctl_qstats.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl_qstats.c,v 1.7 2003/01/10 08:03:28 henning Exp $ */
+/* $OpenBSD: pfctl_qstats.c,v 1.8 2003/01/24 08:54:09 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer
@@ -84,6 +84,10 @@ void pfctl_free_altq_node(struct pf_altq_node *);
void pfctl_print_altq_nodestat(int,
const struct pf_altq_node *);
+double calc_interval(struct timeval *, struct timeval *);
+double calc_rate(u_int64_t, u_int64_t, double);
+double calc_pps(u_int64_t, u_int64_t, double);
+
int
pfctl_show_altq(int dev, int verbose)
{
@@ -285,3 +289,34 @@ pfctl_free_altq_node(struct pf_altq_node *node)
free(prev);
}
}
+
+/* calculate interval in sec */
+double
+calc_interval(struct timeval *cur_time, struct timeval *last_time)
+{
+ double sec;
+
+ sec = (double)(cur_time->tv_sec - last_time->tv_sec) +
+ (double)(cur_time->tv_usec - last_time->tv_usec) / 1000000;
+ return (sec);
+}
+
+/* calculate rate in bps */
+double
+calc_rate(u_int64_t new_bytes, u_int64_t last_bytes, double interval)
+{
+ double rate;
+
+ rate = (double)(new_bytes - last_bytes) * 8 / interval;
+ return (rate);
+}
+
+/* calculate packets in second */
+double
+calc_pps(u_int64_t new_pkts, u_int64_t last_pkts, double interval)
+{
+ double pps;
+
+ pps = (double)(new_pkts - last_pkts) / interval;
+ return (pps);
+}