#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>
#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"
font(0),
max_hosts(1000),
max_visible_hosts(30),
- draw_labels(true),
- blend(true),
frames(0)
{
if(argc<2)
wnd = new Graphics::SimpleGLWindow(1024, 768);
wnd->set_title("NetVis");
wnd->signal_close.connect(sigc::bind(sigc::mem_fun(this, &NetVis::exit), 0));
- wnd->signal_key_press.connect(sigc::mem_fun(this, &NetVis::key_press));
wnd->show();
GL::enable(GL::BLEND);
font = new GL::Font;
DataFile::load(*font, "dejavu-10.font");
+ history = new History(*this, 301, 100);
+
catch_signal(SIGINT);
}
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)
{
i->second->set_active(true);
hosts.insert(*i);
+ for(unsigned j=0; j<100; ++j)
+ i->second->tick(100*Time::msec);
disabled_hosts.erase(i++);
}
else if(i->second->get_activity()<del_limit)
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)
host->set_local(true);
resolver->push(host);
host->set_position(Vector2(rand()*400.0/RAND_MAX-200.0, rand()*400.0/RAND_MAX-200.0));
+ for(unsigned j=0; j<100; ++j)
+ host->tick(100*Time::msec);
hosts[a] = host;
return *host;
}
return *port;
}
-void NetVis::key_press(unsigned key, unsigned, wchar_t)
-{
- if(key==46)
- draw_labels = !draw_labels;
- else if(key==56)
- {
- blend = !blend;
- GL::set(GL_BLEND, blend);
- }
-}
-
void NetVis::capture_handler(unsigned char *user, const pcap_pkthdr *, const unsigned char *data)
{
NetVis *self = reinterpret_cast<NetVis *>(user);
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);
}
}