-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmainwindow.h
95 lines (82 loc) · 2.19 KB
/
mainwindow.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
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtAlgorithms>
#include <algorithm>
#include <QMainWindow>
#include <QTimer>
#include <QClipboard>
#include <QList>
#include <QPair>
#include <QMutex>
#include "npcap.h"
namespace Ui {
class MainWindow;
}
struct Mykey
{
qint64 ts;
QString proto;
QString saddr;
quint16 sport;
QString daddr;
quint16 dport;
QString toString() const
{
const char separator[] = " | ";
QString r;
r.append(QDateTime::fromSecsSinceEpoch(ts).toString("yyyy-MM-dd HH"));
r.append(separator);
r.append(proto.leftJustified(5));
r.append(separator);
r.append(saddr);
r.append(separator);
r.append(QString::number(sport).rightJustified(5));
r.append(separator);
r.append(daddr);
r.append(separator);
r.append(QString::number(dport).rightJustified(5));
return r;
}
static QString headers()
{
return "yyyy-MM-dd HH | Proto | Src | Port | Dest | Port | KiloBytes \n";
}
};
inline bool operator==(const Mykey &a, const Mykey &b)
{
return a.ts == b.ts && a.proto == b.proto && a.saddr == b.saddr && a.sport == b.sport && a.daddr == b.daddr && a.dport == b.dport;
}
inline uint qHash(const Mykey &key, uint seed)
{
uint r = 0;
r ^= qHash(key.ts, seed);
r ^= qHash(key.proto, seed);
r ^= qHash(key.saddr, seed);
r ^= qHash(key.sport, seed);
r ^= qHash(key.daddr, seed);
r ^= qHash(key.dport, seed);
return r;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void timer_timeout();
void npcap_newPacket(QDateTime timestamp, QString proto, QString saddr, u_short sport, QString daddr, u_short dport, bpf_u_int32 len);
void on_btnStart_clicked();
void on_cmbIfs_currentIndexChanged(int index);
void on_btnClipboard_clicked();
void on_btnRefresh_clicked();
private:
Ui::MainWindow *ui;
QMutex m_mutex;
QTimer m_timer;
QString m_string;
Npcap npcap;
QHash<Mykey, quint64> m_map;
bool isSame(QString addr);
};
#endif // MAINWINDOW_H