/src/PcapPlusPlus/Packet++/header/LLCLayer.h
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | #include "Layer.h" |
4 | | |
5 | | /// @file |
6 | | |
7 | | /// @namespace pcpp |
8 | | /// @brief The main namespace for the PcapPlusPlus lib |
9 | | namespace pcpp |
10 | | { |
11 | | #pragma pack(push, 1) |
12 | | /// @struct llc_header |
13 | | /// Logical Link Control (LLC) header |
14 | | struct llc_header |
15 | | { |
16 | | /// Destination Service Access Point |
17 | | uint8_t dsap, |
18 | | /// Source Service Access Point |
19 | | ssap, |
20 | | /// Control Field |
21 | | control; |
22 | | }; |
23 | | #pragma pack(pop) |
24 | | static_assert(sizeof(llc_header) == 3, "llc_header size is not 3 bytes"); |
25 | | |
26 | | /// @class LLCLayer |
27 | | /// Represents Logical Link Control layer messages |
28 | | class LLCLayer : public Layer |
29 | | { |
30 | | public: |
31 | | /// A constructor that creates the layer from an existing packet raw data |
32 | | /// @param[in] data A pointer to the raw data (will be casted to llc_header) |
33 | | /// @param[in] dataLen Size of the data in bytes |
34 | | /// @param[in] prevLayer A pointer to the previous layer |
35 | | /// @param[in] packet A pointer to the Packet instance where layer will be stored in |
36 | | LLCLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) |
37 | 962 | : Layer(data, dataLen, prevLayer, packet, LLC) |
38 | 962 | {} |
39 | | |
40 | | /// A constructor that creates the LLC layer from provided values |
41 | | /// @param[in] dsap Destination Service Access Point |
42 | | /// @param[in] ssap Source Service Access Point |
43 | | /// @param[in] control Control Field |
44 | | LLCLayer(uint8_t dsap, uint8_t ssap, uint8_t control); |
45 | | |
46 | | /// Get a pointer to Logical Link Control (LLC) layer header |
47 | | /// @return Pointer to LLC header |
48 | | inline llc_header* getLlcHeader() const |
49 | 962 | { |
50 | 962 | return reinterpret_cast<llc_header*>(m_Data); |
51 | 962 | }; |
52 | | |
53 | | // overridden methods |
54 | | |
55 | | /// Parses the next layer. Currently only STP supported as next layer |
56 | | void parseNextLayer() override; |
57 | | |
58 | | /// Does nothing for this layer |
59 | | void computeCalculateFields() override |
60 | 187 | {} |
61 | | |
62 | | /// @return Get the size of the LLC header |
63 | | size_t getHeaderLen() const override |
64 | 187 | { |
65 | 187 | return sizeof(llc_header); |
66 | 187 | } |
67 | | |
68 | | /// @return Returns the protocol info as readable string |
69 | | std::string toString() const override; |
70 | | |
71 | | /// @return The OSI layer level of LLC (Data Link Layer). |
72 | | OsiModelLayer getOsiModelLayer() const override |
73 | 187 | { |
74 | 187 | return OsiModelDataLinkLayer; |
75 | 187 | } |
76 | | |
77 | | /// A static method that validates the input data |
78 | | /// @param[in] data The pointer to the beginning of a byte stream of an LLC packet |
79 | | /// @param[in] dataLen The length of the byte stream |
80 | | /// @return True if the data is valid and can represent an LLC packet |
81 | | static bool isDataValid(const uint8_t* data, size_t dataLen); |
82 | | }; |
83 | | |
84 | | } // namespace pcpp |