Coverage Report

Created: 2026-08-14 06:52

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
    allocData(headerLen);
14
15
0
    ether_dot3_header* ethHdr = getEthHeader();
16
0
    destMac.copyTo(ethHdr->dstMac);
17
0
    sourceMac.copyTo(ethHdr->srcMac);
18
0
    ethHdr->length = be16toh(length);
19
0
    m_Protocol = Ethernet;
20
0
  }
21
22
  void EthDot3Layer::parseNextLayer()
23
12.2k
  {
24
12.2k
    if (m_DataLen <= sizeof(ether_dot3_header))
25
378
      return;
26
27
11.8k
    uint8_t* payload = m_Data + sizeof(ether_dot3_header);
28
11.8k
    size_t payloadLen = m_DataLen - sizeof(ether_dot3_header);
29
30
11.8k
    tryConstructNextLayerWithFallback<LLCLayer, PayloadLayer>(payload, payloadLen);
31
11.8k
  }
32
33
  std::string EthDot3Layer::toString() const
34
5.93k
  {
35
5.93k
    return "IEEE 802.3 Ethernet, Src: " + getSourceMac().toString() + ", Dst: " + getDestMac().toString();
36
5.93k
  }
37
38
  bool EthDot3Layer::isDataValid(const uint8_t* data, size_t dataLen)
39
12.3k
  {
40
12.3k
    if (dataLen >= sizeof(ether_dot3_header))
41
12.2k
    {
42
      // LSAPs: ... Such a length must, when considered as an
43
      // unsigned integer, be less than 0x5DC or it could be mistaken as
44
      // an Ethertype...
45
      //
46
      // From: https://tools.ietf.org/html/rfc5342#section-2.3.2.1
47
      // More: IEEE Std 802.3 Clause 3.2.6
48
12.2k
      return be16toh(*reinterpret_cast<const uint16_t*>(data + 12)) <= static_cast<uint16_t>(0x05DC);
49
12.2k
    }
50
84
    else
51
84
    {
52
84
      return false;
53
84
    }
54
12.3k
  }
55
}  // namespace pcpp