PcapPlusPlus  Next
TpktLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "EthLayer.h"
4 #include "Layer.h"
5 
7 
12 namespace pcpp
13 {
14 
19 #pragma pack(push, 1)
20  struct tpkthdr
21  {
23  uint8_t version;
25  uint8_t reserved;
27  uint16_t length;
28  };
29 #pragma pack(pop)
30 
35  class TpktLayer : public Layer
36  {
37  public:
45  TpktLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
46  : Layer(data, dataLen, prevLayer, packet, TPKT)
47  {}
48 
54  TpktLayer(uint8_t version, uint16_t length);
55 
56  ~TpktLayer() override = default;
57 
61  uint8_t getReserved() const;
62 
66  uint8_t getVersion() const;
67 
71  uint16_t getLength() const;
72 
77  void setVersion(uint8_t version) const;
78 
83  void setLength(uint16_t length) const;
84 
88  size_t getHeaderLen() const override
89  {
90  return sizeof(tpkthdr);
91  }
92 
96  void computeCalculateFields() override
97  {}
98 
102  void parseNextLayer() override;
103 
110  static bool isTpktPort(uint16_t portSrc, uint16_t portDst)
111  {
112  return portSrc == 102 || portDst == 102;
113  }
114 
121  static bool isDataValid(const uint8_t* data, size_t dataSize)
122  {
123  return data && dataSize >= sizeof(tpkthdr);
124  }
125 
126  std::string toString() const override;
127 
129  {
130  return OsiModelTransportLayer;
131  }
132 
133  private:
140  tpkthdr* getTpktHeader() const
141  {
142  return reinterpret_cast<tpkthdr*>(m_Data);
143  }
144  };
145 
146 } // namespace pcpp
Definition: Layer.h:69
Definition: Packet.h:27
Definition: TpktLayer.h:36
void setVersion(uint8_t version) const
size_t getHeaderLen() const override
Definition: TpktLayer.h:88
std::string toString() const override
uint8_t getVersion() const
TpktLayer(uint8_t version, uint16_t length)
uint16_t getLength() const
static bool isTpktPort(uint16_t portSrc, uint16_t portDst)
Definition: TpktLayer.h:110
uint8_t getReserved() const
void computeCalculateFields() override
Definition: TpktLayer.h:96
TpktLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: TpktLayer.h:45
static bool isDataValid(const uint8_t *data, size_t dataSize)
Definition: TpktLayer.h:121
void parseNextLayer() override
void setLength(uint16_t length) const
OsiModelLayer getOsiModelLayer() const override
Definition: TpktLayer.h:128
The main namespace for the PcapPlusPlus lib.
const ProtocolType TPKT
Definition: ProtocolType.h:308
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelTransportLayer
Definition: ProtocolType.h:372
Definition: TpktLayer.h:21
uint8_t version
Definition: TpktLayer.h:23
uint8_t reserved
Definition: TpktLayer.h:25
uint16_t length
Definition: TpktLayer.h:27