PcapPlusPlus
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);
130 
138  bool setSequenceNumber(uint32_t seqNumber);
139 
145  bool unsetSequenceNumber();
146 
147 
148  // implement abstract methods
149 
154  void parseNextLayer();
155 
159  size_t getHeaderLen();
160 
162 
163  protected:
164  GreLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { }
165 
166  GreLayer() {}
167 
168  enum GreField
169  {
170  GreChecksumOrRouting = 0,
171  GreKey = 1,
172  GreSeq = 2,
173  GreAck = 3
174  };
175 
176  uint8_t* getFieldValue(GreField field, bool returnOffsetEvenIfFieldMissing);
177 
178  void computeCalculateFieldsInner();
179  };
180 
181 
188  class GREv0Layer : public GreLayer
189  {
190  public:
191 
198  GREv0Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : GreLayer(data, dataLen, prevLayer, packet) { m_Protocol = GREv0; }
199 
203  GREv0Layer();
204 
205  virtual ~GREv0Layer() {}
206 
216  inline gre_basic_header* getGreHeader() { return (gre_basic_header*)m_Data; }
217 
224  bool getChecksum(uint16_t& checksum);
225 
235  bool setChecksum(uint16_t checksum);
236 
243  bool unsetChecksum();
244 
252  bool getOffset(uint16_t& offset);
253 
260  bool getKey(uint32_t& key);
261 
269  bool setKey(uint32_t key);
270 
276  bool unsetKey();
277 
278 
279  // implement abstract methods
280 
281 
287  void computeCalculateFields();
288 
289  std::string toString();
290 
291  };
292 
293 
298  class GREv1Layer : public GreLayer
299  {
300  public:
301 
308  GREv1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : GreLayer(data, dataLen, prevLayer, packet) { m_Protocol = GREv1; }
309 
314  GREv1Layer(uint16_t callID);
315 
316  virtual ~GREv1Layer() {}
317 
326  inline gre1_header* getGreHeader() { return (gre1_header*)m_Data; }
327 
334  bool getAcknowledgmentNum(uint32_t& ackNum);
335 
343  bool setAcknowledgmentNum(uint32_t ackNum);
344 
350  bool unsetAcknowledgmentNum();
351 
352 
353  // implement abstract methods
354 
360  void computeCalculateFields();
361 
362  std::string toString();
363 
364  };
365 
366 
371  class PPP_PPTPLayer : public Layer
372  {
373  public:
381  PPP_PPTPLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = PPP_PPTP; }
382 
388  PPP_PPTPLayer(uint8_t address, uint8_t control);
389 
390  ~PPP_PPTPLayer() {}
391 
396  inline ppp_pptp_header* getPPP_PPTPHeader() { return (ppp_pptp_header*)m_Data; }
397 
398 
399  // implement abstract methods
400 
404  void parseNextLayer();
405 
409  inline size_t getHeaderLen() { return sizeof(ppp_pptp_header); }
410 
415  void computeCalculateFields();
416 
417  std::string toString() { return "PPP for PPTP Layer"; }
418 
420 
421  };
422 
423 } // namespace pcpp
424 
425 #endif /* PACKETPP_GRE_LAYER */
gre_basic_header * getGreHeader()
Definition: GreLayer.h:216
bool setSequenceNumber(uint32_t seqNumber)
gre1_header * getGreHeader()
Definition: GreLayer.h:326
std::string toString()
uint8_t ackSequenceNumBit
Definition: GreLayer.h:52
Definition: ProtocolType.h:224
Definition: ProtocolType.h:116
bool setAcknowledgmentNum(uint32_t ackNum)
OsiModelLayer getOsiModelLayer()
Definition: GreLayer.h:419
uint16_t protocol
Definition: GreLayer.h:99
bool getAcknowledgmentNum(uint32_t &ackNum)
void parseNextLayer()
bool getSequenceNumber(uint32_t &seqNumber)
uint16_t payloadLength
Definition: GreLayer.h:80
ppp_pptp_header * getPPP_PPTPHeader()
Definition: GreLayer.h:396
uint16_t protocol
Definition: GreLayer.h:67
size_t getHeaderLen()
Definition: GreLayer.h:409
Definition: GreLayer.h:77
bool setChecksum(uint16_t checksum)
uint8_t checksumBit
Definition: GreLayer.h:25
Definition: Layer.h:70
bool setKey(uint32_t key)
bool unsetAcknowledgmentNum()
bool getOffset(uint16_t &offset)
void computeCalculateFields()
bool getChecksum(uint16_t &checksum)
void computeCalculateFields()
Definition: GreLayer.h:108
Definition: Packet.h:26
uint8_t keyBit
Definition: GreLayer.h:25
uint8_t version
Definition: GreLayer.h:52
static ProtocolType getGREVersion(uint8_t *greData, size_t greDataLen)
uint8_t routingBit
Definition: GreLayer.h:25
OsiModelLayer
Definition: ProtocolType.h:213
bool getKey(uint32_t &key)
Definition: ProtocolType.h:220
GREv1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:308
GREv0Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:198
Definition: GreLayer.h:21
uint8_t sequenceNumBit
Definition: GreLayer.h:25
uint8_t flags
Definition: GreLayer.h:52
OsiModelLayer getOsiModelLayer()
Definition: GreLayer.h:161
std::string toString()
ProtocolType
Definition: ProtocolType.h:16
Definition: GreLayer.h:298
uint8_t recursionControl
Definition: GreLayer.h:25
Definition: GreLayer.h:92
void computeCalculateFields()
Definition: ProtocolType.h:111
bool unsetSequenceNumber()
uint8_t control
Definition: GreLayer.h:97
Definition: GreLayer.h:188
Definition: ProtocolType.h:126
uint8_t address
Definition: GreLayer.h:95
uint8_t strictSourceRouteBit
Definition: GreLayer.h:25
PPP_PPTPLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:381
uint16_t callID
Definition: GreLayer.h:82
size_t getHeaderLen()
The main namespace for the PcapPlusPlus lib.
Definition: GreLayer.h:371
std::string toString()
Definition: GreLayer.h:417