]> git.tdb.fi Git - netvis.git/blob - source/netvis.h
Handle ICMP packets
[netvis.git] / source / netvis.h
1 /* $Id$
2
3 This file is part of NetVis
4 Copyright @ 2008 Mikko Rasa, Mikkosoft Productions
5 Distributed unter the GPL
6 */
7
8 #ifndef NETVIS_H_
9 #define NETVIS_H_
10
11 #include <list>
12 #include <map>
13 #include <pcap.h>
14 #include <netinet/ether.h>
15 #include <netinet/icmp6.h>
16 #include <netinet/ip.h>
17 #include <netinet/ip_icmp.h>
18 #include <netinet/ip6.h>
19 #include <netinet/tcp.h>
20 #include <netinet/udp.h>
21 #include <msp/core/application.h>
22 #include <msp/debug/profiler.h>
23 #include <msp/graphics/display.h>
24 #include <msp/graphics/glcontext.h>
25 #include <msp/graphics/simplewindow.h>
26 #include <msp/gl/color.h>
27 #include <msp/gl/font.h>
28 #include <msp/time/timestamp.h>
29 #include "address.h"
30
31 class History;
32 class Host;
33 class Packet;
34 class Port;
35 class Resolver;
36
37 class NetVis: public Msp::RegisteredApplication<NetVis>
38 {
39 private:
40         struct CaptureContext
41         {
42                 const pcap_pkthdr *cap_hdr;
43                 Host *src_host;
44                 Port *src_port;
45                 Host *dst_host;
46                 Port *dst_port;
47                 unsigned size;
48
49                 CaptureContext();
50         };
51
52         std::string iface;
53         pcap_t *pcap;
54         Resolver *resolver;
55         std::list<Address> localnets;
56
57         Msp::Graphics::SimpleGLWindow *wnd;
58         Msp::GL::Font *font;
59
60         unsigned max_hosts;
61         unsigned max_visible_hosts;
62         std::map<Address, Host *> hosts;
63         std::map<Address, Host *> disabled_hosts;
64         std::list<Packet *> packets;
65         std::map<unsigned, Port *> ports;
66         History *history;
67
68         Msp::Time::TimeStamp tick_t;
69         Msp::Time::TimeStamp fps_t;
70         unsigned frames;
71         float fps;
72
73 public:
74         NetVis(int, char **);
75         ~NetVis();
76
77         const Msp::GL::Font &get_font() const { return *font; }
78         const std::map<Address, Host *> &get_hosts() const { return hosts; }
79         const std::map<unsigned, Port *> &get_ports() const { return ports; }
80 private:
81         virtual void tick();
82         void render();
83         Host &get_host(const Address &);
84         Msp::GL::Color generate_color(bool) const;
85         Port &get_port(unsigned);
86         void create_history_texture();
87
88         static void capture_handler(unsigned char *, const pcap_pkthdr *, const unsigned char *);
89         void handle_ethernet(CaptureContext &, const ethhdr *, unsigned);
90         void handle_ipv4(CaptureContext &, const iphdr *, unsigned);
91         void handle_ipv6(CaptureContext &, const ip6_hdr *, unsigned);
92         void handle_tcp(CaptureContext &, const tcphdr *, unsigned);
93         void handle_udp(CaptureContext &, const udphdr *, unsigned);
94         void handle_icmp(CaptureContext &, const icmphdr *, unsigned);
95         void handle_icmp6(CaptureContext &, const icmp6_hdr *, unsigned);
96         void handle_packet(CaptureContext &);
97
98         void sighandler(int);
99 };
100
101 #endif