pcapBackend.hpp
Go to the documentation of this file.
1 #ifdef WITH_PCAP
2 
3 #ifndef PCAPBACKEND_HPP
4 #define PCAPBACKEND_HPP
5 
6 #include <pcap.h>
7 
8 #include <array>
9 #include <cassert>
10 #include <cerrno>
11 #include <cstdint>
12 #include <cstdio>
13 #include <cstdlib>
14 #include <cstring>
15 #include <iostream>
16 #include <string>
17 
18 #include <net/ethernet.h>
19 
20 #include "IPv4_5TupleL2Ident.hpp"
21 #include "bufArray.hpp"
22 #include "samplePacket.hpp"
23 #include "stateMachine.hpp"
24 
25 class PcapBackend {
26 private:
27  using TupleIdent = IPv4_5TupleL2Ident<SamplePacket>;
28 
29  pcap_t *handle;
30  std::string dev;
31  char errbuf[PCAP_ERRBUF_SIZE];
32  // StateMachine<TupleIdent, SamplePacket> &sm;
33 
34  static constexpr uint32_t bufSize = 2048;
35  static constexpr unsigned int maxBufArraySize = 64;
36 
37  std::vector<SamplePacket *> packetPool;
38  std::array<uint8_t, 6> srcMac;
39 
40 public:
41  // WARNING: THIS CLASS IS NOT THREAD SAFE
42  PcapBackend(std::string dev,
43  std::array<uint8_t, 6> srcMac //,
44  // StateMachine<TupleIdent, SamplePacket> &sm
45  );
46 
47  ~PcapBackend();
48 
49  void sendBatch(BufArray<SamplePacket> &pkts);
50  void freeBatch(BufArray<SamplePacket> &pkts);
51 
52  BufArray<SamplePacket> *recvBatch();
53 
54  SamplePacket *getPkt();
55 };
56 
57 #endif /* PCAPBACKEND_HPP */
58 
59 #endif /* WITH_PCAP */
Example for a packet class.
Wrapper around MoonGen bufarrays.
Definition: bufArray.hpp:42