-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcap_analyse.cpp
65 lines (58 loc) · 1.5 KB
/
pcap_analyse.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "pcap_analyse.h"
#include <netdb.h>
#include <QDebug>
#include <QThread>
struct pcap_pkthdr pcap_analyse::header;
pcap_t *pcap_analyse::handle;
pcap_analyse::pcap_analyse(QObject *parent) :
QObject(parent)
{
window = (MainWindow*)parent;
_abort = false;
_interrupt = false;
}
void pcap_analyse::requestPaquet(QString filename)
{
handle = pcap_open_offline(filename.toLatin1(), errbuf); //call pcap library function
if (this->handle == NULL) {
qDebug("fail open file");
return;
}
QMutexLocker locker(&mutex);
_interrupt = true;
condition.wakeOne();
}
void pcap_analyse::run()
{
u_char * data;
struct pcap_pkthdr *pkt_hdr;
if(handle)
{
while (int returnValue = pcap_next_ex(handle, &pkt_hdr, const_cast<const u_char**>(&data)) >= 0) {
mutex.lock();
if (!_interrupt && !_abort) {
condition.wait(&mutex);
}
if (_abort) {
qDebug() <<"Aborting worker mainLoop in Thread "<<thread()->currentThreadId();
mutex.unlock();
pcap_close(handle);
emit finished();
return;
}
mutex.unlock();
QDateTime timestamp;
qDebug(timestamp.toString().toLatin1());
emit tvalueChanged(const_cast<uchar *> (data), *pkt_hdr);
// pkt_hdr = malloc(sizeof(struct_pkthdr));
} //end internal loop for reading packets (all in one file)
pcap_close(handle);
}
emit finished();
}
void pcap_analyse::abort()
{
QMutexLocker locker(&mutex);
_abort = true;
condition.wakeOne();
}