PcapPlusPlus  23.09
TpktLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_TPKT_LAYER
2 #define PACKETPP_TPKT_LAYER
3 
4 #include "EthLayer.h"
5 #include "Layer.h"
6 
8 
13 namespace pcpp
14 {
15 
20 #pragma pack(push, 1)
21  struct tpkthdr
22  {
24  uint8_t version;
26  uint8_t reserved;
28  uint16_t length;
29  };
30 #pragma pack(pop)
31 
36  class TpktLayer : public Layer
37  {
38  public:
46  TpktLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
47  : Layer(data, dataLen, prevLayer, packet)
48  {
49  m_Protocol = TPKT;
50  }
51 
57  TpktLayer(uint8_t version, uint16_t length);
58 
59  virtual ~TpktLayer() {}
60 
64  uint8_t getReserved() const;
65 
69  uint8_t getVersion() const;
70 
74  uint16_t getLength() const;
75 
80  void setVersion(uint8_t version) const;
81 
86  void setLength(uint16_t length) const;
87 
91  size_t getHeaderLen() const override { return sizeof(tpkthdr); }
92 
96  void computeCalculateFields() override {}
97 
101  void parseNextLayer() override;
102 
109  static bool isTpktPort(uint16_t portSrc, uint16_t portDst) { return portSrc == 102 || portDst == 102; }
110 
117  static bool isDataValid(const uint8_t *data, size_t dataSize) { return data && dataSize >= sizeof(tpkthdr); }
118 
119  std::string toString() const override;
120 
122 
123  private:
130  tpkthdr *getTpktHeader() const { return (tpkthdr *)m_Data; }
131  };
132 
133 } // namespace pcpp
134 #endif // PACKETPP_TPKT_LAYER
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:333
Definition: TpktLayer.h:21
static bool isDataValid(const uint8_t *data, size_t dataSize)
Definition: TpktLayer.h:117
Definition: Layer.h:70
void computeCalculateFields() override
Definition: TpktLayer.h:96
Definition: Packet.h:26
uint8_t version
Definition: TpktLayer.h:24
Definition: TpktLayer.h:36
static bool isTpktPort(uint16_t portSrc, uint16_t portDst)
Definition: TpktLayer.h:109
uint16_t length
Definition: TpktLayer.h:28
Definition: ProtocolType.h:342
OsiModelLayer getOsiModelLayer() const override
Definition: TpktLayer.h:121
uint8_t reserved
Definition: TpktLayer.h:26
const ProtocolType TPKT
Definition: ProtocolType.h:303
TpktLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: TpktLayer.h:46
size_t getHeaderLen() const override
Definition: TpktLayer.h:91