PcapPlusPlus  24.09
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  virtual ~TpktLayer()
57  {}
58 
62  uint8_t getReserved() const;
63 
67  uint8_t getVersion() const;
68 
72  uint16_t getLength() const;
73 
78  void setVersion(uint8_t version) const;
79 
84  void setLength(uint16_t length) const;
85 
89  size_t getHeaderLen() const override
90  {
91  return sizeof(tpkthdr);
92  }
93 
97  void computeCalculateFields() override
98  {}
99 
103  void parseNextLayer() override;
104 
111  static bool isTpktPort(uint16_t portSrc, uint16_t portDst)
112  {
113  return portSrc == 102 || portDst == 102;
114  }
115 
122  static bool isDataValid(const uint8_t* data, size_t dataSize)
123  {
124  return data && dataSize >= sizeof(tpkthdr);
125  }
126 
127  std::string toString() const override;
128 
130  {
131  return OsiModelTransportLayer;
132  }
133 
134  private:
141  tpkthdr* getTpktHeader() const
142  {
143  return (tpkthdr*)m_Data;
144  }
145  };
146 
147 } // namespace pcpp
Definition: Layer.h:70
Definition: Packet.h:27
Definition: TpktLayer.h:36
void setVersion(uint8_t version) const
size_t getHeaderLen() const override
Definition: TpktLayer.h:89
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:111
uint8_t getReserved() const
void computeCalculateFields() override
Definition: TpktLayer.h:97
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:122
void parseNextLayer() override
void setLength(uint16_t length) const
OsiModelLayer getOsiModelLayer() const override
Definition: TpktLayer.h:129
The main namespace for the PcapPlusPlus lib.
const ProtocolType TPKT
Definition: ProtocolType.h:308
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelTransportLayer
Definition: ProtocolType.h:362
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