Coverage Report

Created: 2025-07-11 07:47

/src/PcapPlusPlus/Packet++/src/EthDot3Layer.cpp
Line
Count
Source (jump to first uncovered line)
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
445
  {
26
445
    if (m_DataLen <= sizeof(ether_dot3_header))
27
0
      return;
28
29
445
    uint8_t* payload = m_Data + sizeof(ether_dot3_header);
30
445
    size_t payloadLen = m_DataLen - sizeof(ether_dot3_header);
31
32
445
    if (LLCLayer::isDataValid(payload, payloadLen))
33
316
      m_NextLayer = new LLCLayer(payload, payloadLen, this, m_Packet);
34
129
    else
35
129
      m_NextLayer = new PayloadLayer(payload, payloadLen, this, m_Packet);
36
445
  }
37
38
  std::string EthDot3Layer::toString() const
39
244
  {
40
244
    return "IEEE 802.3 Ethernet, Src: " + getSourceMac().toString() + ", Dst: " + getDestMac().toString();
41
244
  }
42
43
  bool EthDot3Layer::isDataValid(const uint8_t* data, size_t dataLen)
44
447
  {
45
447
    if (dataLen >= sizeof(ether_dot3_header))
46
445
    {
47
      // LSAPs: ... Such a length must, when considered as an
48
      // unsigned integer, be less than 0x5DC or it could be mistaken as
49
      // an Ethertype...
50
      //
51
      // From: https://tools.ietf.org/html/rfc5342#section-2.3.2.1
52
      // More: IEEE Std 802.3 Clause 3.2.6
53
445
      return be16toh(*reinterpret_cast<const uint16_t*>(data + 12)) <= static_cast<uint16_t>(0x05DC);
54
445
    }
55
2
    else
56
2
    {
57
2
      return false;
58
2
    }
59
447
  }
60
}  // namespace pcpp