- unsigned size = ntohs(ip->tot_len);
- unsigned port = 0;
- if(ip->protocol==IPPROTO_TCP)
- {
- const tcphdr *tcp = reinterpret_cast<const tcphdr *>(ip+1);
- port = min(ntohs(tcp->source), ntohs(tcp->dest));
- }
- else if(ip->protocol==IPPROTO_UDP)
- {
- const udphdr *udp = reinterpret_cast<const udphdr *>(ip+1);
- port = min(ntohs(udp->source), ntohs(udp->dest));
- }
- Host &shost = self->get_host(ntohl(ip->saddr));
- Host *dhost = 0;
- if((ntohl(ip->daddr)&0xFF)!=0xFF)
- dhost = &self->get_host(ntohl(ip->daddr));
+void NetVis::handle_ipv4(CaptureContext &ctx, const iphdr *ip, unsigned len)
+{
+ ctx.src_host = &get_host(ntohl(ip->saddr));
+ if((ntohl(ip->daddr)&0xFF)!=0xFF)
+ ctx.dst_host = &get_host(ntohl(ip->daddr));
+
+ if(ip->protocol==IPPROTO_TCP)
+ {
+ const tcphdr *tcp = reinterpret_cast<const tcphdr *>(ip+1);
+ handle_tcp(ctx, tcp, len-sizeof(iphdr));
+ }
+ else if(ip->protocol==IPPROTO_UDP)
+ {
+ const udphdr *udp = reinterpret_cast<const udphdr *>(ip+1);
+ handle_udp(ctx, udp, len-sizeof(iphdr));
+ }
+ else
+ IO::print("Unknown protocol in ip: %d\n", ip->protocol);
+}
+
+void NetVis::handle_ipv6(CaptureContext &ctx, const ip6_hdr *ip6, unsigned len)
+{
+ ctx.src_host = &get_host(ip6->ip6_src);
+ if(!IN6_IS_ADDR_MULTICAST(ip6->ip6_dst.s6_addr))
+ ctx.dst_host = &get_host(ip6->ip6_dst);
+
+ if(ip6->ip6_nxt==IPPROTO_TCP)
+ {
+ const tcphdr *tcp = reinterpret_cast<const tcphdr *>(ip6+1);
+ handle_tcp(ctx, tcp, len-sizeof(ip6_hdr));
+ }
+ else if(ip6->ip6_nxt==IPPROTO_UDP)
+ {
+ const udphdr *udp = reinterpret_cast<const udphdr *>(ip6+1);
+ handle_udp(ctx, udp, len-sizeof(ip6_hdr));
+ }
+ else
+ IO::print("Unknown next header in ip6: %d\n", ip6->ip6_nxt);
+}