/src/PcapPlusPlus/Packet++/header/EthDot3Layer.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "Layer.h" |
4 | | #include "MacAddress.h" |
5 | | |
6 | | /// @file |
7 | | |
8 | | /** |
9 | | * \namespace pcpp |
10 | | * \brief The main namespace for the PcapPlusPlus lib |
11 | | */ |
12 | | namespace pcpp |
13 | | { |
14 | | |
15 | | /** |
16 | | * @struct ether_dot3_header |
17 | | * Represents an IEEE 802.3 Ethernet header |
18 | | */ |
19 | | #pragma pack(push, 1) |
20 | | struct ether_dot3_header |
21 | | { |
22 | | /** Destination MAC */ |
23 | | uint8_t dstMac[6]; |
24 | | /** Source MAC */ |
25 | | uint8_t srcMac[6]; |
26 | | /** EtherType */ |
27 | | uint16_t length; |
28 | | }; |
29 | | #pragma pack(pop) |
30 | | |
31 | | /** |
32 | | * @class EthDot3Layer |
33 | | * Represents an IEEE 802.3 Ethernet protocol layer |
34 | | */ |
35 | | class EthDot3Layer : public Layer |
36 | | { |
37 | | public: |
38 | | |
39 | | /** |
40 | | * A constructor that creates the layer from an existing packet raw data |
41 | | * @param[in] data A pointer to the raw data (will be casted to ether_dot3_header) |
42 | | * @param[in] dataLen Size of the data in bytes |
43 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
44 | | */ |
45 | 9.50k | EthDot3Layer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, NULL, packet) { m_Protocol = EthernetDot3; } |
46 | | |
47 | | /** |
48 | | * A constructor that creates the layer from an existing packet raw data |
49 | | * @param[in] data A pointer to the raw data (will be casted to ether_header) |
50 | | * @param[in] dataLen Size of the data in bytes |
51 | | * @param[in] prevLayer A pointer to the previous layer |
52 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
53 | | */ |
54 | 2.73k | EthDot3Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = EthernetDot3; } |
55 | | |
56 | | /** |
57 | | * A constructor that creates a new IEEE 802.3 Ethernet header and allocates the data |
58 | | * @param[in] sourceMac The source MAC address |
59 | | * @param[in] destMac The destination MAC address |
60 | | * @param[in] length The frame length |
61 | | */ |
62 | | EthDot3Layer(const MacAddress& sourceMac, const MacAddress& destMac, uint16_t length); |
63 | | |
64 | 0 | ~EthDot3Layer() {} |
65 | | |
66 | | /** |
67 | | * Get a pointer to the Ethernet header. Notice this points directly to the data, so every change will change the actual packet data |
68 | | * @return A pointer to the ether_header |
69 | | */ |
70 | 10.4k | ether_dot3_header* getEthHeader() const { return (ether_dot3_header*)m_Data; } |
71 | | |
72 | | /** |
73 | | * Get the source MAC address |
74 | | * @return The source MAC address |
75 | | */ |
76 | 5.21k | MacAddress getSourceMac() const { return MacAddress(getEthHeader()->srcMac); } |
77 | | |
78 | | /** |
79 | | * Set source MAC address |
80 | | * @param sourceMac Source MAC to set |
81 | | */ |
82 | 0 | void setSourceMac(const MacAddress& sourceMac) { sourceMac.copyTo(getEthHeader()->srcMac); } |
83 | | |
84 | | /** |
85 | | * Get the destination MAC address |
86 | | * @return The destination MAC address |
87 | | */ |
88 | 5.21k | MacAddress getDestMac() const { return MacAddress(getEthHeader()->dstMac); } |
89 | | |
90 | | /** |
91 | | * Set destination MAC address |
92 | | * @param destMac Destination MAC to set |
93 | | */ |
94 | 0 | void setDestMac(const MacAddress& destMac) { destMac.copyTo(getEthHeader()->dstMac); } |
95 | | |
96 | | // implement abstract methods |
97 | | |
98 | | /** |
99 | | * Parses next layer |
100 | | */ |
101 | | void parseNextLayer(); |
102 | | |
103 | | /** |
104 | | * @return Size of ether_dot3_header |
105 | | */ |
106 | 2.60k | size_t getHeaderLen() const { return sizeof(ether_dot3_header); } |
107 | | |
108 | | /** |
109 | | * Does nothing for this layer |
110 | | */ |
111 | 2.60k | void computeCalculateFields() {} |
112 | | |
113 | | std::string toString() const; |
114 | | |
115 | 2.60k | OsiModelLayer getOsiModelLayer() const { return OsiModelDataLinkLayer; } |
116 | | |
117 | | /** |
118 | | * A static method that validates the input data |
119 | | * @param[in] data The pointer to the beginning of a byte stream of an IEEE 802.3 Eth packet |
120 | | * @param[in] dataLen The length of the byte stream |
121 | | * @return True if the data is valid and can represent an IEEE 802.3 Eth packet |
122 | | */ |
123 | | static bool isDataValid(const uint8_t* data, size_t dataLen); |
124 | | }; |
125 | | |
126 | | } // namespace pcpp |