#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
-#include <msp/core/except.h>
+#include <msp/core/getopt.h>
#include <msp/debug/profilingscope.h>
#include <msp/gl/blend.h>
#include <msp/gl/framebuffer.h>
#include <msp/gl/projection.h>
#include <msp/gl/texture2d.h>
#include <msp/gl/transform.h>
-#include <msp/strings/formatter.h>
+#include <msp/strings/format.h>
#include <msp/time/units.h>
#include <msp/time/utils.h>
#include "history.h"
frames(0)
{
if(argc<2)
- throw UsageError("No interface given");
+ throw usage_error("No interface given");
iface = argv[1];
char err[1024];
pcap = pcap_open_live(iface.c_str(), 128, true, 0, err);
if(!pcap)
- throw Exception(err);
+ throw runtime_error(err);
if(pcap_setnonblock(pcap, true, err)==-1)
- throw Exception(err);
+ throw runtime_error(err);
pcap_lookupnet(iface.c_str(), &localnet, &localnet_mask, err);
localnet = ntohl(localnet);
wnd->signal_close.connect(sigc::bind(sigc::mem_fun(this, &NetVis::exit), 0));
wnd->show();
- GL::enable(GL::BLEND);
- GL::blend_func(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA);
+ GL::Blend::alpha().bind();
font = new GL::Font;
DataFile::load(*font, "dejavu-10.font");
NetVis::~NetVis()
{
+ delete history;
delete resolver;
delete font;
i->second->tick(dt);
min_activity = min(min_activity, i->second->get_activity());
}
- float del_limit = pow(10, 6-0.1*(max_hosts-hosts.size()-disabled_hosts.size()));
+ float del_limit = pow(10, 6-0.1*static_cast<int>(max_hosts-hosts.size()-disabled_hosts.size()));
for(map<unsigned, Host *>::iterator i=disabled_hosts.begin(); i!=disabled_hosts.end();)
{
i->second->tick(dt);
}
}
+ for(map<unsigned, Port *>::iterator i=ports.begin(); i!=ports.end();)
+ {
+ i->second->tick(dt);
+
+ if(!i->second->is_registered() && i->second->get_activity()<0.1)
+ {
+ delete i->second;
+ ports.erase(i++);
+ }
+ else
+ ++i;
+ }
+
for(list<Packet *>::iterator i=packets.begin(); i!=packets.end();)
{
(*i)->tick(dt);
void NetVis::render()
{
- GL::clear(GL::COLOR_BUFFER_BIT);
+ GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT);
- GL::matrix_mode(GL::PROJECTION);
- GL::load_identity();
- GL::ortho_centered(1024, 768);
- GL::matrix_mode(GL::MODELVIEW);
- GL::load_identity();
+ GL::MatrixStack::projection() = GL::Matrix::ortho_centered(1024, 768);
+ GL::MatrixStack::modelview() = GL::Matrix();
for(map<unsigned, Host *>::iterator i=hosts.begin(); i!=hosts.end(); ++i)
i->second->render();
imm.end();
}
- GL::push_matrix();
- GL::translate(-500, 360, 0);
+ GL::MatrixStack::modelview() = GL::Matrix::translation(-500, 360, 0);
unsigned n = 0;
- for(map<unsigned, Port *>::iterator i=ports.begin(); (i!=ports.end() && n<50); ++i, ++n)
+ for(map<unsigned, Port *>::iterator i=ports.begin(); (i!=ports.end() && n<50); ++i)
{
- i->second->render();
- GL::translate(0, -12, 0);
+ float act = i->second->get_activity();
+ if((i->second->is_registered() && act>1) || act>200)
+ {
+ i->second->render();
+ GL::MatrixStack::modelview() *= GL::Matrix::translation(0, -12, 0);
+ ++n;
+ }
}
- GL::pop_matrix();
- GL::push_matrix();
- GL::translate(-500, -360, 0);
- GL::scale_uniform(10);
+ GL::MatrixStack::modelview() = GL::Matrix::translation(-500, -348, 0);
+ GL::MatrixStack::modelview() *= GL::Matrix::scaling(10);
font->draw_string(format("%d hosts", hosts.size()+disabled_hosts.size()));
- GL::translate(0, -1.2, 0);
+ GL::MatrixStack::modelview() *= GL::Matrix::translation(0, -1.2, 0);
+ font->draw_string(format("%d ports", ports.size()));
+ GL::MatrixStack::modelview() *= GL::Matrix::translation(0, -1.2, 0);
font->draw_string(format("%.2f fps", fps));
GL::Texture::unbind();
- GL::pop_matrix();
- GL::push_matrix();
- GL::translate(170, -370, 0);
+ GL::MatrixStack::modelview() = GL::Matrix::translation(170, -370, 0);
history->render();
- GL::pop_matrix();
}
Host &NetVis::get_host(unsigned a)
return *host;
}
-const Port &NetVis::get_port(unsigned number)
+Port &NetVis::get_port(unsigned number)
{
map<unsigned, Port *>::iterator i = ports.find(number);
if(i!=ports.end())
const iphdr *ip = reinterpret_cast<const iphdr *>(eth+1);
unsigned size = ntohs(ip->tot_len);
- unsigned port = 0;
+
+ Port *sport = 0;
+ Port *dport = 0;
if(ip->protocol==IPPROTO_TCP)
{
const tcphdr *tcp = reinterpret_cast<const tcphdr *>(ip+1);
- port = min(ntohs(tcp->source), ntohs(tcp->dest));
+ sport = &self->get_port(ntohs(tcp->source));
+ dport = &self->get_port(ntohs(tcp->dest));
}
else if(ip->protocol==IPPROTO_UDP)
{
const udphdr *udp = reinterpret_cast<const udphdr *>(ip+1);
- port = min(ntohs(udp->source), ntohs(udp->dest));
+ sport = &self->get_port(ntohs(udp->source));
+ dport = &self->get_port(ntohs(udp->dest));
+ }
+
+ Port *port = 0;
+ if(sport && dport)
+ {
+ if(sport->is_registered()!=dport->is_registered())
+ {
+ if(sport->is_registered())
+ port = sport;
+ else
+ port = dport;
+ }
+ else if(sport->get_number()<dport->get_number())
+ port = sport;
+ else
+ port = dport;
}
+ else
+ port = &self->get_port(0);
+
Host &shost = self->get_host(ntohl(ip->saddr));
Host *dhost = 0;
if((ntohl(ip->daddr)&0xFF)!=0xFF)
float throttle = shost.send_packet();
if(throttle<1)
{
- self->packets.push_back(new Packet(shost, dhost, self->get_port(port).get_color(), size));
+ self->packets.push_back(new Packet(shost, dhost, port->get_color(), size));
self->packets.back()->tick(-throttle*Msp::Time::sec);
}
if(dhost)
dhost->add_activity(size);
+ if(sport)
+ sport->add_activity(size);
+ if(dport)
+ dport->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)
{
exit(0);
}
-
-Application::RegApp<NetVis> NetVis::reg;