Coverage Report

Created: 2025-07-11 07:47

/src/PcapPlusPlus/Packet++/header/IPLayer.h
Line
Count
Source
1
#pragma once
2
3
#include "IpAddress.h"
4
#include "Layer.h"
5
6
/// @file
7
8
/// @namespace pcpp
9
/// @brief The main namespace for the PcapPlusPlus lib
10
namespace pcpp
11
{
12
  /// @class IPLayer
13
  /// This is an interface (abstract class) implemented in the IP layers (IPv4Layer and IPv6Layer).
14
  /// It provides methods to fetch the source and destination IP addresses in an abdtract way
15
  /// that hides the IP type (IPv4 or IPv6). This is useful for use-cases in which the IP type doesn't matter.
16
  /// For example: if you're only interested in printing the IP address the IP type shouldn't matter.
17
  class IPLayer
18
  {
19
  protected:
20
357k
    IPLayer() = default;
21
22
  public:
23
    /// An abstract method to get the source IP address
24
    /// @return An IPAddress object containing the source address
25
    virtual IPAddress getSrcIPAddress() const = 0;
26
27
    /// An abstract method to get the destination IP address
28
    /// @return An IPAddress object containing the destination address
29
    virtual IPAddress getDstIPAddress() const = 0;
30
31
    /// An empty destructor
32
357k
    virtual ~IPLayer() = default;
33
34
    /// @brief Get the IP version of a given packet data.
35
    ///
36
    /// The buffer is expected to start with the IP header and contain at least the first byte of it.
37
    /// The method will recognize IPv4 and IPv6 headers and return the respective protocol constant.
38
    /// If the IP version is not recognized or the buffer is malformed, UnknownProtocol will be returned.
39
    ///
40
    /// @param[in] data A pointer to the packet data
41
    /// @param[in] dataLen The length of the packet data in bytes
42
    /// @return A ProtocolType representing the IP version of the packet data.
43
    static ProtocolType getIPVersion(uint8_t const* data, size_t dataLen);
44
  };
45
}  // namespace pcpp