This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 136
/
pcapsession.h
82 lines (70 loc) · 1.77 KB
/
pcapsession.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
Copyright (C) 2019 Srivats P.
This file is part of "Ostinato"
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef _PCAP_SESSION_H
#define _PCAP_SESSION_H
#include <QThread>
#include <pcap.h>
#ifdef Q_OS_UNIX
#include <QHash>
#include <pthread.h>
class ThreadId {
public:
ThreadId() {
id_ = pthread_self();
}
ThreadId(pthread_t id) {
id_ = id;
}
pthread_t nativeId() {
return id_;
}
uint hash() const {
QByteArray t((const char*)(&id_), sizeof(id_));
return qHash(t);
}
bool operator==(const ThreadId &other) const {
return (pthread_equal(id_, other.id_) != 0);
}
private:
pthread_t id_;
};
inline uint qHash(const ThreadId &key)
{
return key.hash();
}
class PcapSession: public QThread
{
protected:
void preRun();
void postRun();
void stop(pcap_t *handle);
private:
static void signalBreakHandler(int /*signum*/);
ThreadId thread_;
static QHash<ThreadId, bool> signalSeen_;
};
#else
class PcapSession: public QThread
{
protected:
void preRun() {};
void postRun() {};
void stop(pcap_t *handle) {
qDebug("calling breakloop with handle %p", handle);
pcap_breakloop(handle);
}
};
#endif
#endif