#include <arpa/inet.h> /* for inet_aton() */
#define __FAVOR_BSD
#include <netinet/tcp.h>
+#include <sys/socket.h>
#include <stdlib.h> /* for free */
#include <string.h> /* for memcpy */
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;
- if (using_localnet) {
- if ((sm->src_ip & localmask) == localnet)
- dir_out = 1;
- if ((sm->dest_ip & localmask) == localnet)
- dir_in = 1;
- if (dir_in == 1 && dir_out == 1)
- /* Traffic staying within the network isn't counted. */
- dir_in = dir_out = 0;
- } else {
- if (sm->src_ip == localip)
+ if (sm->af == AF_INET) {
+ if (using_localnet) {
+ if ((sm->src_ip & localmask) == localnet)
+ dir_out = 1;
+ if ((sm->dest_ip & localmask) == localnet)
+ dir_in = 1;
+ if (dir_in == 1 && dir_out == 1)
+ /* Traffic staying within the network isn't counted. */
+ dir_in = dir_out = 0;
+ } else {
+ if (sm->src_ip == localip)
+ dir_out = 1;
+ if (sm->dest_ip == localip)
+ dir_in = 1;
+ }
+ } else if (sm->af == AF_INET6) {
+ /* Only exact address has been implemented. */
+ if (memcmp(&sm->src_ip6, &localip6, sizeof(localip6)) == 0)
dir_out = 1;
- if (sm->dest_ip == localip)
+ if (memcmp(&sm->dest_ip6, &localip6, sizeof(localip6)) == 0)
dir_in = 1;
}
graph_acct((uint64_t)sm->len, GRAPH_IN);
}
+ if (sm->af == AF_INET6) return; /* Still no continuation for IPv6! */
+
+ 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) {
pd->in += sm->len;
pd->total += sm->len;
+ if (ports_max == 0) return; /* skip ports accounting */
+
/* Ports. */
switch (sm->proto)
{
break;
case IPPROTO_ICMP:
+ case IPPROTO_ICMPV6:
/* known protocol, don't complain about it */
break;