Coverage Report

Created: 2026-10-17 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/src/NullLoopbackLayer.cpp
Line
Count
Source
1
#include "NullLoopbackLayer.h"
2
#include "EthLayer.h"
3
#include "IPv4Layer.h"
4
#include "IPv6Layer.h"
5
#include "PayloadLayer.h"
6
7
namespace pcpp
8
{
9
10
495
#define BSWAP16(x) (((x) >> 8) | ((x) << 8))
11
16.0k
#define BSWAP32(x) (((x) >> 24) | (((x) & 0x00FF'0000) >> 8) | (((x) & 0x0000'FF00) << 8) | ((x) << 24))
12
13
  constexpr uint32_t Ieee8023MaxLength = 0x5dc;
14
15
  NullLoopbackLayer::NullLoopbackLayer(uint32_t family)
16
0
  {
17
0
    allocData(sizeof(uint32_t));
18
0
    m_Protocol = NULL_LOOPBACK;
19
20
0
    setFamily(family);
21
0
  }
22
23
  uint32_t NullLoopbackLayer::getFamily() const
24
19.3k
  {
25
19.3k
    uint32_t family = *(reinterpret_cast<uint32_t*>(m_Data));
26
19.3k
    if ((family & 0xFFFF'0000) != 0)
27
16.5k
    {
28
16.5k
      if ((family & 0xFF00'0000) == 0 && (family & 0x00FF'0000) < 0x0006'0000)
29
558
      {
30
558
        family >>= 16;
31
558
      }
32
16.0k
      else
33
16.0k
      {
34
16.0k
        family = BSWAP32(family);
35
16.0k
      }
36
16.5k
    }
37
2.72k
    else if ((family & 0x0000'00FF) == 0 && (family & 0x0000'FF00) < 0x0000'0600)
38
495
    {
39
495
      family = BSWAP16(family & 0xFFFF);
40
495
    }
41
42
19.3k
    return family;
43
19.3k
  }
44
45
  void NullLoopbackLayer::setFamily(uint32_t family)
46
0
  {
47
0
    *m_Data = family;
48
0
  }
49
50
  void NullLoopbackLayer::parseNextLayer()
51
19.3k
  {
52
19.3k
    uint8_t* payload = m_Data + sizeof(uint32_t);
53
19.3k
    size_t payloadLen = m_DataLen - sizeof(uint32_t);
54
55
19.3k
    uint32_t family = getFamily();
56
19.3k
    if (family > Ieee8023MaxLength)
57
14.6k
    {
58
14.6k
      uint16_t ethType = static_cast<uint16_t>(family);
59
14.6k
      switch (ethType)
60
14.6k
      {
61
9.44k
      case PCPP_ETHERTYPE_IP:
62
9.44k
      {
63
9.44k
        tryConstructNextLayerWithFallback<IPv4Layer, PayloadLayer>(payload, payloadLen);
64
9.44k
        return;
65
0
      }
66
0
      case PCPP_ETHERTYPE_IPV6:
67
0
      {
68
0
        tryConstructNextLayerWithFallback<IPv6Layer, PayloadLayer>(payload, payloadLen);
69
0
        return;
70
0
      }
71
5.16k
      default:
72
5.16k
      {
73
5.16k
        constructNextLayer<PayloadLayer>(payload, payloadLen);
74
5.16k
        return;
75
0
      }
76
14.6k
      }
77
14.6k
    }
78
79
4.68k
    switch (family)
80
4.68k
    {
81
544
    case PCPP_BSD_AF_INET:
82
544
    {
83
544
      tryConstructNextLayerWithFallback<IPv4Layer, PayloadLayer>(payload, payloadLen);
84
544
      break;
85
0
    }
86
578
    case PCPP_BSD_AF_INET6_BSD:
87
578
    case PCPP_BSD_AF_INET6_FREEBSD:
88
3.05k
    case PCPP_BSD_AF_INET6_DARWIN:
89
3.05k
    {
90
3.05k
      tryConstructNextLayerWithFallback<IPv6Layer, PayloadLayer>(payload, payloadLen);
91
3.05k
      break;
92
578
    }
93
1.08k
    default:
94
1.08k
    {
95
1.08k
      constructNextLayer<PayloadLayer>(payload, payloadLen);
96
1.08k
      break;
97
578
    }
98
4.68k
    }
99
4.68k
  }
100
101
  std::string NullLoopbackLayer::toString() const
102
9.33k
  {
103
9.33k
    return "Null/Loopback";
104
9.33k
  }
105
106
  const FieldDescriptor NullLoopbackLayer::SerializedFields::Family{ Layer::SerializedFields::MaxID + 1, "family" };
107
108
  void NullLoopbackLayer::serializeLayer(ObjectScope& serializer) const
109
0
  {
110
0
    serializer.writeField(SerializedFields::Family, getFamily());
111
0
  }
112
113
}  // namespace pcpp