Skip per-host accounting if --hosts-max is zero.
authorEmil Mikulic <emikulic@gmail.com>
Thu, 1 Jan 2009 12:17:34 +0000 (23:17 +1100)
committerEmil Mikulic <emikulic@gmail.com>
Fri, 24 Apr 2009 11:40:23 +0000 (21:40 +1000)
acct.c

diff --git a/acct.c b/acct.c
index 7c70011..ae9c39d 100644 (file)
--- a/acct.c
+++ b/acct.c
@@ -101,19 +101,6 @@ acct_for(const pktsummary *sm)
    total_packets++;
    total_bytes += sm->len;
 
-   /* Hosts. */
-   hs = host_get(sm->src_ip);
-   hs->out   += sm->len;
-   hs->total += sm->len;
-   memcpy(hs->u.host.mac_addr, sm->src_mac, sizeof(sm->src_mac));
-   hs->u.host.last_seen = now;
-
-   hd = host_get(sm->dest_ip); /* this can invalidate hs! */
-   hd->in    += sm->len;
-   hd->total += sm->len;
-   memcpy(hd->u.host.mac_addr, sm->dst_mac, sizeof(sm->dst_mac));
-   hd->u.host.last_seen = now;
-
    /* Graphs. */
    dir_in = dir_out = 0;
 
@@ -141,6 +128,21 @@ acct_for(const pktsummary *sm)
       graph_acct((uint64_t)sm->len, GRAPH_IN);
    }
 
+   if (hosts_max == 0) return; /* skip per-host accounting */
+
+   /* Hosts. */
+   hs = host_get(sm->src_ip);
+   hs->out   += sm->len;
+   hs->total += sm->len;
+   memcpy(hs->u.host.mac_addr, sm->src_mac, sizeof(sm->src_mac));
+   hs->u.host.last_seen = now;
+
+   hd = host_get(sm->dest_ip); /* this can invalidate hs! */
+   hd->in    += sm->len;
+   hd->total += sm->len;
+   memcpy(hd->u.host.mac_addr, sm->dst_mac, sizeof(sm->dst_mac));
+   hd->u.host.last_seen = now;
+
    /* Protocols. */
    hs = host_find(sm->src_ip);
    if (hs != NULL) {