Skip to content

Conversation

@seladb
Copy link
Owner

@seladb seladb commented Nov 9, 2025

This PR integrates WinDivert as another packet capture engine in PcapPlusPlus, enabling packet capture/injection on Windows via the WinDivert driver.

What is WinDivert

WinDivert is an open-source Windows library (kernel + user-mode) that allows applications to intercept, modify, drop or inject network packets traversing the Windows network stack. It is designed for use cases such as packet sniffing, firewalling, NAT-/VPN-tunneling, loopback traffic inspection, etc.

Key features include:

  • Capturing both inbound and outbound packets (and loopback) on Windows 7/8/10/11.
  • Support for IPv4 and IPv6, and a simple filtering language.
  • User-mode API (via windivert.h / WinDivert.dll) that interacts with a kernel-mode driver.

Project Links

Testing

This PR includes basic tests for the WinDivertDevice. However, it also adds a lightweight abstraction over the WinDivert API using internal interfaces. It enables testing WinDivertDevice logic without the real driver by providing mock implementations. These mock tests aren't implemented in this PR, but can be added later.

@codecov
Copy link

codecov bot commented Nov 9, 2025

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.47%. Comparing base (a4fa94b) to head (b2c3765).
⚠️ Report is 3 commits behind head on dev.

Files with missing lines Patch % Lines
Tests/Pcap++Test/Tests/WinDivertTests.cpp 90.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #2019   +/-   ##
=======================================
  Coverage   83.47%   83.47%           
=======================================
  Files         311      312    +1     
  Lines       54574    54588   +14     
  Branches    11514    11522    +8     
=======================================
+ Hits        45553    45565   +12     
+ Misses       7795     7765   -30     
- Partials     1226     1258   +32     
Flag Coverage Δ
alpine320 75.90% <100.00%> (+<0.01%) ⬆️
fedora42 75.43% <100.00%> (-0.02%) ⬇️
macos-14 81.58% <93.75%> (+<0.01%) ⬆️
macos-15 81.57% <93.75%> (+<0.01%) ⬆️
mingw32 70.00% <ø> (+0.01%) ⬆️
mingw64 69.86% <ø> (ø)
npcap 85.26% <ø> (-0.01%) ⬇️
rhel94 75.46% <100.00%> (+<0.01%) ⬆️
ubuntu2004 59.46% <85.71%> (+<0.01%) ⬆️
ubuntu2004-zstd 59.57% <85.71%> (+<0.01%) ⬆️
ubuntu2204 75.40% <100.00%> (+<0.01%) ⬆️
ubuntu2204-icpx 57.88% <ø> (ø)
ubuntu2404 75.52% <100.00%> (+0.03%) ⬆️
ubuntu2404-arm64 75.55% <100.00%> (+<0.01%) ⬆️
unittest 83.47% <93.75%> (+<0.01%) ⬆️
windows-2022 85.26% <ø> (-0.01%) ⬇️
windows-2025 85.34% <ø> (ø)
winpcap 85.54% <ø> (ø)
xdp 52.98% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@seladb seladb changed the title Add support for WinDivert packet capture engine [DRAFT] Add support for WinDivert packet capture engine Nov 10, 2025
PTF_ASSERT_TRUE(sendURLRequest("www.google.com"));
// let the capture work for couple of seconds
totalSleepTime = incSleep(capturedPackets, 2, 7);
totalSleepTime = incSleep(capturedPackets, 2, 20);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test also failed in CI so I made it more robust

Comment on lines +75 to 83
parser.add_argument(
"--include-tests",
"-t",
type=str,
nargs="+",
default=[],
help="Pcap++ tests to include",
)
parser.add_argument(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was needed to support running only WinDivert tests in the windivert job in CI

@seladb seladb marked this pull request as ready for review November 14, 2025 07:36
@seladb seladb changed the title [DRAFT] Add support for WinDivert packet capture engine Add support for WinDivert packet capture engine Nov 14, 2025
@seladb seladb requested a review from Dimi1010 November 30, 2025 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants