/src/PcapPlusPlus/Packet++/header/CotpLayer.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "EthLayer.h" |
4 | | #include "Layer.h" |
5 | | |
6 | | namespace pcpp |
7 | | { |
8 | | |
9 | | /** |
10 | | * @struct cotphdr |
11 | | * Represents a COTP protocol header |
12 | | */ |
13 | | #pragma pack(push, 1) |
14 | | typedef struct |
15 | | { |
16 | | /** length */ |
17 | | uint8_t length; |
18 | | /** PDU type identifier */ |
19 | | uint8_t pduType ; |
20 | | /** TPDU number sequence*/ |
21 | | uint8_t tpduNumber; |
22 | | } cotphdr; |
23 | | #pragma pack(pop) |
24 | | |
25 | | /** |
26 | | * @class CotpLayer |
27 | | * Represents a COTP (Connection Oriented Transport Protocol) |
28 | | */ |
29 | | class CotpLayer : public Layer |
30 | | { |
31 | | public: |
32 | | /** |
33 | | * A constructor that creates the layer from an existing packet raw data |
34 | | * @param[in] data A pointer to the raw data (will be casted to @ref cotphdr) |
35 | | * @param[in] dataLen Size of the data in bytes |
36 | | * @param[in] prevLayer A pointer to the previous layer |
37 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
38 | | */ |
39 | | CotpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) |
40 | | : Layer(data, dataLen, prevLayer, packet) |
41 | 606 | { |
42 | 606 | m_Protocol = COTP; |
43 | 606 | } |
44 | | |
45 | | /** |
46 | | * A constructor that allocates a new COTP header |
47 | | * @param[in] tpduNumber Protocol TPDU number |
48 | | */ |
49 | | explicit CotpLayer(uint8_t tpduNumber); |
50 | | |
51 | 0 | virtual ~CotpLayer() {} |
52 | | |
53 | | /** |
54 | | * @return COTP length |
55 | | */ |
56 | | uint8_t getLength() const; |
57 | | |
58 | | /** |
59 | | * @return COTP PDU type |
60 | | */ |
61 | | uint8_t getPduType() const; |
62 | | |
63 | | /** |
64 | | * @return COTP TPDU number |
65 | | */ |
66 | | uint8_t getTpduNumber() const; |
67 | | |
68 | | /** |
69 | | * @return Size of @ref cotphdr |
70 | | */ |
71 | 707 | size_t getHeaderLen() const override { return sizeof(cotphdr); } |
72 | | |
73 | | /** |
74 | | * Set the value of the length |
75 | | * @param[in] length The value of the length |
76 | | */ |
77 | | void setLength(uint8_t length) const; |
78 | | |
79 | | /** |
80 | | * Set the value of the version |
81 | | * @param[in] pduType The number of the PDU type |
82 | | */ |
83 | | void setPduType(uint8_t pduType) const; |
84 | | |
85 | | /** |
86 | | * Set the value of the version |
87 | | * @param[in] tpduNumber The value of the TPDU number |
88 | | */ |
89 | | void setTpduNumber(uint8_t tpduNumber) const; |
90 | | |
91 | | /** |
92 | | * Does nothing for this layer |
93 | | */ |
94 | 101 | void computeCalculateFields() override {} |
95 | | |
96 | | /** |
97 | | * Currently parses the rest of the packet as a S7COMM or generic payload (PayloadLayer) |
98 | | */ |
99 | | void parseNextLayer() override; |
100 | | |
101 | | /** |
102 | | * A static method that takes a byte array and detects whether it is a COTP |
103 | | * @param[in] data A byte array |
104 | | * @param[in] dataSize The byte array size (in bytes) |
105 | | * @return True if the data looks like a valid COTP layer |
106 | | */ |
107 | | static bool isDataValid(const uint8_t *data, size_t dataSize); |
108 | | |
109 | | std::string toString() const override; |
110 | | |
111 | 101 | OsiModelLayer getOsiModelLayer() const override { return OsiModelTransportLayer; } |
112 | | |
113 | | private: |
114 | 0 | cotphdr *getCotpHeader() const { return (cotphdr *)m_Data; } |
115 | | }; |
116 | | |
117 | | } // namespace pcpp |