My Project
Public Slots | Signals | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Sniffer Class Reference

The Sniffer class is the one that use the pcap library to extract the packet information. It discards any packet that is not Ethernet->IP->(TCP|UDP), and pass up to the GUI the packets that are Ethernet->IP->(TCP|UDP). More...

#include <sniffer.h>

Inheritance diagram for Sniffer:

Public Slots

void process ()
 The sniffer is run as a separate thread and the function process is the main function of the thread. It is the sniffer.
 

Signals

void resultReady (unsigned long index)
 

Public Member Functions

 Sniffer ()
 Constructor, does nothing.
 
 Sniffer (QWaitCondition *pw, QMutex *mx, int *ps)
 Sets the mutexes for the inter communication between the sniffer and the GUI. More...
 
 ~Sniffer ()
 Destructor, does nothing.
 
vector< ip_packet > * getPacketList ()
 Returns the packet list that contains the packets that are Ethernet -> IP -> (TCP|UDP) More...
 
string format_payload (const char *payload, int len)
 Formats the payload from a byte stream into a string of ascci. More...
 
string format_hex_ascii_line (const char *payload, int len, int offset)
 Return string with the bytes of a payload line in ascii. More...
 
void find_devices (vector< string > &)
 Find the network devices in the computer, and store them in vector devs. More...
 
void setDevice (string)
 Sets the device to capture packets to dev. More...
 

Private Member Functions

void print_payload (const u_char *payload, int len)
 Prints the payload in ascii. More...
 
void print_hex_ascii_line (const u_char *payload, int len, int offset)
 Prints to std output the a payload in ascii. More...
 
void got_packet (const struct pcap_pkthdr *header, const u_char *packet)
 Disects the received packet. Takes out the info needed. More...
 

Private Attributes

vector< ip_packetpacket_list
 
QWaitCondition * wait_pause
 
QMutex * mutex
 
string device
 
string filter
 
int * pause
 

Detailed Description

The Sniffer class is the one that use the pcap library to extract the packet information. It discards any packet that is not Ethernet->IP->(TCP|UDP), and pass up to the GUI the packets that are Ethernet->IP->(TCP|UDP).

Constructor & Destructor Documentation

Sniffer::Sniffer ( QWaitCondition *  pw,
QMutex *  mx,
int *  ps 
)

Sets the mutexes for the inter communication between the sniffer and the GUI.

Parameters
pwused to pause the capture of packets
mxused to protect critical region
psflag to pause the packet capture

Member Function Documentation

void Sniffer::find_devices ( vector< string > &  devs)

Find the network devices in the computer, and store them in vector devs.

Parameters
devsvector of string for device names
string Sniffer::format_hex_ascii_line ( const char *  payload,
int  len,
int  offset 
)

Return string with the bytes of a payload line in ascii.

Parameters
payloadpayload of the packet
lenlength of the packet
offsetoffset of packet
Returns
a string with the bytes of a payload line in ascii
string Sniffer::format_payload ( const char *  payload,
int  len 
)

Formats the payload from a byte stream into a string of ascci.

Parameters
payloadpayload of the packet
lenlength of the packet
Returns
the payload in a string of ascii
vector< ip_packet > * Sniffer::getPacketList ( )

Returns the packet list that contains the packets that are Ethernet -> IP -> (TCP|UDP)

Returns
vector of packets
void Sniffer::got_packet ( const struct pcap_pkthdr *  header,
const u_char *  packet 
)
private

Disects the received packet. Takes out the info needed.

Parameters
pcap_pkthdrheader of the pcap packet
packetrecieved packet
void Sniffer::print_hex_ascii_line ( const u_char *  payload,
int  len,
int  offset 
)
private

Prints to std output the a payload in ascii.

Parameters
payloadpayload of the packet
lenlength of the packet
offsetoffset
void Sniffer::print_payload ( const u_char *  payload,
int  len 
)
private

Prints the payload in ascii.

Parameters
payloadpayload of the packet
lenpayload length
void Sniffer::setDevice ( string  dev)

Sets the device to capture packets to dev.

Parameters
devname of the device

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