-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
39 lines (36 loc) · 957 Bytes
/
main.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
#include "stdafx.h"
#include "PCAPRecorder.h"
#include "Sniffer.h"
int main()
{
int i = 0;
Yellow::Sniffer s;
Yellow::PCAP::Recorder rec;
std::shared_ptr<Yellow::Packet> pack;
std::ofstream ofs ("test.txt", std::ofstream::out | std::ofstream::trunc | std::ofstream::binary);
if (!ofs)
{
std::cout << "fail to get file" << std::endl;
return 0;
}
if (!s.start())
{
std::cout << "Fail tu start" << std::endl;
return 0;
}
while ((pack = s.getPacket()) != nullptr)
{
rec.addRecord(pack);
std::cout << "Source IP : " << pack->getIPHeader().getSourceIP()
<< ", Destination IP :" << pack->getIPHeader().getDestinationIP()
<< ", proto: " << pack->getIPHeader().getProtocol() << std::endl;
i++;
if (i >= 150)
{
std::cout << "Stopping..." << std::endl;
s.stop();
}
}
ofs << rec;
return 0;
}