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_packet > | packet_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

  pw | used to pause the capture of packets
  mx | used to protect critical region
  ps | flag 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

  devs | vector 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

  payload | payload of the packet
  len | length of the packet
  offset | offset 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

  payload | payload of the packet
  len | length 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_pkthdr | header of the pcap packet
  packet | recieved 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

  payload | payload of the packet
  len | length of the packet
  offset | offset

void Sniffer::print_payload | ( | const u_char * | payload,
|  | int | len
| ) |  |

private

Prints the payload in ascii.

Parameters

  payload | payload of the packet
  len | payload length

void Sniffer::setDevice | ( | string | dev | ) |

Sets the device to capture packets to dev.

Parameters

  dev | name of the device

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

- sniffer.h
- sniffer.cpp