-
Notifications
You must be signed in to change notification settings - Fork 0
/
PCAPRecorder.cpp
73 lines (61 loc) · 1.9 KB
/
PCAPRecorder.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
#include "stdafx.h"
#include "Packet.h"
#include "PCAPHeader.h"
#include "PCAPRecord.h"
#include "PCAPRecorder.h"
Yellow::PCAP::Recorder::Recorder()
{
_gheader.magic_number = 0xa1b2c3d4;
_gheader.version_major = 2;
_gheader.version_minor = 4;
_gheader.thiszone = 0;
_gheader.sigfigs = 0;
_gheader.snaplen = 655335;
_gheader.network = 1;
}
Yellow::PCAP::Recorder::~Recorder()
{
}
const Yellow::PCAP::GlobalHeader &Yellow::PCAP::Recorder::getGlobalHeader() const
{
return _gheader;
}
const std::vector<std::shared_ptr<Yellow::PCAP::Record>> &Yellow::PCAP::Recorder::getRecords() const
{
return _records;
}
std::shared_ptr<Yellow::PCAP::Record> Yellow::PCAP::Recorder::addRecord(std::shared_ptr<Yellow::PCAP::Record> rec)
{
_records.push_back(rec);
return rec;
}
std::shared_ptr<Yellow::PCAP::Record> Yellow::PCAP::Recorder::addRecord(std::shared_ptr<Yellow::Packet> pack)
{
std::shared_ptr<Record> rec = std::make_shared<Yellow::PCAP::Record>(pack);
_records.push_back(rec);
return rec;
}
std::ostream &Yellow::PCAP::operator<<(std::ostream &output, Yellow::PCAP::Recorder &rec)
{
output.write(reinterpret_cast<char *>(&rec._gheader), sizeof(rec._gheader));
if (!output || output.eof())
return (output);
for (std::shared_ptr<Yellow::PCAP::Record> record : rec._records)
output << *record;
return output;
}
std::istream &Yellow::PCAP::operator>>(std::istream &input, Yellow::PCAP::Recorder &rec)
{
std::shared_ptr<Yellow::PCAP::Record> record;
input.read(reinterpret_cast<char *>(&rec._gheader), sizeof(rec._gheader));
if (!input || input.eof())
return (input);
rec._records.clear();
record = std::make_shared<Yellow::PCAP::Record>();
while (input >> *record)
{
rec._records.push_back(record);
record = std::make_shared<Yellow::PCAP::Record>();
}
return input;
}