From 2a1e068dee7c3c183f0776b2d6f4d59b9371658c Mon Sep 17 00:00:00 2001 From: PAVAN Date: Fri, 18 May 2018 19:45:07 +0530 Subject: [PATCH] added unknown udp.... --- src/connection.cpp | 77 ++++++++++++++++++++-------------------------- src/decpcap.c | 5 --- src/main.cpp | 7 ++--- 3 files changed, 37 insertions(+), 52 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index 15da6fd..448d4e7 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -155,70 +155,61 @@ void Connection::add(Packet *packet) { Connection *findConnectionWithMatchingSource(Packet *packet, short int packettype) { assert(packet->Outgoing()); + ConnList *current = NULL; switch(packettype) { case IPPROTO_TCP: - { //std::cout<<"hell.......o"<matchSource(current->getVal()->refpacket)) { - return current->getVal(); - } - - current = current->getNext(); - } - return NULL; + { + current = connections; + break; } - break; case IPPROTO_UDP: { - ConnList *current = unknownudp->connections; - while (current != NULL) { - /* the reference packet is always outgoing */ - if (packet->matchSource(current->getVal()->refpacket)) { - return current->getVal(); - } - - current = current->getNext(); - } - return NULL; + current = unknownudp->connections; + break; } - break; } + + while (current != NULL) { + /* the reference packet is always outgoing */ + if (packet->matchSource(current->getVal()->refpacket)) { + return current->getVal(); + } + + current = current->getNext(); + } + + return NULL; } Connection *findConnectionWithMatchingRefpacketOrSource(Packet *packet, short int packettype) { + ConnList *current = NULL; switch(packettype) { case IPPROTO_TCP: - { ConnList *current = connections; - while (current != NULL) { - /* the reference packet is always *outgoing* */ - if (packet->match(current->getVal()->refpacket)) { - return current->getVal(); - } - - current = current->getNext(); - } + { + current = connections; + break; } - break; + case IPPROTO_UDP: - { ConnList *current = unknownudp->connections; - while (current != NULL) { - /* the reference packet is always *outgoing* */ - if (packet->match(current->getVal()->refpacket)) { - return current->getVal(); - } - - current = current->getNext(); - } + { + current = unknownudp->connections; + break; + } - break; + } + + while (current != NULL) { + /* the reference packet is always *outgoing* */ + if (packet->match(current->getVal()->refpacket)) { + return current->getVal(); + } + current = current->getNext(); } return findConnectionWithMatchingSource(packet, packettype); diff --git a/src/decpcap.c b/src/decpcap.c index 73e09ff..72544a9 100644 --- a/src/decpcap.c +++ b/src/decpcap.c @@ -141,8 +141,6 @@ void dp_parse_tcp(struct dp_handle *handle, const dp_header *header, void dp_parse_udp(struct dp_handle *handle, const dp_header *header, const u_char *packet) { - // const struct tcphdr * tcp = (struct tcphdr *) packet; - // u_char * payload = (u_char *) packet + sizeof (struct tcphdr); if (handle->callback[dp_packet_udp] != NULL) { int done = @@ -174,7 +172,6 @@ void dp_parse_ip(struct dp_handle *handle, const dp_header *header, case IPPROTO_UDP: if(catchall) dp_parse_udp(handle, header, payload); - //fprintf(stdout, "udp packet...................\n"); break; default: // TODO: maybe support for non-tcp IP packets @@ -200,7 +197,6 @@ void dp_parse_ip6(struct dp_handle *handle, const dp_header *header, case IPPROTO_UDP: if(catchall) dp_parse_udp(handle, header, payload); - //fprintf(stdout, "udp packet...................\n"); break; default: // TODO: maybe support for non-tcp ipv6 packets @@ -219,7 +215,6 @@ void dp_parse_ethernet(struct dp_handle *handle, const dp_header *header, int done = (handle->callback[dp_packet_ethernet])(handle->userdata, header, packet); - /* return if handle decides we're done */ if (done) return; diff --git a/src/main.cpp b/src/main.cpp index 7b86d1e..0700e16 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,7 @@ static void help(bool iserror) { // output << "usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [-f (eth|ppp))] // [device [device [device ...]]]\n"; output << "usage: nethogs [-V] [-h] [-b] [-d seconds] [-v mode] [-c count] " - "[-t] [-p] [-s] [-a] [-l] [-f filter] [-C catchall]" + "[-t] [-p] [-s] [-a] [-l] [-f filter] [-C]" "[device [device [device ...]]]\n"; output << " -V : prints version.\n"; output << " -h : prints this help.\n"; @@ -44,7 +44,8 @@ static void help(bool iserror) { output << " -s : sort output by sent column.\n"; output << " -l : display command line.\n"; output << " -a : monitor all devices, even loopback/stopped ones.\n"; - output << " -f : EXPERIMENTAL: specify string pcap filter (like tcpdump)." + output << " -C : capture TCP and UDP.\n"; + output << " -f : EXPRIMENTAL: specify string pcap filter (like tcpdump)." " This may be removed or changed in a future version.\n"; output << " device : device(s) to monitor. default is all " "interfaces up and running excluding loopback\n"; @@ -54,7 +55,6 @@ static void help(bool iserror) { output << " s: sort by SENT traffic\n"; output << " r: sort by RECEIVE traffic\n"; output << " l: display command line\n"; - output << " C: capture all packets\n"; output << " m: switch between total (KB, B, MB) and KB/s mode\n"; } @@ -133,7 +133,6 @@ void clean_up() { } int main(int argc, char **argv) { - process_init(); int promisc = 0; bool all = false;