PcapPlusPlus  20.08
MBufRawPacket.h
1 #ifndef PCAPPP_MBUF_RAW_PACKET
2 #define PCAPPP_MBUF_RAW_PACKET
3 
4 #include <time.h>
5 #include "Packet.h"
6 #include "PointerVector.h"
7 
8 struct rte_mbuf;
9 struct rte_mempool;
10 
15 namespace pcpp
16 {
17 
18  class DpdkDevice;
19  class KniDevice;
20 
21  #define MBUFRAWPACKET_OBJECT_TYPE 1
22 
43  class MBufRawPacket : public RawPacket
44  {
45  friend class DpdkDevice;
46  friend class KniDevice;
47  static const int MBUF_DATA_SIZE;
48 
49  protected:
50  struct rte_mbuf* m_MBuf;
51  struct rte_mempool* m_Mempool;
52  bool m_FreeMbuf;
53 
54  void setMBuf(struct rte_mbuf* mBuf, timespec timestamp);
55  bool init(struct rte_mempool* mempool);
56  bool initFromRawPacket(const RawPacket* rawPacket, struct rte_mempool* mempool);
57  public:
58 
64  MBufRawPacket() : RawPacket(), m_MBuf(NULL), m_Mempool(NULL), m_FreeMbuf(true) { m_DeleteRawDataAtDestructor = false; }
65 
69  virtual ~MBufRawPacket();
70 
77  MBufRawPacket(const MBufRawPacket& other);
78 
88  bool init(DpdkDevice* device);
98  bool init(KniDevice* device);
99 
111  bool initFromRawPacket(const RawPacket* rawPacket, DpdkDevice* device);
123  bool initFromRawPacket(const RawPacket* rawPacket, KniDevice* device);
124 
128  inline rte_mbuf* getMBuf() { return m_MBuf; }
129 
130  // overridden methods
131 
135  virtual inline uint8_t getObjectType() const { return MBUFRAWPACKET_OBJECT_TYPE; }
136 
143  MBufRawPacket& operator=(const MBufRawPacket& other);
144 
159  bool setRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
160 
164  void clear();
165 
172  void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen);
173 
182  void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen);
183 
192  bool removeData(int atIndex, size_t numOfBytesToRemove);
193 
200  bool reallocateData(size_t newBufferLength);
201 
207  inline void setFreeMbuf(bool val = true) { m_FreeMbuf = val; }
208  };
209 
215 
216 } // namespace pcpp
217 
218 #endif /* PCAPPP_MBUF_RAW_PACKET */
pcpp::MBufRawPacket::MBufRawPacket
MBufRawPacket()
Definition: MBufRawPacket.h:64
pcpp::MBufRawPacket::insertData
void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen)
pcpp::MBufRawPacket::setFreeMbuf
void setFreeMbuf(bool val=true)
Definition: MBufRawPacket.h:207
pcpp::DpdkDevice
Definition: DpdkDevice.h:164
pcpp::LINKTYPE_ETHERNET
@ LINKTYPE_ETHERNET
Definition: RawPacket.h:30
pcpp::MBufRawPacketVector
PointerVector< MBufRawPacket > MBufRawPacketVector
Definition: MBufRawPacket.h:214
pcpp::MBufRawPacket::removeData
bool removeData(int atIndex, size_t numOfBytesToRemove)
pcpp::KniDevice
Definition: KniDevice.h:120
PointerVector.h
pcpp::MBufRawPacket::reallocateData
bool reallocateData(size_t newBufferLength)
pcpp::MBufRawPacket::getObjectType
virtual uint8_t getObjectType() const
Definition: MBufRawPacket.h:135
pcpp::MBufRawPacket::appendData
void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen)
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::LinkLayerType
LinkLayerType
Definition: RawPacket.h:25
pcpp::MBufRawPacket::getMBuf
rte_mbuf * getMBuf()
Definition: MBufRawPacket.h:128
Packet.h
pcpp::PointerVector
Definition: PointerVector.h:24
pcpp::MBufRawPacket::clear
void clear()
pcpp::MBufRawPacket::setRawData
bool setRawData(const uint8_t *pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1)
pcpp::MBufRawPacket::~MBufRawPacket
virtual ~MBufRawPacket()
pcpp::MBufRawPacket
Definition: MBufRawPacket.h:43
pcpp::RawPacket
Definition: RawPacket.h:252
pcpp::MBufRawPacket::operator=
MBufRawPacket & operator=(const MBufRawPacket &other)