PcapPlusPlus  Next
pcpp::PortRangeFilter Class Reference

#include <PcapFilter.h>

Inheritance diagram for pcpp::PortRangeFilter:
pcpp::IFilterWithDirection pcpp::GeneralFilter

Public Member Functions

 PortRangeFilter (uint16_t fromPort, uint16_t toPort, Direction dir)
 
void parseToString (std::string &result) const override
 
void setFromPort (uint16_t fromPort)
 
void setToPort (uint16_t toPort)
 
- Public Member Functions inherited from pcpp::IFilterWithDirection
void setDirection (Direction dir)
 
- Public Member Functions inherited from pcpp::GeneralFilter
virtual ~GeneralFilter ()=default
 Virtual destructor, frees the bpf program.
 
bool matchPacketWithFilter (RawPacket *rawPacket) const
 
bool matches (RawPacket const &rawPacket) const
 Match a raw packet against the filter. More...
 

Additional Inherited Members

- Protected Member Functions inherited from pcpp::GeneralFilter
bool cacheFilter () const
 Parse the filter and cache the compiled BPF program. More...
 
void invalidateCache () const
 Invalidate the cached BPF program. This method should be called whenever the filter changes.
 

Detailed Description

A class for filtering TCP or UDP port ranges, meaning match only packets which port is within this range, for example: "src portrange 1000-2000" will match only TCP or UDP traffic which source port is in the range of 1000

  • 2000

For deeper understanding of the filter concept please refer to PcapFilter.h

Constructor & Destructor Documentation

◆ PortRangeFilter()

pcpp::PortRangeFilter::PortRangeFilter ( uint16_t  fromPort,
uint16_t  toPort,
Direction  dir 
)
inline

A constructor that gets the port range the the direction and creates the filter with them

Parameters
[in]fromPortThe lower end of the port range
[in]toPortThe higher end of the port range
[in]dirThe port range direction to filter (source or destination)

Member Function Documentation

◆ parseToString()

void pcpp::PortRangeFilter::parseToString ( std::string &  result) const
overridevirtual

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

Implements pcpp::GeneralFilter.

◆ setFromPort()

void pcpp::PortRangeFilter::setFromPort ( uint16_t  fromPort)
inline

Set the lower end of the port range

Parameters
[in]fromPortThe lower end of the port range

◆ setToPort()

void pcpp::PortRangeFilter::setToPort ( uint16_t  toPort)
inline

Set the higher end of the port range

Parameters
[in]toPortThe higher end of the port range