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