* when a packet's owner cannot be found (for example if it has already disappeared,

which can happen with for example small fast HTTP requests), show the source and
  destination ports and ip's
* support UDP packets (which never have owners)
* nicely truncate oversized program names
This commit is contained in:
Arnout Engelen
2005-08-27 11:49:16 +00:00
parent c4ac4e55eb
commit 4182fc0b17
5 changed files with 138 additions and 30 deletions

View File

@@ -14,6 +14,7 @@
#include <netinet/ip.h>
#include <netinet/ip6.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include "cui.h"
@@ -26,6 +27,8 @@ extern "C" {
#include "process.h"
#include "refresh.h"
extern Process * unknownudp;
unsigned refreshdelay = 1;
bool tracemode = false;
bool needrefresh = true;
@@ -124,6 +127,51 @@ int process_tcp (u_char * userdata, const dp_header * header, const u_char * m_p
return true;
}
int process_udp (u_char * userdata, const dp_header * header, const u_char * m_packet) {
struct dpargs * args = (struct dpargs *) userdata;
//struct tcphdr * tcp = (struct tcphdr *) m_packet;
struct udphdr * udp = (struct udphdr *) m_packet;
curtime = header->ts;
/* TODO get info from userdata, then call getPacket */
Packet * packet;
switch (args->sa_family)
{
case (AF_INET):
packet = new Packet (args->ip_src, ntohs(udp->source), args->ip_dst, ntohs(udp->dest), header->len, header->ts);
break;
case (AF_INET6):
packet = new Packet (args->ip6_src, ntohs(udp->source), args->ip6_dst, ntohs(udp->dest), header->len, header->ts);
break;
}
//if (DEBUG)
// std::cout << "Got packet from " << packet->gethashstring() << std::endl;
Connection * connection = findConnection(packet);
if (connection != NULL)
{
/* add packet to the connection */
connection->add(packet);
} else {
/* else: unknown connection, create new */
connection = new Connection (packet);
getProcess(connection, currentdevice);
}
delete packet;
if (needrefresh)
{
do_refresh();
needrefresh = false;
}
/* we're done now. */
return true;
}
int process_ip (u_char * userdata, const dp_header * header, const u_char * m_packet) {
struct dpargs * args = (struct dpargs *) userdata;
struct ip * ip = (struct ip *) m_packet;
@@ -275,6 +323,7 @@ int main (int argc, char** argv)
dp_addcb (newhandle, dp_packet_ip, process_ip);
dp_addcb (newhandle, dp_packet_ip6, process_ip6);
dp_addcb (newhandle, dp_packet_tcp, process_tcp);
dp_addcb (newhandle, dp_packet_tcp, process_udp);
if (newhandle != NULL)
{
/* The following code solves sf.net bug 1019381, but is only available