- map<unsigned, GL::Color>::iterator i=port_colors.find(port);
- if(i!=port_colors.end())
- return i->second;
+ map<unsigned, Port *>::iterator i = ports.find(number);
+ if(i!=ports.end())
+ return *i->second;
+ Port *port = new Port(*this, number);
+ if(number>=0x10000)
+ {
+ if((number&0xFF)==IPPROTO_ICMP)
+ port->set_name("icmp");
+ else if((number&0xFF)==IPPROTO_ICMPV6)
+ port->set_name("icmp6");
+ }
+ ports[number] = port;
+ return *port;
+}
+
+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);