PcapPlusPlus  Next
CotpLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "EthLayer.h"
4 #include "Layer.h"
5 
7 
10 namespace pcpp
11 {
14 #pragma pack(push, 1)
15  struct cotphdr
16  {
18  uint8_t length;
20  uint8_t pduType;
22  uint8_t tpduNumber;
23  };
24 #pragma pack(pop)
25  static_assert(sizeof(cotphdr) == 3, "cotphdr size is not 3 bytes");
26 
29  class CotpLayer : public Layer
30  {
31  public:
37  CotpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
38  : Layer(data, dataLen, prevLayer, packet, COTP)
39  {}
40 
43  explicit CotpLayer(uint8_t tpduNumber);
44 
45  ~CotpLayer() override = default;
46 
48  uint8_t getLength() const;
49 
51  uint8_t getPduType() const;
52 
54  uint8_t getTpduNumber() const;
55 
57  size_t getHeaderLen() const override
58  {
59  return sizeof(cotphdr);
60  }
61 
64  void setLength(uint8_t length) const;
65 
68  void setPduType(uint8_t pduType) const;
69 
72  void setTpduNumber(uint8_t tpduNumber) const;
73 
75  void computeCalculateFields() override
76  {}
77 
79  void parseNextLayer() override;
80 
85  static bool isDataValid(const uint8_t* data, size_t dataSize);
86 
87  std::string toString() const override;
88 
90  {
92  }
93 
94  private:
95  cotphdr* getCotpHeader() const
96  {
97  return reinterpret_cast<cotphdr*>(m_Data);
98  }
99  };
100 
101 } // namespace pcpp
Definition: CotpLayer.h:30
uint8_t getTpduNumber() const
CotpLayer(uint8_t tpduNumber)
size_t getHeaderLen() const override
Definition: CotpLayer.h:57
uint8_t getPduType() const
OsiModelLayer getOsiModelLayer() const override
Definition: CotpLayer.h:89
uint8_t getLength() const
void setPduType(uint8_t pduType) const
CotpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: CotpLayer.h:37
std::string toString() const override
void setLength(uint8_t length) const
void setTpduNumber(uint8_t tpduNumber) const
void parseNextLayer() override
Currently parses the rest of the packet as a S7COMM or generic payload (PayloadLayer)
static bool isDataValid(const uint8_t *data, size_t dataSize)
void computeCalculateFields() override
Does nothing for this layer.
Definition: CotpLayer.h:75
Definition: Layer.h:60
Definition: Packet.h:22
The main namespace for the PcapPlusPlus lib.
const ProtocolType COTP
COTP protocol.
Definition: ProtocolType.h:200
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:225
@ OsiModelTransportLayer
Transport layer (layer 4)
Definition: ProtocolType.h:233
Definition: CotpLayer.h:16
uint8_t tpduNumber
TPDU number sequence.
Definition: CotpLayer.h:22
uint8_t length
length
Definition: CotpLayer.h:18
uint8_t pduType
PDU type identifier.
Definition: CotpLayer.h:20