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