Coverage Report

Created: 2023-01-17 06:15

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