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