PcapPlusPlus  24.09
GreLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
11 namespace pcpp
12 {
13 
18 #pragma pack(push, 1)
20  {
21 #if (BYTE_ORDER == LITTLE_ENDIAN)
23  uint8_t recursionControl : 3,
29  keyBit : 1,
34 #else
36  uint8_t checksumBit : 1,
38  routingBit : 1,
40  keyBit : 1,
42  sequenceNumBit : 1,
46  recursionControl : 3;
47 #endif
48 #if (BYTE_ORDER == LITTLE_ENDIAN)
50  uint8_t version : 3,
52  flags : 4,
55 #else
57  uint8_t ackSequenceNumBit : 1,
59  flags : 4,
61  version : 3;
62 #endif
63 
65  uint16_t protocol;
66  };
67 #pragma pack(pop)
68 
73 #pragma pack(push, 1)
75  {
77  uint16_t payloadLength;
79  uint16_t callID;
80  };
81 #pragma pack(pop)
82 
87 #pragma pack(push, 1)
89  {
91  uint8_t address;
93  uint8_t control;
95  uint16_t protocol;
96  };
97 #pragma pack(pop)
98 
104  class GreLayer : public Layer
105  {
106  public:
107  virtual ~GreLayer()
108  {}
109 
117  static ProtocolType getGREVersion(uint8_t* greData, size_t greDataLen);
118 
125  bool getSequenceNumber(uint32_t& seqNumber) const;
126 
134  bool setSequenceNumber(uint32_t seqNumber);
135 
142 
143  // implement abstract methods
144 
151 
155  size_t getHeaderLen() const;
156 
158  {
159  return OsiModelNetworkLayer;
160  }
161 
162  protected:
163  GreLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType protocol)
164  : Layer(data, dataLen, prevLayer, packet, protocol)
165  {}
166 
167  GreLayer()
168  {}
169 
170  enum GreField
171  {
172  GreChecksumOrRouting = 0,
173  GreKey = 1,
174  GreSeq = 2,
175  GreAck = 3
176  };
177 
178  uint8_t* getFieldValue(GreField field, bool returnOffsetEvenIfFieldMissing) const;
179 
180  void computeCalculateFieldsInner();
181  };
182 
189  class GREv0Layer : public GreLayer
190  {
191  public:
198  GREv0Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
199  : GreLayer(data, dataLen, prevLayer, packet, GREv0)
200  {}
201 
206 
207  virtual ~GREv0Layer()
208  {}
209 
220  {
221  return (gre_basic_header*)m_Data;
222  }
223 
230  bool getChecksum(uint16_t& checksum);
231 
242  bool setChecksum(uint16_t checksum);
243 
252 
260  bool getOffset(uint16_t& offset) const;
261 
268  bool getKey(uint32_t& key) const;
269 
277  bool setKey(uint32_t key);
278 
284  bool unsetKey();
285 
292  static inline bool isDataValid(const uint8_t* data, size_t dataLen)
293  {
294  return data && dataLen >= sizeof(gre_basic_header);
295  }
296 
297  // implement abstract methods
298 
305 
306  std::string toString() const;
307  };
308 
313  class GREv1Layer : public GreLayer
314  {
315  public:
322  GREv1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
323  : GreLayer(data, dataLen, prevLayer, packet, GREv1)
324  {}
325 
330  explicit GREv1Layer(uint16_t callID);
331 
332  virtual ~GREv1Layer()
333  {}
334 
346  {
347  return (gre1_header*)m_Data;
348  }
349 
356  bool getAcknowledgmentNum(uint32_t& ackNum) const;
357 
365  bool setAcknowledgmentNum(uint32_t ackNum);
366 
373 
380  static inline bool isDataValid(const uint8_t* data, size_t dataLen)
381  {
382  return data && dataLen >= sizeof(gre1_header);
383  }
384 
385  // implement abstract methods
386 
393 
394  std::string toString() const;
395  };
396 
402  class PPP_PPTPLayer : public Layer
403  {
404  public:
412  PPP_PPTPLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
413  : Layer(data, dataLen, prevLayer, packet, PPP_PPTP)
414  {}
415 
421  PPP_PPTPLayer(uint8_t address, uint8_t control);
422 
423  ~PPP_PPTPLayer()
424  {}
425 
432  {
433  return (ppp_pptp_header*)m_Data;
434  }
435 
436  // implement abstract methods
437 
442 
446  size_t getHeaderLen() const
447  {
448  return sizeof(ppp_pptp_header);
449  }
450 
456 
457  std::string toString() const
458  {
459  return "PPP for PPTP Layer";
460  }
461 
463  {
464  return OsiModelSesionLayer;
465  }
466  };
467 
468 } // namespace pcpp
Definition: GreLayer.h:190
std::string toString() const
bool getChecksum(uint16_t &checksum)
bool setKey(uint32_t key)
gre_basic_header * getGreHeader() const
Definition: GreLayer.h:219
GREv0Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:198
void computeCalculateFields()
bool getKey(uint32_t &key) const
bool getOffset(uint16_t &offset) const
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: GreLayer.h:292
bool setChecksum(uint16_t checksum)
Definition: GreLayer.h:314
bool setAcknowledgmentNum(uint32_t ackNum)
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: GreLayer.h:380
bool getAcknowledgmentNum(uint32_t &ackNum) const
std::string toString() const
GREv1Layer(uint16_t callID)
void computeCalculateFields()
bool unsetAcknowledgmentNum()
gre1_header * getGreHeader() const
Definition: GreLayer.h:345
GREv1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:322
Definition: GreLayer.h:105
OsiModelLayer getOsiModelLayer() const
Definition: GreLayer.h:157
bool unsetSequenceNumber()
bool getSequenceNumber(uint32_t &seqNumber) const
size_t getHeaderLen() const
void parseNextLayer()
bool setSequenceNumber(uint32_t seqNumber)
static ProtocolType getGREVersion(uint8_t *greData, size_t greDataLen)
Definition: Layer.h:70
Definition: GreLayer.h:403
size_t getHeaderLen() const
Definition: GreLayer.h:446
std::string toString() const
Definition: GreLayer.h:457
PPP_PPTPLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:412
ppp_pptp_header * getPPP_PPTPHeader() const
Definition: GreLayer.h:431
OsiModelLayer getOsiModelLayer() const
Definition: GreLayer.h:462
PPP_PPTPLayer(uint8_t address, uint8_t control)
void computeCalculateFields()
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
uint8_t ProtocolType
Definition: ProtocolType.h:17
const ProtocolType GREv0
Definition: ProtocolType.h:118
const ProtocolType PPP_PPTP
Definition: ProtocolType.h:133
const ProtocolType GREv1
Definition: ProtocolType.h:123
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelSesionLayer
Definition: ProtocolType.h:364
@ OsiModelNetworkLayer
Definition: ProtocolType.h:360
Definition: GreLayer.h:75
uint16_t payloadLength
Definition: GreLayer.h:77
uint16_t callID
Definition: GreLayer.h:79
Definition: GreLayer.h:20
uint8_t recursionControl
Definition: GreLayer.h:23
uint8_t sequenceNumBit
Definition: GreLayer.h:27
uint8_t strictSourceRouteBit
Definition: GreLayer.h:25
uint8_t routingBit
Definition: GreLayer.h:31
uint8_t ackSequenceNumBit
Definition: GreLayer.h:54
uint8_t keyBit
Definition: GreLayer.h:29
uint8_t flags
Definition: GreLayer.h:52
uint16_t protocol
Definition: GreLayer.h:65
uint8_t checksumBit
Definition: GreLayer.h:33
uint8_t version
Definition: GreLayer.h:50
Definition: GreLayer.h:89
uint16_t protocol
Definition: GreLayer.h:95
uint8_t address
Definition: GreLayer.h:91
uint8_t control
Definition: GreLayer.h:93