Hello all,
I have a thread that calls a pcap loop function which is then called from a class to add items to a table.
Thread class:
void PcapThread::startCaptureOnInterface()
{
int r;
while(captureOn){
struct pcap_pkthdr *header;
const u_char *pkt_data;
r = pcap_next_ex(descr,&header,&pkt_data);
emit addToWidget(header,pkt_data);
}
void PcapThread::startCaptureOnInterface()
{
int r;
while(captureOn){
struct pcap_pkthdr *header;
const u_char *pkt_data;
r = pcap_next_ex(descr,&header,&pkt_data);
emit addToWidget(header,pkt_data);
}
To copy to clipboard, switch view to plain text mode
PacketTable class:
void PacketTable::addToWidget(struct pcap_pkthdr* pkthdr, const u_char* packet)
void PacketTable::addToWidget(struct pcap_pkthdr* pkthdr, const u_char* packet)
To copy to clipboard, switch view to plain text mode
so far this method adds items to a table such as source IP, destination IP, packet length etc but there is no storage.
However i would like to store this in a data structure by using const u_char *packet as this is how the packet headers are declared:
struct ether_header *ethernet = (struct ether_header*)packet;
struct iphdr *ip = (struct iphdr*)(packet + sizeof(struct ether_header));
struct tcphdr *tcp = (struct tcphdr*)(packet + sizeof(struct ether_header) + sizeof(struct iphdr));
payload = (u_char *)(packet + sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct tcphdr));
struct ether_header *ethernet = (struct ether_header*)packet;
struct iphdr *ip = (struct iphdr*)(packet + sizeof(struct ether_header));
struct tcphdr *tcp = (struct tcphdr*)(packet + sizeof(struct ether_header) + sizeof(struct iphdr));
payload = (u_char *)(packet + sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct tcphdr));
To copy to clipboard, switch view to plain text mode
Im not sure how to go about this as i would to declare methods in a seperate class then iterate and call the methods to get data out.
Darshan
Bookmarks