#include <NetSniff.h>
Classes | |
struct | iphdr |
IP header. More... | |
Public Member Functions | |
NetSniff (string device, string sniffport, string sniffproto) | |
NetSniff default constructor. | |
virtual | ~NetSniff () |
NetSniff default destructor. | |
bool | isReady () |
Defines if the Device is ready for sniffing. | |
bool | Open () |
Open capture interface using pcap. | |
bool | ApplyFilter (const char *filter) |
Compile a pcap filter. | |
void | startsniff () |
Start sniffing process (must be started as a non-blocking thread). | |
void | stopsniff () |
Stop sniffing process. | |
void | setDebugger (Debug *dbg) |
Setup debugger for sniffer. | |
bool | isSniffing () |
Defines if we are sniffing or not. | |
void | SetShow (bool option) |
Defines if we have to display network traffic. | |
void | SetCapture (bool option, string captpath) |
Sets pcap file capture path. | |
string | GetFullStatus () |
Get a string detailing sniffer status. | |
Protected Attributes | |
char | dev [32] |
Ethernet device. | |
char | sstr [2048] |
Search string. | |
char | BPFfilter [2048] |
pcap BPF filter | |
char | port [5] |
Sniffing port. | |
char | snfproto [5] |
Sniffing protocol. | |
char | header [128] |
Header. | |
int | sniffed |
Number of packets sniffed. | |
int | displayed |
Displayed packets. | |
int | stored |
Number of Packets stored in this file. | |
pcap_t * | sniff |
Sniffing handler. | |
struct bpf_program | fp |
BPF (BSD Packet filter). | |
bpf_u_int32 | ip |
Our IP address. | |
bpf_u_int32 | mask |
Our mask. | |
Private Member Functions | |
string | HWAddress (u_char *ptr) |
Returns hardware adress string. | |
void | PrintPacket (const u_char *data, const struct pcap_pkthdr *h) |
Print contents of a network package. | |
Private Attributes | |
bool | ready |
Defines if the device is open and ready. | |
bool | dosniff |
defines if we must continue sniffing | |
Debug * | dbg |
Our debugger. | |
bool | debug |
Defines if we must print debug information. | |
bool | snfshow |
Display captured traffic or not. | |
bool | snfcap |
Store traffic to a pcap file. | |
string | snfcappath |
pcap file path | |
string | file |
pcap file name | |
ostringstream | dbgbuffer |
For handling errors and debugging. | |
SIPPacket * | sipp |
SIP packets. | |
PacketHandler | pkghand |
Packet Handler. |
This class takes care of sniffing, displaying and storing network traffic through pcap library
Definition at line 35 of file NetSniff.h.
network::NetSniff::NetSniff | ( | string | device, | |
string | sniffport, | |||
string | sniffproto | |||
) |
NetSniff default constructor.
device | Network device Unix name (i.e. eth0) | |
sniffport | Port to use for listening (i.e. 5060) | |
sniffproto | Protocol to use for sniffing (i.e. UDP) |
network::NetSniff::~NetSniff | ( | ) | [virtual] |
bool network::NetSniff::ApplyFilter | ( | const char * | filter | ) |
string network::NetSniff::GetFullStatus | ( | ) |
string network::NetSniff::HWAddress | ( | u_char * | ptr | ) | [private] |
Returns hardware adress string.
ptr | Pcap pointer contaning encoded Hardware Address |
Definition at line 332 of file NetSniff.cc.
Referenced by PrintPacket().
bool network::NetSniff::isReady | ( | ) |
Defines if the Device is ready for sniffing.
true | Device is ready | |
false | Device is not ready |
Definition at line 98 of file NetSniff.cc.
References ready.
bool network::NetSniff::isSniffing | ( | ) |
Defines if we are sniffing or not.
true | sniffing | |
false | not sniffing |
Definition at line 427 of file NetSniff.cc.
References dosniff.
bool network::NetSniff::Open | ( | ) |
void network::NetSniff::PrintPacket | ( | const u_char * | data, | |
const struct pcap_pkthdr * | h | |||
) | [private] |
Print contents of a network package.
data | Packet data in pcap format | |
h | Packet header in pcap format |
Definition at line 161 of file NetSniff.cc.
References dbg, dbgbuffer, displayed, network::PacketHandler::HandlePacket(), HWAddress(), network::NetSniff::NetSniff::iphdr::ip_dst1, network::NetSniff::NetSniff::iphdr::ip_dst2, network::NetSniff::NetSniff::iphdr::ip_dst3, network::NetSniff::NetSniff::iphdr::ip_dst4, network::NetSniff::NetSniff::iphdr::ip_p, network::NetSniff::NetSniff::iphdr::ip_src1, network::NetSniff::NetSniff::iphdr::ip_src2, network::NetSniff::NetSniff::iphdr::ip_src3, network::NetSniff::NetSniff::iphdr::ip_src4, network::NetSniff::NetSniff::iphdr::ip_ttl, pkghand, network::NetPacket::SetHeadder(), and sipp.
Referenced by startsniff().
void network::NetSniff::SetCapture | ( | bool | option, | |
string | captpath | |||
) |
Sets pcap file capture path.
option | set cature true or false | |
captpath | full path to capture file |
void network::NetSniff::setDebugger | ( | Debug * | dbg | ) |
void network::NetSniff::SetShow | ( | bool | option | ) |
Defines if we have to display network traffic.
option | show traffic true or false |
Definition at line 51 of file NetSniff.cc.
References snfshow.
void network::NetSniff::startsniff | ( | ) |
Start sniffing process (must be started as a non-blocking thread).
Definition at line 103 of file NetSniff.cc.
References dbg, dbgbuffer, displayed, dosniff, file, PrintPacket(), snfcap, snfcappath, snfshow, sniff, sniffed, and stored.
Referenced by main().
void network::NetSniff::stopsniff | ( | ) |
char network::NetSniff::BPFfilter[2048] [protected] |
pcap BPF filter
Definition at line 104 of file NetSniff.h.
Referenced by ApplyFilter(), and GetFullStatus().
Debug* network::NetSniff::dbg [private] |
Our debugger.
Definition at line 173 of file NetSniff.h.
Referenced by ApplyFilter(), Open(), PrintPacket(), startsniff(), and stopsniff().
ostringstream network::NetSniff::dbgbuffer [private] |
For handling errors and debugging.
Definition at line 185 of file NetSniff.h.
Referenced by ApplyFilter(), GetFullStatus(), Open(), PrintPacket(), and startsniff().
bool network::NetSniff::debug [private] |
char network::NetSniff::dev[32] [protected] |
Ethernet device.
Definition at line 100 of file NetSniff.h.
Referenced by ApplyFilter(), GetFullStatus(), and Open().
int network::NetSniff::displayed [protected] |
Displayed packets.
Definition at line 114 of file NetSniff.h.
Referenced by GetFullStatus(), PrintPacket(), and startsniff().
bool network::NetSniff::dosniff [private] |
defines if we must continue sniffing
Definition at line 171 of file NetSniff.h.
Referenced by isSniffing(), startsniff(), and stopsniff().
string network::NetSniff::file [private] |
pcap file name
Definition at line 183 of file NetSniff.h.
Referenced by GetFullStatus(), and startsniff().
struct bpf_program network::NetSniff::fp [read, protected] |
BPF (BSD Packet filter).
Definition at line 120 of file NetSniff.h.
Referenced by ApplyFilter(), and ~NetSniff().
char network::NetSniff::header[128] [protected] |
bpf_u_int32 network::NetSniff::ip [protected] |
bpf_u_int32 network::NetSniff::mask [protected] |
PacketHandler network::NetSniff::pkghand [private] |
char network::NetSniff::port[5] [protected] |
Sniffing port.
Definition at line 106 of file NetSniff.h.
Referenced by ApplyFilter(), and GetFullStatus().
bool network::NetSniff::ready [private] |
Defines if the device is open and ready.
Definition at line 127 of file NetSniff.h.
Referenced by ApplyFilter(), isReady(), and Open().
SIPPacket* network::NetSniff::sipp [private] |
bool network::NetSniff::snfcap [private] |
Store traffic to a pcap file.
Definition at line 179 of file NetSniff.h.
Referenced by GetFullStatus(), and startsniff().
string network::NetSniff::snfcappath [private] |
char network::NetSniff::snfproto[5] [protected] |
Sniffing protocol.
Definition at line 108 of file NetSniff.h.
Referenced by ApplyFilter(), and GetFullStatus().
bool network::NetSniff::snfshow [private] |
Display captured traffic or not.
Definition at line 177 of file NetSniff.h.
Referenced by GetFullStatus(), SetShow(), and startsniff().
pcap_t* network::NetSniff::sniff [protected] |
Sniffing handler.
Definition at line 118 of file NetSniff.h.
Referenced by ApplyFilter(), Open(), startsniff(), and ~NetSniff().
int network::NetSniff::sniffed [protected] |
Number of packets sniffed.
Definition at line 112 of file NetSniff.h.
Referenced by GetFullStatus(), startsniff(), and ~NetSniff().
char network::NetSniff::sstr[2048] [protected] |
int network::NetSniff::stored [protected] |
Number of Packets stored in this file.
Definition at line 116 of file NetSniff.h.
Referenced by GetFullStatus(), and startsniff().