73 void operator()(bpf_program* ptr)
const;
82 std::string m_FilterStr;
84 std::unique_ptr<bpf_program, internal::BpfProgramDeleter> m_Program;
161 const std::string m_FilterStr;
164 explicit BPFStringFilter(
const std::string& filterStr) : m_FilterStr(filterStr)
191 void parseDirection(std::string& directionAsString);
221 std::string parseOperator();
352 m_Address = ipAddress;
354 if (m_Address.
isIPv4() && newPrefixLen > 32u)
359 m_Network =
IPNetwork(m_Address, newPrefixLen);
372 m_Network =
IPNetwork(m_Address, netmask);
432 uint16_t m_TotalLength;
448 m_TotalLength = totalLength;
460 void portToString(uint16_t portAsInt);
505 m_FromPort = fromPort;
539 m_MacAddress = address;
551 uint16_t m_EtherType;
565 m_EtherType = etherType;
577 std::vector<GeneralFilter*> m_FilterList;
591 m_FilterList.push_back(filter);
605 m_FilterList.clear();
626 template <> constexpr
const char* getCompositeLogicOpDelimiter<CompositeLogicFilterOp::AND>()
630 template <> constexpr
const char* getCompositeLogicOpDelimiter<CompositeLogicFilterOp::OR>()
648 for (
auto it = m_FilterList.cbegin(); it != m_FilterList.cend(); ++it)
650 std::string innerFilter;
651 (*it)->parseToString(innerFilter);
652 result +=
'(' + innerFilter +
')';
653 if (m_FilterList.cend() - 1 != it)
655 result += internal::getCompositeLogicOpDelimiter<op>();
693 m_FilterToInverse = filterToInverse;
702 m_FilterToInverse = filterToInverse;
740 m_ProtoFamily = proto;
749 m_ProtoFamily = protoFamily;
840 uint8_t m_TcpFlagsBitMask;
851 : m_TcpFlagsBitMask(tcpFlagBitMask), m_MatchOption(matchOption)
861 m_TcpFlagsBitMask = tcpFlagBitMask;
862 m_MatchOption = matchOption;
875 uint16_t m_WindowSize;
891 m_WindowSize = windowSize;
constexpr const char * getCompositeLogicOpDelimiter()=delete
Definition: PcapFilter.h:759
ArpFilter(ArpOpcode opCode)
Definition: PcapFilter.h:766
void setOpCode(ArpOpcode opCode)
Definition: PcapFilter.h:773
void parseToString(std::string &result) override
Definition: PcapFilter.h:159
void parseToString(std::string &result) override
Definition: PcapFilter.h:80
bool matchPacketWithFilter(const RawPacket *rawPacket)
BpfFilterWrapper(const BpfFilterWrapper &other)
BpfFilterWrapper & operator=(const BpfFilterWrapper &other)
bool matchPacketWithFilter(const uint8_t *packetData, uint32_t packetDataLength, timespec packetTimestamp, uint16_t linkType)
BpfFilterWrapper()
A c'tor for this class.
bool setFilter(const std::string &filter, LinkLayerType linkType=LINKTYPE_ETHERNET)
Definition: PcapFilter.h:575
CompositeFilter()=default
An empty constructor for this class. Use addFilter() to add filters to the composite filter.
void removeFilter(GeneralFilter *filter)
void addFilter(GeneralFilter *filter)
Definition: PcapFilter.h:589
CompositeFilter(const std::vector< GeneralFilter * > &filters)
void setFilters(const std::vector< GeneralFilter * > &filters)
void clearAllFilters()
Remove all filters from the composite filter.
Definition: PcapFilter.h:603
Definition: PcapFilter.h:641
void parseToString(std::string &result) override
Definition: PcapFilter.h:645
Definition: PcapFilter.h:549
EtherTypeFilter(uint16_t etherType)
Definition: PcapFilter.h:556
void setEtherType(uint16_t etherType)
Definition: PcapFilter.h:563
void parseToString(std::string &result) override
Definition: PcapFilter.h:134
bool matchPacketWithFilter(RawPacket *rawPacket)
virtual ~GeneralFilter()=default
Virtual destructor, frees the bpf program.
virtual void parseToString(std::string &result)=0
Definition: PcapFilter.h:186
void setDirection(Direction dir)
Definition: PcapFilter.h:204
Definition: PcapFilter.h:216
void setOperator(FilterOperator op)
Definition: PcapFilter.h:234
Definition: IpAddress.h:276
bool isIPv4() const
Definition: IpAddress.h:331
Definition: PcapFilter.h:245
void setMask(const std::string &netmask)
Definition: PcapFilter.h:370
void clearMask()
Clears the subnet mask.
Definition: PcapFilter.h:376
void setAddr(const std::string &ipAddress)
Definition: PcapFilter.h:340
void setLen(const int len)
Definition: PcapFilter.h:385
IPFilter(const IPAddress &ipAddress, Direction dir, int len)
Definition: PcapFilter.h:315
IPFilter(const std::string &ipAddress, Direction dir, const std::string &netmask)
Definition: PcapFilter.h:276
IPFilter(const IPNetwork &network, Direction dir)
Definition: PcapFilter.h:323
void setNetwork(const IPNetwork &network)
Definition: PcapFilter.h:331
IPFilter(const std::string &ipAddress, Direction dir, int len)
Definition: PcapFilter.h:303
void clearLen()
Clears the subnet mask length.
Definition: PcapFilter.h:391
void parseToString(std::string &result) override
IPFilter(const std::string &ipAddress, Direction dir)
Definition: PcapFilter.h:256
IPFilter(const IPAddress &ipAddress, Direction dir)
Definition: PcapFilter.h:262
IPFilter(const IPAddress &ipAddress, Direction dir, const std::string &netmask)
Definition: PcapFilter.h:289
void setAddr(const IPAddress &ipAddress)
Definition: PcapFilter.h:350
Definition: IpAddress.h:607
IPAddress getNetworkPrefix() const
Definition: IpAddress.h:743
uint8_t getPrefixLen() const
Definition: IpAddress.h:729
Definition: IpAddress.h:28
Definition: PcapFilter.h:403
void parseToString(std::string &result) override
IPv4IDFilter(uint16_t ipID, FilterOperator op)
Definition: PcapFilter.h:411
void setIpID(uint16_t ipID)
Definition: PcapFilter.h:418
Definition: PcapFilter.h:430
void parseToString(std::string &result) override
void setTotalLength(uint16_t totalLength)
Definition: PcapFilter.h:446
IPv4TotalLengthFilter(uint16_t totalLength, FilterOperator op)
Definition: PcapFilter.h:438
Definition: PcapFilter.h:522
void parseToString(std::string &result) override
void setMacAddress(MacAddress address)
Definition: PcapFilter.h:537
MacAddressFilter(MacAddress address, Direction dir)
Definition: PcapFilter.h:530
Definition: MacAddress.h:21
Definition: PcapFilter.h:684
void setFilter(GeneralFilter *filterToInverse)
Definition: PcapFilter.h:700
void parseToString(std::string &result) override
NotFilter(GeneralFilter *filterToInverse)
Definition: PcapFilter.h:691
Definition: PcapFilter.h:457
PortFilter(uint16_t port, Direction dir)
void parseToString(std::string &result) override
void setPort(uint16_t port)
Definition: PcapFilter.h:472
Definition: PcapFilter.h:485
PortRangeFilter(uint16_t fromPort, uint16_t toPort, Direction dir)
Definition: PcapFilter.h:495
void setToPort(uint16_t toPort)
Definition: PcapFilter.h:510
void parseToString(std::string &result) override
void setFromPort(uint16_t fromPort)
Definition: PcapFilter.h:503
Definition: PcapFilter.h:716
void setProto(ProtocolType proto)
Definition: PcapFilter.h:738
ProtoFilter(ProtocolTypeFamily protoFamily)
Definition: PcapFilter.h:730
void setProto(ProtocolTypeFamily protoFamily)
Definition: PcapFilter.h:747
ProtoFilter(ProtocolType proto)
Definition: PcapFilter.h:724
void parseToString(std::string &result) override
Definition: RawPacket.h:269
Definition: PcapFilter.h:810
TcpFlags
An enum of all TCP flags that can be use in the filter.
Definition: PcapFilter.h:814
@ tcpSyn
TCP SYN flag.
Definition: PcapFilter.h:818
@ tcpFin
TCP FIN flag.
Definition: PcapFilter.h:816
@ tcpUrg
TCP URG flag.
Definition: PcapFilter.h:826
@ tcpAck
TCP ACK flag.
Definition: PcapFilter.h:824
@ tcpRst
TCP RST flag.
Definition: PcapFilter.h:820
@ tcpPush
TCP PSH flag.
Definition: PcapFilter.h:822
void parseToString(std::string &result) override
MatchOptions
Definition: PcapFilter.h:832
@ MatchAll
Match only packets that contain all flags defined in the filter.
Definition: PcapFilter.h:834
@ MatchOneAtLeast
Match packets that contain at least one of the flags defined in the filter.
Definition: PcapFilter.h:836
void setTcpFlagsBitMask(uint8_t tcpFlagBitMask, MatchOptions matchOption)
Definition: PcapFilter.h:859
TcpFlagsFilter(uint8_t tcpFlagBitMask, MatchOptions matchOption)
Definition: PcapFilter.h:850
Definition: PcapFilter.h:873
void setWindowSize(uint16_t windowSize)
Definition: PcapFilter.h:889
void parseToString(std::string &result) override
TcpWindowSizeFilter(uint16_t windowSize, FilterOperator op)
Definition: PcapFilter.h:882
Definition: PcapFilter.h:900
void parseToString(std::string &result) override
void setLength(uint16_t length)
Definition: PcapFilter.h:916
UdpLengthFilter(uint16_t length, FilterOperator op)
Definition: PcapFilter.h:909
Definition: PcapFilter.h:785
VlanFilter(uint16_t vlanId)
Definition: PcapFilter.h:792
void parseToString(std::string &result) override
void setVlanID(uint16_t vlanId)
Definition: PcapFilter.h:799
The main namespace for the PcapPlusPlus lib.
ArpOpcode
Definition: ArpLayer.h:50
uint8_t ProtocolType
Definition: ProtocolType.h:17
FilterOperator
Supported operators enum.
Definition: PcapFilter.h:52
@ GREATER_THAN
Greater than.
Definition: PcapFilter.h:58
@ EQUALS
Equals.
Definition: PcapFilter.h:54
@ GREATER_OR_EQUAL
Greater or equal.
Definition: PcapFilter.h:60
@ LESS_THAN
Less than.
Definition: PcapFilter.h:62
@ NOT_EQUALS
Not equals.
Definition: PcapFilter.h:56
@ LESS_OR_EQUAL
Less or equal.
Definition: PcapFilter.h:64
Direction
An enum that contains direction (source or destination)
Definition: PcapFilter.h:41
@ SRC_OR_DST
Source or destination.
Definition: PcapFilter.h:47
@ DST
Destination.
Definition: PcapFilter.h:45
@ SRC
Source.
Definition: PcapFilter.h:43
CompositeLogicFilterOp
Supported composite logic filter operators enum.
Definition: PcapFilter.h:611
@ OR
Logical OR operation.
@ AND
Logical AND operation.
uint32_t ProtocolTypeFamily
Definition: ProtocolType.h:23
LinkLayerType
Definition: RawPacket.h:25
@ LINKTYPE_ETHERNET
Definition: RawPacket.h:29
Definition: PcapFilter.h:72