Skip to content

Commit 8570faa

Browse files
authored
Fix IPcapStatisticsProvider::getStatistics() unresolved symbol error when building without libpcap. (#2146)
* Move `IPcapStatisticsProvider:;getStatistics` to be implemented inline. Remove `PcapDevice.cpp` file due to no implementation. * Add test case. * typo * Update clang tidy to exclude deleted files from checks in change tracking mode. * Use --diff-filter exclude syntax instead of including every valid mode.
1 parent f8fac58 commit 8570faa

6 files changed

Lines changed: 15 additions & 18 deletions

File tree

Pcap++/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ add_library(
1010
$<$<BOOL:${PCAPPP_USE_PCAP}>:src/PcapUtils.cpp>
1111
$<$<BOOL:${PCAPPP_USE_PCAP}>:src/NetworkUtils.cpp>
1212
src/PcapFileDevice.cpp
13-
$<$<BOOL:${PCAPPP_USE_PCAP}>:src/PcapDevice.cpp>
1413
src/PcapFilter.cpp
1514
$<$<BOOL:${PCAPPP_USE_PCAP}>:src/PcapLiveDevice.cpp>
1615
$<$<BOOL:${PCAPPP_USE_PCAP}>:src/PcapLiveDeviceList.cpp>

Pcap++/header/PcapDevice.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ namespace pcpp
2828

2929
/// @brief Get statistics from the device
3030
/// @return An object containing the stats
31-
PcapStats getStatistics() const;
31+
PcapStats getStatistics() const
32+
{
33+
PcapStats stats;
34+
getStatistics(stats);
35+
return stats;
36+
}
3237

3338
/// Get statistics from the device
3439
/// @param[out] stats An object containing the stats

Pcap++/src/PcapDevice.cpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

Tests/Pcap++Test/Tests/FileTests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ PTF_TEST_CASE(TestPcapFileReadWrite)
212212
PTF_ASSERT_TRUE(writerDev.writePacket(rawPacket));
213213
}
214214

215+
// TODO: Fix defect where getStatistics() is shadowed in derived classes.
216+
auto rs = static_cast<pcpp::IPcapStatisticsProvider&>(readerDev).getStatistics();
217+
PTF_ASSERT_EQUAL((uint32_t)rs.packetsRecv, 4631);
218+
PTF_ASSERT_EQUAL((uint32_t)rs.packetsDrop, 0);
219+
215220
pcpp::PcapStats readerStatistics;
216221
pcpp::PcapStats writerStatistics;
217222

ci/clang-tidy-all-new.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ BUILD_DIR=${2:-build}
1818
if [ "$MODE" = "changed" ]; then
1919
# Get the list of changed files from origin/dev
2020
git fetch origin dev
21-
files=$(git diff --name-only origin/dev -- '*.cpp' '*.h' | grep -v '3rdParty/' || true)
21+
# --diff-filter excludes deleted files (D) as they no longer exist.
22+
files=$(git diff --name-only --diff-filter=d origin/dev -- '*.cpp' '*.h' | grep -v '3rdParty/' || true)
2223
else
2324
# Find all relevant files
2425
files=$(find "${ROOTPATH}" -type f \( -name '*.cpp' -o -name '*.h' \) -not -path "*/3rdParty/*")

ci/clang-tidy-all.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ BUILD_DIR=${2:-build}
1818
if [ "$MODE" = "changed" ]; then
1919
# Get the list of changed files from origin/dev
2020
git fetch origin dev
21-
files=$(git diff --name-only origin/dev -- '*.cpp' '*.h' | grep -v '3rdParty/' || true)
21+
# --diff-filter excludes deleted files (D) as they no longer exist.
22+
files=$(git diff --name-only --diff-filter=d origin/dev -- '*.cpp' '*.h' | grep -v '3rdParty/' || true)
2223
else
2324
# Find all relevant files
2425
files=$(find "${ROOTPATH}" -type f \( -name '*.cpp' -o -name '*.h' \) -not -path "*/3rdParty/*")

0 commit comments

Comments
 (0)