PcapPlusPlus  21.11
pcpp::IPFilter Class Reference

#include <PcapFilter.h>

Inheritance diagram for pcpp::IPFilter:
pcpp::IFilterWithDirection pcpp::GeneralFilter

Public Member Functions

 IPFilter (const std::string &ipAddress, Direction dir)
 
 IPFilter (const std::string &ipAddress, Direction dir, const std::string &ipv4Mask)
 
 IPFilter (const std::string &ipAddress, Direction dir, int len)
 
void parseToString (std::string &result)
 
void setAddr (const std::string &ipAddress)
 
void setMask (const std::string &ipv4Mask)
 
void setLen (int len)
 
- Public Member Functions inherited from pcpp::IFilterWithDirection
void setDirection (Direction dir)
 
- Public Member Functions inherited from pcpp::GeneralFilter
bool matchPacketWithFilter (RawPacket *rawPacket)
 
virtual ~GeneralFilter ()
 

Detailed Description

A class for representing IPv4 address filter, equivalent to "net src x.x.x.x" or "net dst x.x.x.x"
For deeper understanding of the filter concept please refer to PcapFilter.h

Constructor & Destructor Documentation

◆ IPFilter() [1/3]

pcpp::IPFilter::IPFilter ( const std::string &  ipAddress,
Direction  dir 
)
inline

The basic constructor that creates the filter from an IPv4 address and direction (source or destination)

Parameters
[in]ipAddressThe IPv4 address to build the filter with. If this address is not a valid IPv4 address an error will be written to log and parsing this filter will fail
[in]dirThe address direction to filter (source or destination)

◆ IPFilter() [2/3]

pcpp::IPFilter::IPFilter ( const std::string &  ipAddress,
Direction  dir,
const std::string &  ipv4Mask 
)
inline

A constructor that enable to filter only part of the address by using a mask (aka subnet). For example: "filter only IP addresses that matches the subnet 10.0.0.x"

Parameters
[in]ipAddressThe IPv4 address to use. Only the part of the address that is not masked will be matched. For example: if the address is "1.2.3.4" and the mask is "255.255.255.0" than the part of the address that will be matched is "1.2.3.X". If this address is not a valid IPv4 address an error will be written to log and parsing this filter will fail
[in]dirThe address direction to filter (source or destination)
[in]ipv4MaskThe mask to use. Mask should also be in a valid IPv4 format (i.e x.x.x.x), otherwise parsing this filter will fail

◆ IPFilter() [3/3]

pcpp::IPFilter::IPFilter ( const std::string &  ipAddress,
Direction  dir,
int  len 
)
inline

A constructor that enables to filter by a subnet. For example: "filter only IP addresses that matches the subnet 10.0.0.3/24" which means the part of the address that will be matched is "10.0.0.X"

Parameters
[in]ipAddressThe IPv4 address to use. Only the part of the address that is not masked will be matched. For example: if the address is "1.2.3.4" and the subnet is "/24" than the part of the address that will be matched is "1.2.3.X". If this address is not a valid IPv4 address an error will be written to log and parsing this filter will fail
[in]dirThe address direction to filter (source or destination)
[in]lenThe subnet to use (e.g "/24")

Member Function Documentation

◆ parseToString()

void pcpp::IPFilter::parseToString ( std::string &  result)
virtual

A method that parses the class instance into BPF string format

Parameters
[out]resultAn empty string that the parsing will be written into. If the string isn't empty, its content will be overridden
Returns
No return value

Implements pcpp::GeneralFilter.

◆ setAddr()

void pcpp::IPFilter::setAddr ( const std::string &  ipAddress)
inline

Set the IPv4 address

Parameters
[in]ipAddressThe IPv4 address to build the filter with. If this address is not a valid IPv4 address an error will be written to log and parsing this filter will fail

◆ setLen()

void pcpp::IPFilter::setLen ( int  len)
inline

Set the subnet

Parameters
[in]lenThe subnet to use (e.g "/24")

◆ setMask()

void pcpp::IPFilter::setMask ( const std::string &  ipv4Mask)
inline

Set the IPv4 mask

Parameters
[in]ipv4MaskThe mask to use. Mask should also be in a valid IPv4 format (i.e x.x.x.x), otherwise parsing this filter will fail