Coverage Report

Created: 2026-10-17 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/src/IPLayer.cpp
Line
Count
Source
1
#include "IPLayer.h"
2
3
namespace pcpp
4
{
5
  ProtocolType IPLayer::getIPVersion(uint8_t const* data, size_t dataLen)
6
2.23k
  {
7
    // The data requires at least 1 byte of valid buffer
8
2.23k
    if (data == nullptr || dataLen < 1)
9
0
    {
10
0
      return UnknownProtocol;
11
0
    }
12
13
    // The first 4 bits of the first byte of the IP header represent the IP version
14
2.23k
    uint8_t version = data[0] >> 4;
15
16
2.23k
    switch (version)
17
2.23k
    {
18
2.08k
    case 4:
19
2.08k
      return IPv4;
20
0
    case 6:
21
0
      return IPv6;
22
154
    default:
23
154
      return UnknownProtocol;
24
2.23k
    }
25
2.23k
  }
26
}  // namespace pcpp