PcapPlusPlus  22.11
GreLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_GRE_LAYER
2 #define PACKETPP_GRE_LAYER
3 
4 #include "Layer.h"
5 
7 
8 
13 namespace pcpp
14 {
15 
20 #pragma pack(push, 1)
22  {
23 #if (BYTE_ORDER == LITTLE_ENDIAN)
24 
25  uint8_t recursionControl:3,
31  keyBit:1,
33  routingBit:1,
35  checksumBit:1;
36 #else
37 
38  uint8_t checksumBit:1,
40  routingBit:1,
42  keyBit:1,
49 #endif
50 #if (BYTE_ORDER == LITTLE_ENDIAN)
51 
52  uint8_t version:3,
54  flags:4,
57 #else
58 
59  uint8_t ackSequenceNumBit:1,
61  flags:4,
63  version:3;
64 #endif
65 
67  uint16_t protocol;
68  };
69 #pragma pack(pop)
70 
71 
76 #pragma pack(push, 1)
78  {
80  uint16_t payloadLength;
82  uint16_t callID;
83  };
84 #pragma pack(pop)
85 
86 
91 #pragma pack(push, 1)
93  {
95  uint8_t address;
97  uint8_t control;
99  uint16_t protocol;
100  };
101 #pragma pack(pop)
102 
103 
108  class GreLayer : public Layer
109  {
110  public:
111 
112  virtual ~GreLayer() {}
113 
121  static ProtocolType getGREVersion(uint8_t* greData, size_t greDataLen);
122 
129  bool getSequenceNumber(uint32_t& seqNumber) const;
130 
138  bool setSequenceNumber(uint32_t seqNumber);
139 
145  bool unsetSequenceNumber();
146 
147 
148  // implement abstract methods
149 
155  void parseNextLayer();
156 
160  size_t getHeaderLen() const;
161 
163 
164  protected:
165  GreLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { }
166 
167  GreLayer() {}
168 
169  enum GreField
170  {
171  GreChecksumOrRouting = 0,
172  GreKey = 1,
173  GreSeq = 2,
174  GreAck = 3
175  };
176 
177  uint8_t* getFieldValue(GreField field, bool returnOffsetEvenIfFieldMissing) const;
178 
179  void computeCalculateFieldsInner();
180  };
181 
182 
189  class GREv0Layer : public GreLayer
190  {
191  public:
192 
199  GREv0Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : GreLayer(data, dataLen, prevLayer, packet) { m_Protocol = GREv0; }
200 
204  GREv0Layer();
205 
206  virtual ~GREv0Layer() {}
207 
217  gre_basic_header* getGreHeader() const { return (gre_basic_header*)m_Data; }
218 
225  bool getChecksum(uint16_t& checksum);
226 
236  bool setChecksum(uint16_t checksum);
237 
244  bool unsetChecksum();
245 
253  bool getOffset(uint16_t& offset) const;
254 
261  bool getKey(uint32_t& key) const;
262 
270  bool setKey(uint32_t key);
271 
277  bool unsetKey();
278 
279 
280  // implement abstract methods
281 
282 
288  void computeCalculateFields();
289 
290  std::string toString() const;
291 
292  };
293 
294 
299  class GREv1Layer : public GreLayer
300  {
301  public:
302 
309  GREv1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : GreLayer(data, dataLen, prevLayer, packet) { m_Protocol = GREv1; }
310 
315  GREv1Layer(uint16_t callID);
316 
317  virtual ~GREv1Layer() {}
318 
327  gre1_header* getGreHeader() const { return (gre1_header*)m_Data; }
328 
335  bool getAcknowledgmentNum(uint32_t& ackNum) const;
336 
344  bool setAcknowledgmentNum(uint32_t ackNum);
345 
351  bool unsetAcknowledgmentNum();
352 
353 
354  // implement abstract methods
355 
361  void computeCalculateFields();
362 
363  std::string toString() const;
364 
365  };
366 
367 
372  class PPP_PPTPLayer : public Layer
373  {
374  public:
382  PPP_PPTPLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = PPP_PPTP; }
383 
389  PPP_PPTPLayer(uint8_t address, uint8_t control);
390 
391  ~PPP_PPTPLayer() {}
392 
397  ppp_pptp_header* getPPP_PPTPHeader() const { return (ppp_pptp_header*)m_Data; }
398 
399 
400  // implement abstract methods
401 
405  void parseNextLayer();
406 
410  size_t getHeaderLen() const { return sizeof(ppp_pptp_header); }
411 
416  void computeCalculateFields();
417 
418  std::string toString() const { return "PPP for PPTP Layer"; }
419 
421 
422  };
423 
424 } // namespace pcpp
425 
426 #endif /* PACKETPP_GRE_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:298
GREv0Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:199
PPP_PPTPLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:382
uint8_t keyBit
Definition: GreLayer.h:25
Definition: GreLayer.h:189
gre1_header * getGreHeader() const
Definition: GreLayer.h:327
size_t getHeaderLen() const
Definition: GreLayer.h:410
Definition: Layer.h:70
Definition: Packet.h:26
uint8_t ackSequenceNumBit
Definition: GreLayer.h:52
uint16_t protocol
Definition: GreLayer.h:67
GREv1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:309
uint8_t address
Definition: GreLayer.h:95
uint8_t sequenceNumBit
Definition: GreLayer.h:25
OsiModelLayer getOsiModelLayer() const
Definition: GreLayer.h:420
uint8_t routingBit
Definition: GreLayer.h:25
uint8_t version
Definition: GreLayer.h:52
gre_basic_header * getGreHeader() const
Definition: GreLayer.h:217
Definition: ProtocolType.h:305
uint16_t payloadLength
Definition: GreLayer.h:80
uint64_t ProtocolType
Definition: ProtocolType.h:18
Definition: GreLayer.h:77
uint8_t recursionControl
Definition: GreLayer.h:25
Definition: GreLayer.h:372
Definition: GreLayer.h:108
const ProtocolType GREv1
Definition: ProtocolType.h:118
const ProtocolType PPP_PPTP
Definition: ProtocolType.h:128
uint16_t callID
Definition: GreLayer.h:82
uint8_t control
Definition: GreLayer.h:97
const ProtocolType GREv0
Definition: ProtocolType.h:113
uint8_t flags
Definition: GreLayer.h:52
Definition: GreLayer.h:21
uint8_t strictSourceRouteBit
Definition: GreLayer.h:25
OsiModelLayer getOsiModelLayer() const
Definition: GreLayer.h:162
Definition: ProtocolType.h:309
uint8_t checksumBit
Definition: GreLayer.h:25
uint16_t protocol
Definition: GreLayer.h:99
Definition: GreLayer.h:92
Definition: GreLayer.h:299
ppp_pptp_header * getPPP_PPTPHeader() const
Definition: GreLayer.h:397
std::string toString() const
Definition: GreLayer.h:418