PcapPlusPlus  19.12
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 
154  void parseNextLayer();
155 
159  size_t getHeaderLen() const;
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) const;
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  gre_basic_header* getGreHeader() const { 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) const;
253 
260  bool getKey(uint32_t& key) const;
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() const;
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  gre1_header* getGreHeader() const { return (gre1_header*)m_Data; }
327 
334  bool getAcknowledgmentNum(uint32_t& ackNum) const;
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() const;
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  ppp_pptp_header* getPPP_PPTPHeader() const { return (ppp_pptp_header*)m_Data; }
397 
398 
399  // implement abstract methods
400 
404  void parseNextLayer();
405 
409  size_t getHeaderLen() const { return sizeof(ppp_pptp_header); }
410 
415  void computeCalculateFields();
416 
417  std::string toString() const { return "PPP for PPTP Layer"; }
418 
420 
421  };
422 
423 } // namespace pcpp
424 
425 #endif /* PACKETPP_GRE_LAYER */
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:224
pcpp::ppp_pptp_header
Definition: GreLayer.h:92
pcpp::Packet
Definition: Packet.h:26
pcpp::gre_basic_header::sequenceNumBit
uint8_t sequenceNumBit
Definition: GreLayer.h:25
pcpp::GREv1
Definition: ProtocolType.h:116
pcpp::PPP_PPTPLayer::getPPP_PPTPHeader
ppp_pptp_header * getPPP_PPTPHeader() const
Definition: GreLayer.h:396
pcpp::GreLayer::parseNextLayer
void parseNextLayer()
Layer.h
pcpp::GREv0Layer::unsetChecksum
bool unsetChecksum()
pcpp::GreLayer::setSequenceNumber
bool setSequenceNumber(uint32_t seqNumber)
pcpp::GREv1Layer::setAcknowledgmentNum
bool setAcknowledgmentNum(uint32_t ackNum)
pcpp::GREv1Layer::computeCalculateFields
void computeCalculateFields()
pcpp::gre1_header::payloadLength
uint16_t payloadLength
Definition: GreLayer.h:80
pcpp::PPP_PPTPLayer::getHeaderLen
size_t getHeaderLen() const
Definition: GreLayer.h:409
pcpp::PPP_PPTP
Definition: ProtocolType.h:126
pcpp::GREv0Layer::getOffset
bool getOffset(uint16_t &offset) const
pcpp::gre_basic_header::flags
uint8_t flags
Definition: GreLayer.h:52
pcpp::OsiModelNetworkLayer
Definition: ProtocolType.h:231
pcpp::gre1_header
Definition: GreLayer.h:77
pcpp::PPP_PPTPLayer::computeCalculateFields
void computeCalculateFields()
pcpp::gre_basic_header::keyBit
uint8_t keyBit
Definition: GreLayer.h:25
pcpp::GREv1Layer
Definition: GreLayer.h:298
pcpp::gre_basic_header::checksumBit
uint8_t checksumBit
Definition: GreLayer.h:25
pcpp::ProtocolType
ProtocolType
Definition: ProtocolType.h:16
pcpp::GreLayer::getHeaderLen
size_t getHeaderLen() const
pcpp::ppp_pptp_header::control
uint8_t control
Definition: GreLayer.h:97
pcpp::GREv0Layer::getChecksum
bool getChecksum(uint16_t &checksum)
pcpp::gre_basic_header::ackSequenceNumBit
uint8_t ackSequenceNumBit
Definition: GreLayer.h:52
pcpp::gre_basic_header::routingBit
uint8_t routingBit
Definition: GreLayer.h:25
pcpp::PPP_PPTPLayer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: GreLayer.h:419
pcpp::GREv0Layer::unsetKey
bool unsetKey()
pcpp::GREv0
Definition: ProtocolType.h:111
pcpp::gre_basic_header::strictSourceRouteBit
uint8_t strictSourceRouteBit
Definition: GreLayer.h:25
pcpp::GreLayer::getGREVersion
static ProtocolType getGREVersion(uint8_t *greData, size_t greDataLen)
pcpp::GreLayer
Definition: GreLayer.h:108
pcpp::GREv0Layer
Definition: GreLayer.h:188
pcpp::GreLayer::unsetSequenceNumber
bool unsetSequenceNumber()
pcpp::GREv0Layer::getKey
bool getKey(uint32_t &key) const
pcpp::GREv1Layer::GREv1Layer
GREv1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:308
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::PPP_PPTPLayer::toString
std::string toString() const
Definition: GreLayer.h:417
pcpp::GREv0Layer::setChecksum
bool setChecksum(uint16_t checksum)
pcpp::PPP_PPTPLayer::PPP_PPTPLayer
PPP_PPTPLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:381
pcpp::OsiModelSesionLayer
Definition: ProtocolType.h:235
pcpp::GREv0Layer::GREv0Layer
GREv0Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GreLayer.h:198
pcpp::GREv1Layer::getGreHeader
gre1_header * getGreHeader() const
Definition: GreLayer.h:326
pcpp::GREv0Layer::setKey
bool setKey(uint32_t key)
pcpp::PPP_PPTPLayer
Definition: GreLayer.h:371
pcpp::Layer
Definition: Layer.h:70
pcpp::PPP_PPTPLayer::parseNextLayer
void parseNextLayer()
pcpp::gre_basic_header
Definition: GreLayer.h:21
pcpp::GREv0Layer::toString
std::string toString() const
pcpp::gre_basic_header::recursionControl
uint8_t recursionControl
Definition: GreLayer.h:25
pcpp::GreLayer::getSequenceNumber
bool getSequenceNumber(uint32_t &seqNumber) const
pcpp::GREv0Layer::GREv0Layer
GREv0Layer()
pcpp::ppp_pptp_header::protocol
uint16_t protocol
Definition: GreLayer.h:99
pcpp::ppp_pptp_header::address
uint8_t address
Definition: GreLayer.h:95
pcpp::gre1_header::callID
uint16_t callID
Definition: GreLayer.h:82
pcpp::GREv1Layer::toString
std::string toString() const
pcpp::GreLayer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: GreLayer.h:161
pcpp::GREv1Layer::unsetAcknowledgmentNum
bool unsetAcknowledgmentNum()
pcpp::GREv0Layer::getGreHeader
gre_basic_header * getGreHeader() const
Definition: GreLayer.h:216
pcpp::GREv0Layer::computeCalculateFields
void computeCalculateFields()
pcpp::GREv1Layer::getAcknowledgmentNum
bool getAcknowledgmentNum(uint32_t &ackNum) const
pcpp::gre_basic_header::protocol
uint16_t protocol
Definition: GreLayer.h:67
pcpp::gre_basic_header::version
uint8_t version
Definition: GreLayer.h:52