]> git.tdb.fi Git - netvis.git/blobdiff - source/netvis.cpp
Handle ICMP packets
[netvis.git] / source / netvis.cpp
index 0e2378fd689ac6ee9efb96a6d77a0ff9af10efc9..771af7f5db93272ee673faffc481810f81ee1164 100644 (file)
@@ -296,6 +296,13 @@ Port &NetVis::get_port(unsigned 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;
 }
@@ -345,6 +352,11 @@ void NetVis::handle_ipv4(CaptureContext &ctx, const iphdr *ip, unsigned len)
                const udphdr *udp = reinterpret_cast<const udphdr *>(ip+1);
                handle_udp(ctx, udp, len-sizeof(iphdr));
        }
+       else if(ip->protocol==IPPROTO_ICMP)
+       {
+               const icmphdr *icmp = reinterpret_cast<const icmphdr *>(ip+1);
+               handle_icmp(ctx, icmp, len-sizeof(iphdr));
+       }
        else
                IO::print("Unknown protocol in ip: %d\n", ip->protocol);
 }
@@ -365,6 +377,11 @@ void NetVis::handle_ipv6(CaptureContext &ctx, const ip6_hdr *ip6, unsigned len)
                const udphdr *udp = reinterpret_cast<const udphdr *>(ip6+1);
                handle_udp(ctx, udp, len-sizeof(ip6_hdr));
        }
+       else if(ip6->ip6_nxt==IPPROTO_ICMPV6)
+       {
+               const icmp6_hdr *icmp6 = reinterpret_cast<const icmp6_hdr *>(ip6+1);
+               handle_icmp6(ctx, icmp6, len-sizeof(ip6_hdr));
+       }
        else
                IO::print("Unknown next header in ip6: %d\n", ip6->ip6_nxt);
 }
@@ -383,6 +400,20 @@ void NetVis::handle_udp(CaptureContext &ctx, const udphdr *udp, unsigned)
        handle_packet(ctx);
 }
 
+void NetVis::handle_icmp(CaptureContext &ctx, const icmphdr *, unsigned)
+{
+       ctx.src_port = &get_port(0x10000|IPPROTO_ICMP);
+       ctx.dst_port = ctx.src_port;
+       handle_packet(ctx);
+}
+
+void NetVis::handle_icmp6(CaptureContext &ctx, const icmp6_hdr *, unsigned)
+{
+       ctx.src_port = &get_port(0x10000|IPPROTO_ICMPV6);
+       ctx.dst_port = ctx.src_port;
+       handle_packet(ctx);
+}
+
 void NetVis::handle_packet(CaptureContext &ctx)
 {
        Port *port = 0;