]> git.tdb.fi Git - netvis.git/blobdiff - source/netvis.cpp
Add a traffic history graph
[netvis.git] / source / netvis.cpp
index fb02c0dde99d13828a35d07c38e5b5ecf6c8bd9f..ff05507a2fc04364d31d1814037b9c247b1bdbbe 100644 (file)
@@ -9,10 +9,10 @@ Distributed unter the GPL
 #include <cstdlib>
 #include <cmath>
 #include <signal.h>
+#include <netinet/ether.h>
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
 #include <netinet/udp.h>
-#include <linux/if_ether.h>
 #include <msp/core/except.h>
 #include <msp/debug/profilingscope.h>
 #include <msp/gl/blend.h>
@@ -26,6 +26,7 @@ Distributed unter the GPL
 #include <msp/strings/formatter.h>
 #include <msp/time/units.h>
 #include <msp/time/utils.h>
+#include "history.h"
 #include "host.h"
 #include "netvis.h"
 #include "packet.h"
@@ -73,6 +74,8 @@ NetVis::NetVis(int argc, char **argv):
        font = new GL::Font;
        DataFile::load(*font, "dejavu-10.font");
 
+       history = new History(*this, 301, 100);
+
        catch_signal(SIGINT);
 }
 
@@ -114,6 +117,8 @@ void NetVis::tick()
        while(pcap_dispatch(pcap, -1, &capture_handler, reinterpret_cast<unsigned char *>(this))>0) ;
 
        resolver->tick();
+       history->tick(tick_t);
+
 
        float min_activity = numeric_limits<float>::max();
        for(map<unsigned, Host *>::iterator i=hosts.begin(); i!=hosts.end(); ++i)
@@ -221,6 +226,11 @@ void NetVis::render()
        font->draw_string(format("%.2f fps", fps));
        GL::Texture::unbind();
        GL::pop_matrix();
+
+       GL::push_matrix();
+       GL::translate(170, -370, 0);
+       history->render();
+       GL::pop_matrix();
 }
 
 Host &NetVis::get_host(unsigned a)
@@ -288,6 +298,11 @@ void NetVis::capture_handler(unsigned char *user, const pcap_pkthdr *, const uns
                shost.add_activity(size);
                if(dhost)
                        dhost->add_activity(size);
+
+               if((ntohl(ip->saddr)&self->localnet_mask)==self->localnet)
+                       self->history->activity(0, size);
+               else if((ntohl(ip->daddr)&self->localnet_mask)==self->localnet)
+                       self->history->activity(size, 0);
        }
 }