83 void operator()(bpf_program* ptr)
const;
94 std::string m_FilterStr;
96 std::unique_ptr<bpf_program, internal::BpfProgramDeleter> m_Program;
196 const std::string m_FilterStr;
199 explicit BPFStringFilter(
const std::string& filterStr) : m_FilterStr(filterStr)
232 void parseDirection(std::string& directionAsString);
266 std::string parseOperator();
420 m_Address = ipAddress;
422 if (m_Address.
isIPv4() && newPrefixLen > 32u)
427 m_Network =
IPNetwork(m_Address, newPrefixLen);
442 m_Network =
IPNetwork(m_Address, netmask);
516 uint16_t m_TotalLength;
536 m_TotalLength = totalLength;
550 void portToString(uint16_t portAsInt);
605 m_FromPort = fromPort;
647 m_MacAddress = address;
661 uint16_t m_EtherType;
679 m_EtherType = etherType;
693 std::vector<GeneralFilter*> m_FilterList;
713 m_FilterList.push_back(filter);
733 m_FilterList.clear();
757 template <> constexpr
const char* getCompositeLogicOpDelimiter<CompositeLogicFilterOp::AND>()
761 template <> constexpr
const char* getCompositeLogicOpDelimiter<CompositeLogicFilterOp::OR>()
781 for (
auto it = m_FilterList.cbegin(); it != m_FilterList.cend(); ++it)
783 std::string innerFilter;
784 (*it)->parseToString(innerFilter);
785 result +=
'(' + innerFilter +
')';
786 if (m_FilterList.cend() - 1 != it)
788 result += internal::getCompositeLogicOpDelimiter<op>();
834 m_FilterToInverse = filterToInverse;
845 m_FilterToInverse = filterToInverse;
891 m_ProtoFamily = proto;
902 m_ProtoFamily = protoFamily;
1011 uint8_t m_TcpFlagsBitMask;
1024 : m_TcpFlagsBitMask(tcpFlagBitMask), m_MatchOption(matchOption)
1036 m_TcpFlagsBitMask = tcpFlagBitMask;
1037 m_MatchOption = matchOption;
1052 uint16_t m_WindowSize;
1072 m_WindowSize = windowSize;
constexpr const char * getCompositeLogicOpDelimiter()=delete
Definition: PcapFilter.h:914
ArpFilter(ArpOpcode opCode)
Definition: PcapFilter.h:923
void setOpCode(ArpOpcode opCode)
Definition: PcapFilter.h:932
void parseToString(std::string &result) override
Definition: PcapFilter.h:194
void parseToString(std::string &result) override
Definition: PcapFilter.h:92
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)
bool setFilter(const std::string &filter, LinkLayerType linkType=LINKTYPE_ETHERNET)
Definition: PcapFilter.h:691
CompositeFilter()=default
void removeFilter(GeneralFilter *filter)
void addFilter(GeneralFilter *filter)
Definition: PcapFilter.h:711
CompositeFilter(const std::vector< GeneralFilter * > &filters)
void setFilters(const std::vector< GeneralFilter * > &filters)
void clearAllFilters()
Definition: PcapFilter.h:731
Definition: PcapFilter.h:774
void parseToString(std::string &result) override
Definition: PcapFilter.h:778
Definition: PcapFilter.h:659
EtherTypeFilter(uint16_t etherType)
Definition: PcapFilter.h:668
void setEtherType(uint16_t etherType)
Definition: PcapFilter.h:677
void parseToString(std::string &result) override
Definition: PcapFilter.h:160
bool matchPacketWithFilter(RawPacket *rawPacket)
virtual ~GeneralFilter()
Definition: PcapFilter.h:185
virtual void parseToString(std::string &result)=0
Definition: PcapFilter.h:227
void setDirection(Direction dir)
Definition: PcapFilter.h:247
Definition: PcapFilter.h:261
void setOperator(FilterOperator op)
Definition: PcapFilter.h:281
Definition: IpAddress.h:358
bool isIPv4() const
Definition: IpAddress.h:438
Definition: PcapFilter.h:294
void setMask(const std::string &netmask)
Definition: PcapFilter.h:440
void clearMask()
Definition: PcapFilter.h:448
void setAddr(const std::string &ipAddress)
Definition: PcapFilter.h:406
void setLen(const int len)
Definition: PcapFilter.h:459
IPFilter(const IPAddress &ipAddress, Direction dir, int len)
Definition: PcapFilter.h:375
IPFilter(const std::string &ipAddress, Direction dir, const std::string &netmask)
Definition: PcapFilter.h:330
IPFilter(const IPNetwork &network, Direction dir)
Definition: PcapFilter.h:385
void setNetwork(const IPNetwork &network)
Definition: PcapFilter.h:395
IPFilter(const std::string &ipAddress, Direction dir, int len)
Definition: PcapFilter.h:361
void clearLen()
Definition: PcapFilter.h:467
void parseToString(std::string &result) override
IPFilter(const std::string &ipAddress, Direction dir)
Definition: PcapFilter.h:306
IPFilter(const IPAddress &ipAddress, Direction dir)
Definition: PcapFilter.h:314
IPFilter(const IPAddress &ipAddress, Direction dir, const std::string &netmask)
Definition: PcapFilter.h:345
void setAddr(const IPAddress &ipAddress)
Definition: PcapFilter.h:418
Definition: IpAddress.h:790
IPAddress getNetworkPrefix() const
Definition: IpAddress.h:967
uint8_t getPrefixLen() const
Definition: IpAddress.h:949
Definition: IpAddress.h:32
Definition: PcapFilter.h:481
void parseToString(std::string &result) override
IPv4IDFilter(uint16_t ipID, FilterOperator op)
Definition: PcapFilter.h:491
void setIpID(uint16_t ipID)
Definition: PcapFilter.h:500
Definition: PcapFilter.h:514
void parseToString(std::string &result) override
void setTotalLength(uint16_t totalLength)
Definition: PcapFilter.h:534
IPv4TotalLengthFilter(uint16_t totalLength, FilterOperator op)
Definition: PcapFilter.h:524
Definition: PcapFilter.h:626
void parseToString(std::string &result) override
void setMacAddress(MacAddress address)
Definition: PcapFilter.h:645
MacAddressFilter(MacAddress address, Direction dir)
Definition: PcapFilter.h:636
Definition: MacAddress.h:25
Definition: PcapFilter.h:823
void setFilter(GeneralFilter *filterToInverse)
Definition: PcapFilter.h:843
void parseToString(std::string &result) override
NotFilter(GeneralFilter *filterToInverse)
Definition: PcapFilter.h:832
Definition: PcapFilter.h:547
PortFilter(uint16_t port, Direction dir)
void parseToString(std::string &result) override
void setPort(uint16_t port)
Definition: PcapFilter.h:566
Definition: PcapFilter.h:581
PortRangeFilter(uint16_t fromPort, uint16_t toPort, Direction dir)
Definition: PcapFilter.h:593
void setToPort(uint16_t toPort)
Definition: PcapFilter.h:612
void parseToString(std::string &result) override
void setFromPort(uint16_t fromPort)
Definition: PcapFilter.h:603
Definition: PcapFilter.h:861
void setProto(ProtocolType proto)
Definition: PcapFilter.h:889
ProtoFilter(ProtocolTypeFamily protoFamily)
Definition: PcapFilter.h:879
void setProto(ProtocolTypeFamily protoFamily)
Definition: PcapFilter.h:900
ProtoFilter(ProtocolType proto)
Definition: PcapFilter.h:871
void parseToString(std::string &result) override
Definition: RawPacket.h:269
Definition: PcapFilter.h:977
TcpFlags
Definition: PcapFilter.h:983
@ tcpSyn
Definition: PcapFilter.h:987
@ tcpFin
Definition: PcapFilter.h:985
@ tcpUrg
Definition: PcapFilter.h:995
@ tcpAck
Definition: PcapFilter.h:993
@ tcpRst
Definition: PcapFilter.h:989
@ tcpPush
Definition: PcapFilter.h:991
void parseToString(std::string &result) override
MatchOptions
Definition: PcapFilter.h:1003
@ MatchAll
Definition: PcapFilter.h:1005
@ MatchOneAtLeast
Definition: PcapFilter.h:1007
void setTcpFlagsBitMask(uint8_t tcpFlagBitMask, MatchOptions matchOption)
Definition: PcapFilter.h:1034
TcpFlagsFilter(uint8_t tcpFlagBitMask, MatchOptions matchOption)
Definition: PcapFilter.h:1023
Definition: PcapFilter.h:1050
void setWindowSize(uint16_t windowSize)
Definition: PcapFilter.h:1070
void parseToString(std::string &result) override
TcpWindowSizeFilter(uint16_t windowSize, FilterOperator op)
Definition: PcapFilter.h:1061
Definition: PcapFilter.h:1083
void parseToString(std::string &result) override
void setLength(uint16_t length)
Definition: PcapFilter.h:1103
UdpLengthFilter(uint16_t length, FilterOperator op)
Definition: PcapFilter.h:1094
Definition: PcapFilter.h:946
VlanFilter(uint16_t vlanId)
Definition: PcapFilter.h:955
void parseToString(std::string &result) override
void setVlanID(uint16_t vlanId)
Definition: PcapFilter.h:964
The main namespace for the PcapPlusPlus lib.
ArpOpcode
Definition: ArpLayer.h:50
uint8_t ProtocolType
Definition: ProtocolType.h:17
FilterOperator
Definition: PcapFilter.h:60
@ GREATER_THAN
Definition: PcapFilter.h:66
@ EQUALS
Definition: PcapFilter.h:62
@ GREATER_OR_EQUAL
Definition: PcapFilter.h:68
@ LESS_THAN
Definition: PcapFilter.h:70
@ NOT_EQUALS
Definition: PcapFilter.h:64
@ LESS_OR_EQUAL
Definition: PcapFilter.h:72
Direction
Definition: PcapFilter.h:47
@ SRC_OR_DST
Definition: PcapFilter.h:53
@ DST
Definition: PcapFilter.h:51
@ SRC
Definition: PcapFilter.h:49
CompositeLogicFilterOp
Definition: PcapFilter.h:741
uint32_t ProtocolTypeFamily
Definition: ProtocolType.h:23
LinkLayerType
Definition: RawPacket.h:25
@ LINKTYPE_ETHERNET
Definition: RawPacket.h:29
Definition: PcapFilter.h:82