PcapPlusPlus icon indicating copy to clipboard operation
PcapPlusPlus copied to clipboard

Change PcapLiveDevice to store IP information as IPAddresses.

Open Dimi1010 opened this issue 1 year ago • 1 comments

Fixes #1439 and #1499.

This IP changes the internal structure of PcapLiveDevice to hold the IP information in IPAddress classes instead of pcap_addr structs. This fixes the issues where IP information might be randomly overwritten. Additionally the clean separation between the device information and the device proper allows cleaner clone procedure where the cached device information can be used to instantiate another Device object. The reworked procedure also fixes the clone issues with PcapRemoteDevice.

PcapLiveDevice changes

A new protected structure DeviceInformationDetails has been added to PcapLiveDevice to hold the relatively static information about the device (name, description, addresses). The previously separate device members are replaced by a single member structure that is now used to hold that information.

NB: The change removes the previously deprecated method getAddresses() and should NOT be merged before its deprecation cycle is complete

In addition to the changes a new constructor overload has been added to PcapLiveDevice and derived classes taking the abovementioned structure instead of pcap_if_t pointer, allowing device construction from cached information.

Optimizing the clone procedure

During the clone procedure, the m_InterfaceDetails structure is used to inject the current device's parameters to the clone's constructor without the need to re-fetch and search through the entire device list from the Pcap layer. The clone method is updated accordingly to no longer fetch the interface list and directly pass control to the doClone1 method.

Fix for clone of PcapRemoteDevice.

  • Added an override of doClone1 to PcapRemoteDevice to instantiate a new remote device from the current one's interface details.
  • Added unit tests to check if the return object of a PcapRemoteDevice::clone method returns a non-null PcapLiveDevice pointer that can be successfully downcasted to a PcapRemoteDevice pointer.

Renamed methods

The protected virtual method cloneInternal has been renamed to doClone as it now handles the entirety of the clone procedure.

Dimi1010 avatar Jul 12 '24 18:07 Dimi1010

Codecov Report

Attention: Patch coverage is 57.72358% with 52 lines in your changes missing coverage. Please review.

Project coverage is 83.23%. Comparing base (40ba4c5) to head (8e412c0). Report is 118 commits behind head on dev.

Files with missing lines Patch % Lines
Pcap++/src/PcapLiveDevice.cpp 75.40% 12 Missing and 3 partials :warning:
Pcap++/src/PcapRemoteDevice.cpp 0.00% 12 Missing :warning:
Pcap++/src/PcapRemoteDeviceList.cpp 0.00% 12 Missing :warning:
Pcap++/src/PcapLiveDeviceList.cpp 50.00% 6 Missing :warning:
Pcap++/header/PcapRemoteDevice.h 0.00% 3 Missing :warning:
Pcap++/src/WinPcapLiveDevice.cpp 70.00% 3 Missing :warning:
Pcap++/header/PcapLiveDevice.h 88.88% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1497      +/-   ##
==========================================
+ Coverage   80.05%   83.23%   +3.17%     
==========================================
  Files         276      276              
  Lines       42074    46883    +4809     
  Branches     9339     9407      +68     
==========================================
+ Hits        33684    39021    +5337     
- Misses       6664     7008     +344     
+ Partials     1726      854     -872     
Flag Coverage Δ
fedora40 74.86% <52.38%> (+0.13%) :arrow_up:
macos-12 81.19% <62.50%> (+0.06%) :arrow_up:
macos-13 80.62% <63.01%> (+0.06%) :arrow_up:
macos-14 80.54% <63.01%> (+0.07%) :arrow_up:
mingw32 70.84% <35.78%> (+0.20%) :arrow_up:
mingw64 70.80% <35.78%> (+0.20%) :arrow_up:
npcap 85.20% <52.47%> (?)
rhel94 74.68% <50.00%> (+0.10%) :arrow_up:
ubuntu2004 58.01% <47.45%> (+0.09%) :arrow_up:
ubuntu2004-zstd 58.11% <47.45%> (+0.06%) :arrow_up:
ubuntu2204 74.61% <48.38%> (+0.08%) :arrow_up:
ubuntu2204-icpx 58.88% <44.59%> (+0.17%) :arrow_up:
ubuntu2404 74.88% <50.81%> (+0.12%) :arrow_up:
unittest 83.23% <57.72%> (+3.17%) :arrow_up:
windows-2019 85.24% <52.47%> (?)
windows-2022 85.26% <53.60%> (?)
winpcap 85.22% <52.47%> (?)
xdp 49.73% <40.32%> (+0.14%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Aug 12 '24 18:08 codecov[bot]