PcapPlusPlus  23.09
MBufRawPacket.h
1 #ifndef PCAPPP_MBUF_RAW_PACKET
2 #define PCAPPP_MBUF_RAW_PACKET
3 
4 // GCOVR_EXCL_START
5 
6 #include <time.h>
7 #include "Packet.h"
8 #include "PointerVector.h"
9 
10 struct rte_mbuf;
11 struct rte_mempool;
12 
17 namespace pcpp
18 {
19 
20  class DpdkDevice;
21  class KniDevice;
22 
23  #define MBUFRAWPACKET_OBJECT_TYPE 1
24 
45  class MBufRawPacket : public RawPacket
46  {
47  friend class DpdkDevice;
48  friend class KniDevice;
49  static const int MBUF_DATA_SIZE;
50 
51  protected:
52  struct rte_mbuf* m_MBuf;
53  struct rte_mempool* m_Mempool;
54  bool m_FreeMbuf;
55 
56  void setMBuf(struct rte_mbuf* mBuf, timespec timestamp);
57  bool init(struct rte_mempool* mempool);
58  bool initFromRawPacket(const RawPacket* rawPacket, struct rte_mempool* mempool);
59  public:
60 
66  MBufRawPacket() : RawPacket(), m_MBuf(NULL), m_Mempool(NULL), m_FreeMbuf(true) { m_DeleteRawDataAtDestructor = false; }
67 
71  virtual ~MBufRawPacket();
72 
79  MBufRawPacket(const MBufRawPacket& other);
80 
90  bool init(DpdkDevice* device);
100  bool init(KniDevice* device);
101 
113  bool initFromRawPacket(const RawPacket* rawPacket, DpdkDevice* device);
125  bool initFromRawPacket(const RawPacket* rawPacket, KniDevice* device);
126 
130  inline rte_mbuf* getMBuf() { return m_MBuf; }
131 
132  // overridden methods
133 
137  virtual inline uint8_t getObjectType() const { return MBUFRAWPACKET_OBJECT_TYPE; }
138 
145  MBufRawPacket& operator=(const MBufRawPacket& other);
146 
161  bool setRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
162 
166  void clear();
167 
174  void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen);
175 
184  void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen);
185 
194  bool removeData(int atIndex, size_t numOfBytesToRemove);
195 
202  bool reallocateData(size_t newBufferLength);
203 
209  inline void setFreeMbuf(bool val = true) { m_FreeMbuf = val; }
210  };
211 
217 
218 } // namespace pcpp
219 
220 // GCOVR_EXCL_STOP
221 
222 #endif /* PCAPPP_MBUF_RAW_PACKET */
The main namespace for the PcapPlusPlus lib.
void setFreeMbuf(bool val=true)
Definition: MBufRawPacket.h:209
Definition: KniDevice.h:123
Definition: RawPacket.h:30
void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen)
PointerVector< MBufRawPacket > MBufRawPacketVector
Definition: MBufRawPacket.h:216
virtual uint8_t getObjectType() const
Definition: MBufRawPacket.h:137
MBufRawPacket & operator=(const MBufRawPacket &other)
Definition: PointerVector.h:24
Definition: RawPacket.h:254
Definition: MBufRawPacket.h:45
void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen)
Definition: DpdkDevice.h:169
bool removeData(int atIndex, size_t numOfBytesToRemove)
MBufRawPacket()
Definition: MBufRawPacket.h:66
LinkLayerType
Definition: RawPacket.h:25
virtual ~MBufRawPacket()
bool reallocateData(size_t newBufferLength)
bool setRawData(const uint8_t *pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1)
rte_mbuf * getMBuf()
Definition: MBufRawPacket.h:130