Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/IPDefragUtil/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void processPackets(pcpp::IFileReaderDevice* reader, pcpp::IFileWriterDevice* wr
if (filterByBpf)
{
// check if packet matches the BPF filter supplied by the user
if (pcpp::IPcapDevice::matchPacketWithFilter(filter, &rawPacket))
if (filter.matches(rawPacket))
{
stats.ipPacketsMatchBpfFilter++;
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/IPFragUtil/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void processPackets(pcpp::IFileReaderDevice* reader, pcpp::IFileWriterDevice* wr
if (filterByBpf)
{
// check if packet matches the BPF filter supplied by the user
if (pcpp::IPcapDevice::matchPacketWithFilter(filter, &rawPacket))
if (filter.matches(rawPacket))
{
stats.ipPacketsMatchBpfFilter++;
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/PcapSplitter/SimpleSplitters.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class BpfCriteriaSplitter : public Splitter
*/
int getFileNumber(pcpp::Packet& packet, std::vector<int>& filesToClose)
{
if (pcpp::IPcapDevice::matchPacketWithFilter(filter, packet.getRawPacket()))
if (packet.getRawPacket() != nullptr && filter.matches(*packet.getRawPacket()))
return 0;
return 1;
}
Expand Down
3 changes: 3 additions & 0 deletions Pcap++/header/PcapDevice.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "Device.h"
#include "DeprecationUtils.h"

// forward declaration for the pcap descriptor defined in pcap.h
struct pcap;
Expand Down Expand Up @@ -159,6 +160,8 @@ namespace pcpp
/// @param[in] filter A filter class to test against
/// @param[in] rawPacket A pointer to the raw packet to match the filter with
/// @return True if raw packet matches the filter or false otherwise
/// @deprecated This method is deprecated, use GeneralFilter::matches(...) method directly.
PCPP_DEPRECATED("Prefer GeneralFilter::matches(...) method directly.")
static bool matchPacketWithFilter(GeneralFilter& filter, RawPacket* rawPacket);

// implement abstract methods
Expand Down
6 changes: 6 additions & 0 deletions Pcap++/header/PcapFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ namespace pcpp
/// @param[in] rawPacket A pointer to a raw packet which the filter will be matched against
/// @return True if the filter matches (or if it's empty). False if the packet doesn't match or if the filter
/// could not be compiled
/// @deprecated This method is deprecated, use matches(...) overload instead.
PCPP_DEPRECATED("Prefer matches(...) overload.")
bool matchPacketWithFilter(const RawPacket* rawPacket) const;

/// Match a packet data with the filter stored in this object. If the filter is empty the method returns "true".
Expand All @@ -120,6 +122,8 @@ namespace pcpp
/// @param[in] linkType The packet link type
/// @return True if the filter matches (or if it's empty). False if the packet doesn't match or if the filter
/// could not be compiled
/// @deprecated This method is deprecated, use matches(...) overload instead.
PCPP_DEPRECATED("Prefer matches(...) overload.")
bool matchPacketWithFilter(const uint8_t* packetData, uint32_t packetDataLength, timespec packetTimestamp,
uint16_t linkType) const;

Expand Down Expand Up @@ -170,6 +174,8 @@ namespace pcpp
/// Match a raw packet with a given BPF filter.
/// @param[in] rawPacket A pointer to the raw packet to match the BPF filter with
/// @return True if a raw packet matches the BPF filter or false otherwise
/// @deprecated This method is deprecated, use matches(...) overload instead.
PCPP_DEPRECATED("Prefer matches(...) overload.")
bool matchPacketWithFilter(RawPacket* rawPacket) const;

/// @brief Match a raw packet against the filter.
Expand Down
8 changes: 7 additions & 1 deletion Pcap++/src/PcapDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ namespace pcpp

bool IPcapDevice::matchPacketWithFilter(GeneralFilter& filter, RawPacket* rawPacket)
{
return filter.matchPacketWithFilter(rawPacket);
if (rawPacket == nullptr)
{
PCPP_LOG_ERROR("Raw packet pointer is null");
return false;
}

return filter.matches(*rawPacket);
}

std::string IPcapDevice::getPcapLibVersionInfo()
Expand Down
5 changes: 2 additions & 3 deletions Pcap++/src/PcapFileDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,7 @@ namespace pcpp
return false;
}

while (!m_BpfWrapper.matchPacketWithFilter(pktData, pktHeader.captured_length, pktHeader.timestamp,
pktHeader.data_link))
while (!m_BpfWrapper.matches(pktData, pktHeader.captured_length, pktHeader.timestamp, pktHeader.data_link))
{
if (!light_get_next_packet(toLightPcapNgT(m_LightPcapNg), &pktHeader, &pktData))
{
Expand Down Expand Up @@ -721,7 +720,7 @@ namespace pcpp
return false;
}

if (!m_BpfWrapper.matchPacketWithFilter(&packet))
if (!m_BpfWrapper.matches(packet))
{
return false;
}
Expand Down