Coverage Report

Created: 2026-02-26 06:41

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
431
  {
7
    // The data requires at least 1 byte of valid buffer
8
431
    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
431
    uint8_t version = data[0] >> 4;
15
16
431
    switch (version)
17
431
    {
18
96
    case 4:
19
96
      return IPv4;
20
87
    case 6:
21
87
      return IPv6;
22
248
    default:
23
248
      return UnknownProtocol;
24
431
    }
25
431
  }
26
}  // namespace pcpp