Coverage Report

Created: 2026-02-14 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/src/EthDot3Layer.cpp
Line
Count
Source
1
#include "EthDot3Layer.h"
2
#include "EndianPortable.h"
3
#include "PayloadLayer.h"
4
#include "LLCLayer.h"
5
6
#include <cstring>
7
8
namespace pcpp
9
{
10
0
  EthDot3Layer::EthDot3Layer(const MacAddress& sourceMac, const MacAddress& destMac, uint16_t length) : Layer()
11
0
  {
12
0
    const size_t headerLen = sizeof(ether_dot3_header);
13
0
    m_DataLen = headerLen;
14
0
    m_Data = new uint8_t[headerLen];
15
0
    memset(m_Data, 0, headerLen);
16
17
0
    ether_dot3_header* ethHdr = getEthHeader();
18
0
    destMac.copyTo(ethHdr->dstMac);
19
0
    sourceMac.copyTo(ethHdr->srcMac);
20
0
    ethHdr->length = be16toh(length);
21
0
    m_Protocol = Ethernet;
22
0
  }
23
24
  void EthDot3Layer::parseNextLayer()
25
10.9k
  {
26
10.9k
    if (m_DataLen <= sizeof(ether_dot3_header))
27
36
      return;
28
29
10.9k
    uint8_t* payload = m_Data + sizeof(ether_dot3_header);
30
10.9k
    size_t payloadLen = m_DataLen - sizeof(ether_dot3_header);
31
32
10.9k
    tryConstructNextLayerWithFallback<LLCLayer, PayloadLayer>(payload, payloadLen);
33
10.9k
  }
34
35
  std::string EthDot3Layer::toString() const
36
4.31k
  {
37
4.31k
    return "IEEE 802.3 Ethernet, Src: " + getSourceMac().toString() + ", Dst: " + getDestMac().toString();
38
4.31k
  }
39
40
  bool EthDot3Layer::isDataValid(const uint8_t* data, size_t dataLen)
41
11.3k
  {
42
11.3k
    if (dataLen >= sizeof(ether_dot3_header))
43
10.9k
    {
44
      // LSAPs: ... Such a length must, when considered as an
45
      // unsigned integer, be less than 0x5DC or it could be mistaken as
46
      // an Ethertype...
47
      //
48
      // From: https://tools.ietf.org/html/rfc5342#section-2.3.2.1
49
      // More: IEEE Std 802.3 Clause 3.2.6
50
10.9k
      return be16toh(*reinterpret_cast<const uint16_t*>(data + 12)) <= static_cast<uint16_t>(0x05DC);
51
10.9k
    }
52
328
    else
53
328
    {
54
328
      return false;
55
328
    }
56
11.3k
  }
57
}  // namespace pcpp