-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
229 lines (166 loc) · 5.73 KB
/
main.cpp
File metadata and controls
229 lines (166 loc) · 5.73 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include <cstdio>
#include <string>
#include <iostream>
//#include "Packet.h"
//#include "Sniffer.h"
#include "Reader.h"
#include "Detector.h"
//#include "Rule.h"
#include <fstream>
#include <vector>
#include "Assembler.h"
#include <algorithm>
#include "PacketContainer.h"
#include "Thread.h"
using std::string;
using std::endl;
using std::ios;
using std::ifstream;
using std::cout;
int main(int argc, char ** argv){
if (argc < 3)
return 1;
vector<string> captures;
vector<Reader> sniffers;
string conf = argv[1];
for (int i = 2; i < argc; ++i) {
string parametro = argv[i];
captures.push_back(parametro);
}
Detector d(conf);
PacketContainer packetC(d);
// Assembler a(packetC);
// packetC.setAssembler(a);
// packetC.setDetector(d);
// std::vector<Thread*> threads;
std::vector<Reader*> threads;
for (size_t i = 0; i < captures.size(); ++i) {
threads.push_back(new Reader(captures[i], packetC));
}
// cout << "threads: " << threads.size() << endl;
//
for (size_t i = 0; i < captures.size(); ++i) {
threads[i]->start();
// threads[i]->run();
}
//
for (size_t i = 0; i < captures.size(); ++i) {
threads[i]->join();
delete threads[i];
}
// cout << "quedaron" << packetC.getLen() <<endl;
// std::for_each(captures.begin(), captures.end(), [&](string filename){
// sniffers.push_back(Reader(filename, packetC, a, d));
// });
//
//
// std::for_each(sniffers.begin(), sniffers.end(), [&](Reader sniffer) {
// while (!sniffer.is_file_done()) {
// sniffer.create_packets();
// a.assemble();
// d.detect();
// }
// });
// cout << "se generaron: " << packets.size() << "paquetes" << endl;
// for (int j = 0; j < packets.size(); ++j) {
// cout << "id: " << packets[j].getId() << endl;
// cout << "src: " << packets[j].getSrc() << endl;
// cout << "dst: " << packets[j].getDst() << endl;
// cout << "flag: " << (int)packets[j].getFlag() << endl;
// cout << "offset: " << packets[j].getOffset() << endl;
// cout << "len: " << packets[j].getLength() << endl;
//// std::cout << "data: " << packets[j].getData() << std::endl;
// cout << endl;
// }
// cout << "quedaron: " << packets.size() << endl;
// for (int j = 0; j < packets.size(); ++j) {
// cout << "id: " << packets[j].getId() << endl;
// cout << "src: " << packets[j].getSrc() << endl;
// cout << "dst: " << packets[j].getDst() << endl;
// cout << "flag: " << (int)packets[j].getFlag() << endl;
// cout << "offset: " << packets[j].getOffset() << endl;
// cout << "len: " << packets[j].getLength() << endl;
// cout << endl;
// }
// int i = packets.size();
// for (int k = 0; k < i; ++k) {
// d.detect();
// }
// cout << "quedaron: " << packets.size() << endl;
// d.detect();
// // Reader sniffB = Reader(file, packets);
// sniff.create_packets();
// // sniffB.create_packets();
// int i = packets.size();
// cout << "elementos: " << i << endl;
// for (size_t j = 0; j < i; j++) {
// Packet p = packets[j];
// string s = p.getData();
// cout << "data sacada del p"<< j<<": " << s << "\n\n";
// }
//
// Packet p1 = Packet("0", "1", "2", 0x1, 0, 1);
// Packet p2 = Packet("0", "1", "2", 0x1, 1, 1);
// Packet p3 = Packet("0", "1", "2", 0x1, 2, 1);
// Packet p4 = Packet("0", "1", "2", 0x0, 3, 1);
//
// p1.setData("hola");
// p2.setData("que");
// p3.setData("tal");
// p4.setData("?");
//
//
// Packet diff = Packet("0", "1", "3", 0x0, 0, 4);
// diff.setData("diff");
//
// vector<Packet> packets;
// packets.push_back(p1);
// packets.push_back(p2);
// packets.push_back(p3);
// packets.push_back(diff);
// packets.push_back(p4);
// cout << "p2 next de p1: " << p1.is_next(p2) << endl;
// cout << "p3 next de p2: " << p2.is_next(p3) << endl;
// cout << "p4 next de p3: " << p3.is_next(p4) << endl;
// for (int j = 0; j < packets.size(); ++j) {
// std::cout << " quedaron data: " << packets[j].getData() << std::endl;
// }
//
// cout << "data ultimo: " << packets.back().getData() << endl;
// cout << "el p1 es completo?: " << p1.is_complete() << endl;
// cout << "el diff es completo?: " << diff.is_complete() << endl;
//
// cout << "p1 y p2 son iguales?: " << (p1 == p2 )<< endl;
// cout << "p2 y p1 son iguales?: " << (p2 == p1 )<< endl;
//
// cout << "p1 y p3 son iguales?: " << (p1 == p3 )<< endl;
// cout << "p3 y p1 son iguales?: " << (p3 == p1 )<< endl;
//
// cout << "p2 y p3 son iguales?: " << (p2 == p3 )<< endl;
// cout << "p3 y p2 son iguales?: " << (p3 == p2 )<< endl;
//
// cout << "p1 y diff son iguales?: " << (p1 == diff )<< endl;
// cout << "diff y p1 son iguales?: " << (diff == p1 )<< endl;
// cout << "p1 > p2?: " << (p1 > p2) << endl;
// cout << "p1 < p2?: " << (p1 < p2) << endl;
//
// cout << "p1 > p3?: " << (p1 > p2) << endl;
// cout << "p1 < p3?: " << (p1 < p2) << endl;
//
// cout << "p2 > p3?: " << (p2 > p3) << endl;
// cout << "p2 < p3?: " << (p2 < p3) << endl;
// cout << "p1 data: " << p1.getData() << endl;
// p1.mergePacket(p2);
// cout << "p1 + p2 data: " << p1.getData() << endl;
// cout << "p1 completo?: " << p1.is_complete() << endl;
//
// p3.mergePacket(p4);
// cout << "p3 + p4 data: " << p3.getData() << endl;
// cout << "p3 completo?: " << p3.is_complete() << endl;
//
// p1.mergePacket(p3);
// cout << "p1 + p2 + p3 + p4 data: " << p1.getData() << endl;
// cout << "p1 completo?: " << p1.is_complete() << endl;
// cout << "p1 len: " << p1.getLength() << endl;
return 0;
}