PcapPlusPlus
RawPacket.h
Go to the documentation of this file.
1 #ifndef PCAPPP_RAW_PACKET
2 #define PCAPPP_RAW_PACKET
3 
4 #include <stdint.h>
5 #ifdef _MSC_VER
6 #include <WinSock2.h>
7 #else
8 #include <sys/time.h>
9 #endif
10 #include <stddef.h>
11 
13 
18 namespace pcpp
19 {
20 
26  {
54  LINKTYPE_RAW = 101,
207  };
208 
212 #define PCPP_MAX_PACKET_SIZE 65536
213 
220  class RawPacket
221  {
222  protected:
223  uint8_t* m_pRawData;
224  int m_RawDataLen;
225  int m_FrameLength;
226  timeval m_TimeStamp;
227  bool m_DeleteRawDataAtDestructor;
228  bool m_RawPacketSet;
229  LinkLayerType m_linkLayerType;
230  void Init();
231  void copyDataFrom(const RawPacket& other, bool allocateData = true);
232  public:
244  RawPacket(const uint8_t* pRawData, int rawDataLen, timeval timestamp, bool deleteRawDataAtDestructor, LinkLayerType layerType = LINKTYPE_ETHERNET);
245 
253  RawPacket();
254 
258  virtual ~RawPacket();
259 
265  RawPacket(const RawPacket& other);
266 
273  RawPacket& operator=(const RawPacket& other);
274 
278  virtual inline uint8_t getObjectType() const { return 0; }
279 
290  virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
291 
296  const uint8_t* getRawData();
297 
302  const uint8_t* getRawDataReadOnly() const;
303 
309 
314  int getRawDataLen() const;
315 
320  int getFrameLength() const;
325  timeval getPacketTimeStamp();
326 
333  inline bool isPacketSet() { return m_RawPacketSet; }
334 
341  virtual void clear();
342 
350  virtual void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen);
351 
360  virtual void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen);
361 
368  virtual bool removeData(int atIndex, size_t numOfBytesToRemove);
369 
378  virtual bool reallocateData(size_t newBufferLength);
379  };
380 
381 } // namespace pcpp
382 
383 #endif
Definition: RawPacket.h:202
Definition: RawPacket.h:198
virtual ~RawPacket()
Definition: RawPacket.h:110
Definition: RawPacket.h:192
Definition: RawPacket.h:178
Definition: RawPacket.h:40
Definition: RawPacket.h:88
const uint8_t * getRawDataReadOnly() const
Definition: RawPacket.h:122
virtual bool setRawData(const uint8_t *pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1)
Definition: RawPacket.h:102
Definition: RawPacket.h:58
Definition: RawPacket.h:124
Definition: RawPacket.h:76
LinkLayerType getLinkLayerType() const
virtual void clear()
Definition: RawPacket.h:92
virtual void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen)
Definition: RawPacket.h:162
Definition: RawPacket.h:184
Definition: RawPacket.h:32
Definition: RawPacket.h:136
Definition: RawPacket.h:182
Definition: RawPacket.h:30
Definition: RawPacket.h:166
Definition: RawPacket.h:220
Definition: RawPacket.h:186
Definition: RawPacket.h:128
The main namespace for the PcapPlusPlus lib.
Definition: RawPacket.h:164
Definition: RawPacket.h:82
Definition: RawPacket.h:36
Definition: RawPacket.h:138
Definition: RawPacket.h:64
LinkLayerType
Definition: RawPacket.h:25
timeval getPacketTimeStamp()
Definition: RawPacket.h:60
Definition: RawPacket.h:94
Definition: RawPacket.h:84
const uint8_t * getRawData()
Definition: RawPacket.h:158
Definition: RawPacket.h:148
Definition: RawPacket.h:70
Definition: RawPacket.h:78
Definition: RawPacket.h:98
Definition: RawPacket.h:66
virtual uint8_t getObjectType() const
Definition: RawPacket.h:278
Definition: RawPacket.h:62
Definition: RawPacket.h:180
Definition: RawPacket.h:56
RawPacket & operator=(const RawPacket &other)
Definition: RawPacket.h:50
Definition: RawPacket.h:160
Definition: RawPacket.h:38
Definition: RawPacket.h:72
Definition: RawPacket.h:28
Definition: RawPacket.h:196
Definition: RawPacket.h:188
Definition: RawPacket.h:168
Definition: RawPacket.h:176
Definition: RawPacket.h:42
Definition: RawPacket.h:146
Definition: RawPacket.h:68
Definition: RawPacket.h:74
Definition: RawPacket.h:134
Definition: RawPacket.h:156
Definition: RawPacket.h:112
Definition: RawPacket.h:52
int getRawDataLen() const
Definition: RawPacket.h:140
Definition: RawPacket.h:204
Definition: RawPacket.h:118
Definition: RawPacket.h:142
virtual bool reallocateData(size_t newBufferLength)
Definition: RawPacket.h:44
Definition: RawPacket.h:108
Definition: RawPacket.h:190
Definition: RawPacket.h:114
bool isPacketSet()
Definition: RawPacket.h:333
Definition: RawPacket.h:48
Definition: RawPacket.h:130
Definition: RawPacket.h:80
Definition: RawPacket.h:170
Definition: RawPacket.h:100
Definition: RawPacket.h:106
Definition: RawPacket.h:144
Definition: RawPacket.h:150
Definition: RawPacket.h:96
Definition: RawPacket.h:116
Definition: RawPacket.h:86
Definition: RawPacket.h:152
Definition: RawPacket.h:54
Definition: RawPacket.h:132
Definition: RawPacket.h:126
Definition: RawPacket.h:206
Definition: RawPacket.h:90
Definition: RawPacket.h:104
int getFrameLength() const
Definition: RawPacket.h:34
Definition: RawPacket.h:194
Definition: RawPacket.h:174
virtual void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen)
Definition: RawPacket.h:46
virtual bool removeData(int atIndex, size_t numOfBytesToRemove)
Definition: RawPacket.h:200
Definition: RawPacket.h:172
Definition: RawPacket.h:154