]> git.tdb.fi Git - netvis.git/blobdiff - source/netvis.h
Handle ICMP packets
[netvis.git] / source / netvis.h
index 9e8661e58307c43ed9efe5d289fcb1e9eaacde8a..1c8c2874f29d3236f85d073c74f8934e94d7e86b 100644 (file)
@@ -11,60 +11,91 @@ Distributed unter the GPL
 #include <list>
 #include <map>
 #include <pcap.h>
+#include <netinet/ether.h>
+#include <netinet/icmp6.h>
+#include <netinet/ip.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/ip6.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
 #include <msp/core/application.h>
 #include <msp/debug/profiler.h>
-#include <msp/gbase/display.h>
-#include <msp/gbase/glcontext.h>
-#include <msp/gbase/window.h>
+#include <msp/graphics/display.h>
+#include <msp/graphics/glcontext.h>
+#include <msp/graphics/simplewindow.h>
 #include <msp/gl/color.h>
 #include <msp/gl/font.h>
 #include <msp/time/timestamp.h>
+#include "address.h"
 
+class History;
 class Host;
 class Packet;
+class Port;
 class Resolver;
 
-class NetVis: public Msp::Application
+class NetVis: public Msp::RegisteredApplication<NetVis>
 {
 private:
+       struct CaptureContext
+       {
+               const pcap_pkthdr *cap_hdr;
+               Host *src_host;
+               Port *src_port;
+               Host *dst_host;
+               Port *dst_port;
+               unsigned size;
+
+               CaptureContext();
+       };
+
        std::string iface;
        pcap_t *pcap;
+       Resolver *resolver;
+       std::list<Address> localnets;
+
+       Msp::Graphics::SimpleGLWindow *wnd;
+       Msp::GL::Font *font;
+
+       unsigned max_hosts;
+       unsigned max_visible_hosts;
+       std::map<Address, Host *> hosts;
+       std::map<Address, Host *> disabled_hosts;
        std::list<Packet *> packets;
-       std::map<unsigned, Host *> hosts;
-       std::map<unsigned, Host *> disabled_hosts;
-       Msp::Graphics::Display *dpy;
-       Msp::Graphics::Window *wnd;
-       Msp::Graphics::GLContext *glc;
+       std::map<unsigned, Port *> ports;
+       History *history;
+
        Msp::Time::TimeStamp tick_t;
-       std::map<unsigned, Msp::GL::Color> port_colors;
-       Msp::GL::Font *font;
-       Msp::GL::Texture2D *font_tex;
-       Msp::Debug::Profiler profiler;
-       bool draw_labels;
-       bool blend;
-       Resolver *resolver;
-       unsigned localnet;
-       unsigned localnet_mask;
        Msp::Time::TimeStamp fps_t;
        unsigned frames;
        float fps;
 
 public:
        NetVis(int, char **);
-       int main();
+       ~NetVis();
+
        const Msp::GL::Font &get_font() const { return *font; }
-       const std::map<unsigned, Host *> &get_hosts() const { return hosts; }
+       const std::map<Address, Host *> &get_hosts() const { return hosts; }
+       const std::map<unsigned, Port *> &get_ports() const { return ports; }
 private:
        virtual void tick();
-       Host &get_host(unsigned);
-       Msp::GL::Color &get_port_color(unsigned);
-       void key_press(unsigned, unsigned, wchar_t);
+       void render();
+       Host &get_host(const Address &);
+       Msp::GL::Color generate_color(bool) const;
+       Port &get_port(unsigned);
+       void create_history_texture();
 
        static void capture_handler(unsigned char *, const pcap_pkthdr *, const unsigned char *);
+       void handle_ethernet(CaptureContext &, const ethhdr *, unsigned);
+       void handle_ipv4(CaptureContext &, const iphdr *, unsigned);
+       void handle_ipv6(CaptureContext &, const ip6_hdr *, unsigned);
+       void handle_tcp(CaptureContext &, const tcphdr *, unsigned);
+       void handle_udp(CaptureContext &, const udphdr *, unsigned);
+       void handle_icmp(CaptureContext &, const icmphdr *, unsigned);
+       void handle_icmp6(CaptureContext &, const icmp6_hdr *, unsigned);
+       void handle_packet(CaptureContext &);
 
        void sighandler(int);
-
-       static Application::RegApp<NetVis> reg;
 };
 
 #endif