+void NetVis::capture_handler(unsigned char *user, const pcap_pkthdr *cap, const unsigned char *data)
+{
+ NetVis *self = reinterpret_cast<NetVis *>(user);
+
+ CaptureContext ctx;
+ ctx.cap_hdr = cap;
+ const ethhdr *eth = reinterpret_cast<const ethhdr *>(data);
+ self->handle_ethernet(ctx, eth, cap->caplen);
+}
+
+void NetVis::handle_ethernet(CaptureContext &ctx, const ethhdr *eth, unsigned len)
+{
+ ctx.size = ctx.cap_hdr->len-sizeof(ethhdr);
+
+ int proto = ntohs(eth->h_proto);
+ if(proto==ETH_P_IP)
+ {
+ const iphdr *ip = reinterpret_cast<const iphdr *>(eth+1);
+ handle_ipv4(ctx, ip, len-sizeof(ethhdr));
+ }
+ else if(proto==ETH_P_IPV6)
+ {
+ const ip6_hdr *ip6 = reinterpret_cast<const ip6_hdr *>(eth+1);
+ handle_ipv6(ctx, ip6, len-sizeof(ethhdr));
+ }
+ else
+ IO::print("Unknown protocol in eth: %d\n", proto);
+}
+
+void NetVis::handle_ipv4(CaptureContext &ctx, const iphdr *ip, unsigned len)