sniffer.h
#ifndef SNIFFER_H
#define SNIFFER_H
#include <QObject>
#include <QString>
#include <QDebug>
#include "ip_packet.h"
#include <QWaitCondition>
#include <QMutex>
#include <pcap.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <cstring>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "ethernet_hdr.h"
#include "ip_hdr.h"
#include "tcp_hdr.h"
#include "udp_hdr.h"
/* default snap length (maximum bytes per packet to capture) */
#define SNAP_LEN 1518
/* ethernet headers are always exactly 14 bytes [1] */
#define SIZE_ETHERNET 14
#define IPV4 8
class Sniffer : public QObject
{
Q_OBJECT
public:
Sniffer() ;
Sniffer(QWaitCondition *pw, QMutex *mx, int *ps) ;
~Sniffer() ;
vector<ip_packet> * getPacketList() ;
string format_payload(const char *payload, int len);
string format_hex_ascii_line(const char *payload, int len, int offset);
void find_devices(vector<string> &) ;
void setDevice(string) ;
public slots:
void process() ;
signals:
void resultReady(unsigned long index);
private:
vector<ip_packet> packet_list ;
QWaitCondition *wait_pause ;
QMutex * mutex ;
string device ;
string filter ;
int *pause ;
void print_payload(const u_char *payload, int len);
void print_hex_ascii_line(const u_char *payload, int len, int offset);
void
got_packet(const struct pcap_pkthdr *header, const u_char *packet);
};
#endif // SNIFFER_H
Sniffer::got_packet
void got_packet(const struct pcap_pkthdr *header, const u_char *packet)
Disects the received packet. Takes out the info needed.
Definition: sniffer.cpp:394
Sniffer::format_payload
string format_payload(const char *payload, int len)
Formats the payload from a byte stream into a string of ascci.
Definition: sniffer.cpp:342
Sniffer::~Sniffer
~Sniffer()
Destructor, does nothing.
Definition: sniffer.cpp:35
Sniffer::process
void process()
The sniffer is run as a separate thread and the function process is the main function of the thread...
Definition: sniffer.cpp:45
Sniffer::print_hex_ascii_line
void print_hex_ascii_line(const u_char *payload, int len, int offset)
Prints to std output the a payload in ascii.
Definition: sniffer.cpp:157
Sniffer::print_payload
void print_payload(const u_char *payload, int len)
Prints the payload in ascii.
Definition: sniffer.cpp:278
Sniffer::setDevice
void setDevice(string)
Sets the device to capture packets to dev.
Definition: sniffer.cpp:561
Sniffer::getPacketList
vector< ip_packet > * getPacketList()
Returns the packet list that contains the packets that are Ethernet -> IP -> (TCP|UDP) ...
Definition: sniffer.cpp:520
Sniffer::find_devices
void find_devices(vector< string > &)
Find the network devices in the computer, and store them in vector devs.
Definition: sniffer.cpp:533
Sniffer::Sniffer
Sniffer()
Constructor, does nothing.
Definition: sniffer.cpp:8
Sniffer::format_hex_ascii_line
string format_hex_ascii_line(const char *payload, int len, int offset)
Return string with the bytes of a payload line in ascii.
Definition: sniffer.cpp:219
Sniffer
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).
Definition: sniffer.h:40