network::NetSniff Class Reference

Network sniffing class. More...

#include <NetSniff.h>

Collaboration diagram for network::NetSniff:

Collaboration graph
[legend]

List of all members.

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
Debugdbg
 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.
SIPPacketsipp
 SIP packets.
PacketHandler pkghand
 Packet Handler.


Detailed Description

Network sniffing class.

This class takes care of sniffing, displaying and storing network traffic through pcap library

Definition at line 35 of file NetSniff.h.


Constructor & Destructor Documentation

network::NetSniff::NetSniff ( string  device,
string  sniffport,
string  sniffproto 
)

NetSniff default constructor.

Parameters:
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]

NetSniff default destructor.

Definition at line 432 of file NetSniff.cc.

References fp, sniff, and sniffed.


Member Function Documentation

bool network::NetSniff::ApplyFilter ( const char *  filter  ) 

Compile a pcap filter.

Parameters:
filter String containing BPF filter
Return values:
true Filter applied
false Error applying filter

Definition at line 348 of file NetSniff.cc.

References BPFfilter, dbg, dbgbuffer, dev, fp, mask, port, ready, snfproto, and sniff.

string network::NetSniff::GetFullStatus (  ) 

Get a string detailing sniffer status.

Return values:
string string containing full sniffer status

Definition at line 393 of file NetSniff.cc.

References BPFfilter, dbgbuffer, dev, displayed, file, port, snfcap, snfproto, snfshow, sniffed, and stored.

string network::NetSniff::HWAddress ( u_char *  ptr  )  [private]

Returns hardware adress string.

Parameters:
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.

Return values:
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.

Return values:
true sniffing
false not sniffing

Definition at line 427 of file NetSniff.cc.

References dosniff.

bool network::NetSniff::Open (  ) 

Open capture interface using pcap.

Return values:
true Capture interface opened
false Error opening capture interface

Definition at line 63 of file NetSniff.cc.

References dbg, dbgbuffer, dev, ip, mask, pkghand, ready, network::PacketHandler::SetDebugger(), and sniff.

void network::NetSniff::PrintPacket ( const u_char *  data,
const struct pcap_pkthdr *  h 
) [private]

void network::NetSniff::SetCapture ( bool  option,
string  captpath 
)

Sets pcap file capture path.

Parameters:
option set cature true or false
captpath full path to capture file

void network::NetSniff::setDebugger ( Debug dbg  ) 

Setup debugger for sniffer.

Parameters:
dbg Debugger instance for NetSniff

void network::NetSniff::SetShow ( bool  option  ) 

Defines if we have to display network traffic.

Parameters:
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 (  ) 

Stop sniffing process.

Definition at line 155 of file NetSniff.cc.

References dbg, and dosniff.


Member Data Documentation

char network::NetSniff::BPFfilter[2048] [protected]

pcap BPF filter

Definition at line 104 of file NetSniff.h.

Referenced by ApplyFilter(), and GetFullStatus().

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]

Defines if we must print debug information.

Definition at line 175 of file NetSniff.h.

char network::NetSniff::dev[32] [protected]

Ethernet device.

Definition at line 100 of file NetSniff.h.

Referenced by ApplyFilter(), GetFullStatus(), and Open().

Displayed packets.

Definition at line 114 of file NetSniff.h.

Referenced by GetFullStatus(), PrintPacket(), and startsniff().

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]

Header.

Definition at line 110 of file NetSniff.h.

bpf_u_int32 network::NetSniff::ip [protected]

Our IP address.

Definition at line 122 of file NetSniff.h.

Referenced by Open().

bpf_u_int32 network::NetSniff::mask [protected]

Our mask.

Definition at line 124 of file NetSniff.h.

Referenced by ApplyFilter(), and Open().

Packet Handler.

Definition at line 195 of file NetSniff.h.

Referenced by Open(), and PrintPacket().

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().

SIP packets.

Definition at line 193 of file NetSniff.h.

Referenced by PrintPacket().

bool network::NetSniff::snfcap [private]

Store traffic to a pcap file.

Definition at line 179 of file NetSniff.h.

Referenced by GetFullStatus(), and startsniff().

pcap file path

Definition at line 181 of file NetSniff.h.

Referenced by startsniff().

char network::NetSniff::snfproto[5] [protected]

Sniffing protocol.

Definition at line 108 of file NetSniff.h.

Referenced by ApplyFilter(), and GetFullStatus().

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]

Search string.

Definition at line 102 of file NetSniff.h.

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().


The documentation for this class was generated from the following files:

VoipHoney is proudly sponsored by OpenVoIP

This documentation has been generated using doxygen 1.5.8