-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathFakeDriver.h
39 lines (26 loc) · 911 Bytes
/
FakeDriver.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
#include <PcapFileDevice.h>
#include <RawPacket.h>
vector<RawPacket> packet_list;
uint64_t packet_counter = 0;
bool init(uint16_t dev_id = 0, bool enable_dhcp = false){
// create a pcap file reader
pcpp::PcapFileReaderDevice pcapReader("input.pcap");
pcapReader.open();
// create a pcapng file writer
pcpp::PcapNgFileWriterDevice pcapNgWriter("output.pcapng");
pcapNgWriter.open();
// raw packet object
pcpp::RawPacket rawPacket;
// read packets from pcap reader and write pcapng writer
while (pcapReader->getNextPacket(rawPacket)) {
packet_list.append(rawPacket)
}
return true;
}
driver_event receive()
{
RawPacket *rawPacket = &packet_list[packet_counter];
packet_counter++;
vector<uint8_t> pcap_buffer(rawPacket->getRawData(), rawPacket->getRawData() + rawPacket->getRawDataLen());
return driver_event({NL_CMD_RX, pcap_buffer, &pcap_buffer[0], rawPacket->getRawDataLen()});
}