PcapPlusPlus  Next
pcpp::IPLayer Class Referenceabstract

#include <IPLayer.h>

Inheritance diagram for pcpp::IPLayer:
pcpp::IPv4Layer pcpp::IPv6Layer

Public Member Functions

virtual IPAddress getSrcIPAddress () const =0
 
virtual IPAddress getDstIPAddress () const =0
 
virtual ~IPLayer ()=default
 An empty destructor.
 

Static Public Member Functions

static ProtocolType getIPVersion (uint8_t const *data, size_t dataLen)
 Get the IP version of a given packet data. More...
 

Detailed Description

This is an interface (abstract class) implemented in the IP layers (IPv4Layer and IPv6Layer). It provides methods to fetch the source and destination IP addresses in an abdtract way that hides the IP type (IPv4 or IPv6). This is useful for use-cases in which the IP type doesn't matter. For example: if you're only interested in printing the IP address the IP type shouldn't matter.

Member Function Documentation

◆ getDstIPAddress()

virtual IPAddress pcpp::IPLayer::getDstIPAddress ( ) const
pure virtual

An abstract method to get the destination IP address

Returns
An IPAddress object containing the destination address

Implemented in pcpp::IPv6Layer, and pcpp::IPv4Layer.

◆ getIPVersion()

static ProtocolType pcpp::IPLayer::getIPVersion ( uint8_t const *  data,
size_t  dataLen 
)
static

Get the IP version of a given packet data.

The buffer is expected to start with the IP header and contain at least the first byte of it. The method will recognize IPv4 and IPv6 headers and return the respective protocol constant. If the IP version is not recognized or the buffer is malformed, UnknownProtocol will be returned.

Parameters
[in]dataA pointer to the packet data
[in]dataLenThe length of the packet data in bytes
Returns
A ProtocolType representing the IP version of the packet data.

◆ getSrcIPAddress()

virtual IPAddress pcpp::IPLayer::getSrcIPAddress ( ) const
pure virtual

An abstract method to get the source IP address

Returns
An IPAddress object containing the source address

Implemented in pcpp::IPv6Layer, and pcpp::IPv4Layer.