-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDevPool.cpp
115 lines (99 loc) · 1.64 KB
/
DevPool.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "DevPool.h"
DevPool::DevPool()
{
cur = 0;
}
DevPool::DevPool(pcap_if_t* devlist)
{
cur = 0;
pcap_if_t* a;
int i = 0;
for (a = devlist; a; a = a->next, i++)
{
u_long netmask;
if (a->addresses != NULL)
{
netmask = ((struct sockaddr_in*)(a->addresses->netmask))->sin_addr.S_un.S_addr;
}
else {
netmask = 0xffffff;
}
data.append(
new DevMsg{
QString(a->name),
QString(a->description),
netmask
}
);
}
}
DevPool::~DevPool()
{
clearPool();
}
bool DevPool::isEmpty() const
{
return getDevSize() == 0;
}
bool DevPool::outOfSize(int index) const
{
return index >= data.size() + files.size();
}
bool DevPool::isFile(int index) const
{
return index >= data.size();
}
int DevPool::getDevSize() const
{
return data.size() + files.size();
}
DevMsg* DevPool::getData(int index) const
{
return data[index];
}
DevMsg* DevPool::getFile(int index) const
{
return files[index - data.size()];
}
DevMsg* DevPool::getDev(int index) const
{
if (outOfSize(index)) return nullptr;
return isFile(index) ? getFile(index) : getData(index);
}
QVector<QString> DevPool::getDevs() const
{
QVector<QString> tmp;
for (auto dev : data) tmp.append(dev->desc);
for (auto file : files) tmp.append(file->desc);
return tmp;
}
bool DevPool::curIsFile() const
{
return isFile(cur);
}
DevMsg* DevPool::getCurDev() const
{
return getDev(cur);
}
void DevPool::setCurDev(int index)
{
if (outOfSize(index)) return;
cur = index;
}
void DevPool::addDev(DevMsg* dev)
{
files.append(dev);
}
void DevPool::clearPool()
{
for (auto dev : data)
{
delete dev;
}
for (auto file : files)
{
delete file;
}
data.clear();
files.clear();
}