Skip to content

Commit 7185411

Browse files
authored
Merge branch 'dev' into fix-malformed-pkt-crash
2 parents b8ab283 + 6f756e0 commit 7185411

File tree

12 files changed

+97
-27
lines changed

12 files changed

+97
-27
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# We need 3.12 or later, so that we can set policy CMP0074; see below.
22
cmake_minimum_required(VERSION 3.12)
33

4-
set(PCAPPP_VERSION "25.05")
4+
set(PCAPPP_VERSION "25.05+")
55

66
# MAIN_PROJECT CHECK
77
set(PCAPPP_MAIN_PROJECT OFF)
@@ -146,9 +146,9 @@ option(PCAPPP_USE_XDP "Setup PcapPlusPlus with XDP")
146146
option(PCAPPP_INSTALL "Install Pcap++" ${PCAPPP_MAIN_PROJECT})
147147
option(PCAPPP_PACKAGE "Package Pcap++ could require a recent version of CMake" OFF)
148148

149-
# Set C++11 if not defined
149+
# Set C++14 if not defined
150150
if(NOT DEFINED CMAKE_CXX_STANDARD)
151-
set(CMAKE_CXX_STANDARD 11)
151+
set(CMAKE_CXX_STANDARD 14)
152152
set(CMAKE_CXX_STANDARD_REQUIRED ON)
153153
endif()
154154

Common++/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ set(
3434
# Set the public header that will be installed
3535
set_property(TARGET Common++ PROPERTY PUBLIC_HEADER ${public_headers})
3636

37-
target_compile_features(Common++ PUBLIC cxx_std_11)
37+
target_compile_features(Common++ PUBLIC cxx_std_14)
3838

3939
target_include_directories(
4040
Common++

Common++/header/PcapPlusPlusVersion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
/// @brief The main namespace for the PcapPlusPlus lib
99
namespace pcpp
1010
{
11-
#define PCAPPLUSPLUS_VERSION "25.05"
12-
#define PCAPPLUSPLUS_VERSION_OFFICIAL "official release"
11+
#define PCAPPLUSPLUS_VERSION "25.05+"
12+
#define PCAPPLUSPLUS_VERSION_OFFICIAL "non-official release"
1313

1414
#define PCAPPLUSPLUS_VERSION_FULL "v" PCAPPLUSPLUS_VERSION " (" PCAPPLUSPLUS_VERSION_OFFICIAL ")"
1515

Examples/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ project(PcapPlusPlusExamples)
44

55
set(CMAKE_PROJECT_HOMEPAGE_URL "https://pcapplusplus.github.io/")
66

7-
# Set C++11
8-
set(CMAKE_CXX_STANDARD 11)
7+
# Set C++14
8+
set(CMAKE_CXX_STANDARD 14)
99
# popen()/pclose() are not C++ standards
1010
set(CMAKE_CXX_EXTENSIONS ON)
1111

Packet++/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ set(
145145
# Don't use set_target_properties CMake limit to 50 elements
146146
set_property(TARGET Packet++ PROPERTY PUBLIC_HEADER ${public_headers})
147147

148-
target_compile_features(Packet++ PUBLIC cxx_std_11)
148+
target_compile_features(Packet++ PUBLIC cxx_std_14)
149149

150150
target_include_directories(
151151
Packet++

Pcap++/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ endif()
6464

6565
set_property(TARGET Pcap++ PROPERTY PUBLIC_HEADER ${public_headers})
6666

67-
target_compile_features(Pcap++ PUBLIC cxx_std_11)
67+
target_compile_features(Pcap++ PUBLIC cxx_std_14)
6868

6969
if(APPLE)
7070
target_link_libraries(Pcap++ PRIVATE "-framework CoreFoundation" "-framework SystemConfiguration")

Pcap++/header/PcapDevice.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,12 @@ namespace pcpp
9797
};
9898
} // namespace internal
9999

100-
/// @class IPcapDevice
101-
/// An abstract class representing all libpcap-based packet capturing devices: files, libPcap, WinPcap/Npcap and
102-
/// RemoteCapture. This class is abstract and cannot be instantiated
103-
class IPcapDevice : public IDevice, public IFilterableDevice
100+
/// @brief An interface for providing Pcap-based device statistics
101+
class IPcapStatisticsProvider
104102
{
105-
protected:
106-
internal::PcapHandle m_PcapDescriptor;
107-
108-
// c'tor should not be public
109-
IPcapDevice() : IDevice()
110-
{}
111-
112103
public:
104+
virtual ~IPcapStatisticsProvider() = default;
105+
113106
/// @struct PcapStats
114107
/// A container for pcap device statistics
115108
struct PcapStats
@@ -122,11 +115,29 @@ namespace pcpp
122115
uint64_t packetsDropByInterface;
123116
};
124117

125-
virtual ~IPcapDevice();
118+
/// @brief Get statistics from the device
119+
/// @return An object containing the stats
120+
PcapStats getStatistics() const;
126121

127122
/// Get statistics from the device
128123
/// @param[out] stats An object containing the stats
129124
virtual void getStatistics(PcapStats& stats) const = 0;
125+
};
126+
127+
/// @class IPcapDevice
128+
/// An abstract class representing all libpcap-based packet capturing devices: files, libPcap, WinPcap/Npcap and
129+
/// RemoteCapture. This class is abstract and cannot be instantiated
130+
class IPcapDevice : public IDevice, public IFilterableDevice, public IPcapStatisticsProvider
131+
{
132+
protected:
133+
internal::PcapHandle m_PcapDescriptor;
134+
135+
// c'tor should not be public
136+
IPcapDevice() : IDevice()
137+
{}
138+
139+
public:
140+
virtual ~IPcapDevice() = default;
130141

131142
/// A static method for retrieving pcap lib (libpcap/WinPcap/etc.) version information. This method is actually
132143
/// a wrapper for [pcap_lib_version()](https://www.tcpdump.org/manpages/pcap_lib_version.3pcap.html)

Pcap++/header/PcapRemoteDeviceList.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,45 @@ namespace pcpp
140140
/// Search a PcapRemoteDevice in the list by its IPv4 address
141141
/// @param[in] ip4Addr The IPv4 address
142142
/// @return The PcapRemoteDevice if found, nullptr otherwise
143+
PCPP_DEPRECATED("Use `getDeviceByIp`")
143144
PcapRemoteDevice* getRemoteDeviceByIP(const IPv4Address& ip4Addr) const;
144145

146+
/// Search a PcapRemoteDevice in the list by its IPv4 address
147+
/// @param[in] ip4Addr The IPv4 address
148+
/// @return The PcapRemoteDevice if found, nullptr otherwise
149+
PcapRemoteDevice* getDeviceByIP(const IPv4Address& ip4Addr) const;
150+
145151
/// Search a PcapRemoteDevice in the list by its IPv6 address
146152
/// @param[in] ip6Addr The IPv6 address
147153
/// @return The PcapRemoteDevice if found, nullptr otherwise
154+
PCPP_DEPRECATED("Use `getDeviceByIp`")
148155
PcapRemoteDevice* getRemoteDeviceByIP(const IPv6Address& ip6Addr) const;
149156

157+
/// Search a PcapRemoteDevice in the list by its IPv6 address
158+
/// @param[in] ip6Addr The IPv6 address
159+
/// @return The PcapRemoteDevice if found, nullptr otherwise
160+
PcapRemoteDevice* getDeviceByIP(const IPv6Address& ip6Addr) const;
161+
150162
/// Search a PcapRemoteDevice in the list by its IP address (IPv4 or IPv6)
151163
/// @param[in] ipAddr The IP address
152164
/// @return The PcapRemoteDevice if found, nullptr otherwise
165+
PCPP_DEPRECATED("Use `getDeviceByIp`")
153166
PcapRemoteDevice* getRemoteDeviceByIP(const IPAddress& ipAddr) const;
154167

168+
/// Search a PcapRemoteDevice in the list by its IP address (IPv4 or IPv6)
169+
/// @param[in] ipAddr The IP address
170+
/// @return The PcapRemoteDevice if found, nullptr otherwise
171+
PcapRemoteDevice* getDeviceByIP(const IPAddress& ipAddr) const;
172+
155173
/// Search a PcapRemoteDevice in the list by its IP address
156174
/// @param[in] ipAddrAsString The IP address in string format
157175
/// @return The PcapRemoteDevice if found, nullptr otherwise
176+
PCPP_DEPRECATED("Use `getDeviceByIp`")
158177
PcapRemoteDevice* getRemoteDeviceByIP(const std::string& ipAddrAsString) const;
178+
179+
/// Search a PcapRemoteDevice in the list by its IP address
180+
/// @param[in] ipAddrAsString The IP address in string format
181+
/// @return The PcapRemoteDevice if found, nullptr otherwise
182+
PcapRemoteDevice* getDeviceByIP(const std::string& ipAddrAsString) const;
159183
};
160184
} // namespace pcpp

Pcap++/header/PfRingDeviceList.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ namespace pcpp
4848
/// Get a PF_RING device by name. The name is the Linux interface name which appears in ifconfig
4949
/// (e.g eth0, eth1, etc.)
5050
/// @return A pointer to the PF_RING device
51+
PCPP_DEPRECATED("Use `getDeviceByName`")
5152
PfRingDevice* getPfRingDeviceByName(const std::string& devName) const;
5253

54+
/// Get a PF_RING device by name. The name is the Linux interface name which appears in ifconfig
55+
/// (e.g eth0, eth1, etc.)
56+
/// @return A pointer to the PF_RING device
57+
PfRingDevice* getDeviceByName(const std::string& devName) const;
58+
5359
/// Get installed PF_RING version
5460
/// @return A string representing PF_RING version
5561
std::string getPfRingVersion() const

Pcap++/src/PcapDevice.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ namespace pcpp
105105
}
106106
} // namespace internal
107107

108-
IPcapDevice::~IPcapDevice()
109-
{}
108+
IPcapStatisticsProvider::PcapStats IPcapStatisticsProvider::getStatistics() const
109+
{
110+
PcapStats stats;
111+
getStatistics(stats);
112+
return stats;
113+
}
110114

111115
bool IPcapDevice::setFilter(std::string filterAsString)
112116
{

Pcap++/src/PcapRemoteDeviceList.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ namespace pcpp
122122
}
123123

124124
PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const std::string& ipAddrAsString) const
125+
{
126+
return getDeviceByIP(ipAddrAsString);
127+
}
128+
129+
PcapRemoteDevice* PcapRemoteDeviceList::getDeviceByIP(const std::string& ipAddrAsString) const
125130
{
126131
IPAddress ipAddr;
127132

@@ -135,23 +140,33 @@ namespace pcpp
135140
return nullptr;
136141
}
137142

138-
PcapRemoteDevice* result = getRemoteDeviceByIP(ipAddr);
143+
PcapRemoteDevice* result = getDeviceByIP(ipAddr);
139144
return result;
140145
}
141146

142147
PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPAddress& ipAddr) const
148+
{
149+
return getDeviceByIP(ipAddr);
150+
}
151+
152+
PcapRemoteDevice* PcapRemoteDeviceList::getDeviceByIP(const IPAddress& ipAddr) const
143153
{
144154
if (ipAddr.getType() == IPAddress::IPv4AddressType)
145155
{
146-
return getRemoteDeviceByIP(ipAddr.getIPv4());
156+
return getDeviceByIP(ipAddr.getIPv4());
147157
}
148158
else // IPAddress::IPv6AddressType
149159
{
150-
return getRemoteDeviceByIP(ipAddr.getIPv6());
160+
return getDeviceByIP(ipAddr.getIPv6());
151161
}
152162
}
153163

154164
PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPv4Address& ip4Addr) const
165+
{
166+
return getDeviceByIP(ip4Addr);
167+
}
168+
169+
PcapRemoteDevice* PcapRemoteDeviceList::getDeviceByIP(const IPv4Address& ip4Addr) const
155170
{
156171
auto it = std::find_if(m_DeviceList.begin(), m_DeviceList.end(), [&ip4Addr](PcapRemoteDevice const* devPtr) {
157172
auto devIP = devPtr->getIPv4Address();
@@ -161,6 +176,11 @@ namespace pcpp
161176
}
162177

163178
PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPv6Address& ip6Addr) const
179+
{
180+
return getDeviceByIP(ip6Addr);
181+
}
182+
183+
PcapRemoteDevice* PcapRemoteDeviceList::getDeviceByIP(const IPv6Address& ip6Addr) const
164184
{
165185
auto it = std::find_if(m_DeviceList.begin(), m_DeviceList.end(), [&ip6Addr](PcapRemoteDevice const* devPtr) {
166186
auto devIP = devPtr->getIPv6Address();

Pcap++/src/PfRingDeviceList.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ namespace pcpp
111111
}
112112

113113
PfRingDevice* PfRingDeviceList::getPfRingDeviceByName(const std::string& devName) const
114+
{
115+
return getDeviceByName(devName);
116+
}
117+
118+
PfRingDevice* PfRingDeviceList::getDeviceByName(const std::string& devName) const
114119
{
115120
PCPP_LOG_DEBUG("Searching all live devices...");
116121
auto devIter = std::find_if(m_DeviceList.begin(), m_DeviceList.end(),

0 commit comments

Comments
 (0)