-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change PcapLiveDevice to store IP information as IPAddresses. #1497
Conversation
…uct DeviceInterfaceDetails to allow direct construction of the device without re-fetching from the Pcap layer.
… of the correct type.
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
# Conflicts: # Pcap++/header/PcapDevice.h # Pcap++/header/WinPcapLiveDevice.h # Pcap++/src/PcapLiveDevice.cpp # Pcap++/src/PcapRemoteDevice.cpp # Pcap++/src/PcapRemoteDeviceList.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see a few minor comments, otherwise LGTM
/// @struct DeviceInterfaceDetails | ||
/// @brief A struct that contains all details of a network interface. | ||
struct DeviceInterfaceDetails | ||
{ | ||
explicit DeviceInterfaceDetails(pcap_if_t* pInterface); | ||
/// @brief Name of the device. | ||
std::string name; | ||
/// @brief Description of the device. | ||
std::string description; | ||
/// @brief IP addresses associated with the device. | ||
std::vector<IPAddress> addresses; | ||
/// @brief Flag to indicate if the device is a loopback device. | ||
bool isLoopback; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nit: no need for doxygen documentation for private/protected structs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, its not strictly required, but I think its fine to stay, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure we can leave it 🙂
@@ -91,8 +91,13 @@ namespace pcpp | |||
std::shared_ptr<PcapRemoteAuthentication> m_RemoteAuthentication; | |||
|
|||
// c'tor is private, as only PcapRemoteDeviceList should create instances of it, and it'll create only one for | |||
// every remote interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this line? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh, good catch. did not mean that to be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed d9bef35
Fixes #1439 and #1499.
This IP changes the internal structure of
PcapLiveDevice
to hold the IP information inIPAddress
classes instead ofpcap_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 anotherDevice
object. The reworked procedure also fixes the clone issues withPcapRemoteDevice
.PcapLiveDevice
changesA new protected structure
DeviceInformationDetails
has been added toPcapLiveDevice
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 completeIn addition to the changes a new constructor overload has been added to
PcapLiveDevice
and derived classes taking the abovementioned structure instead ofpcap_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. Theclone
method is updated to a virtual method and performs the construction of a new device object directly without re-fetching the devices.The method
cloneInternal
has been removed as superfluous, and derived implementations have been updated to override theclone
method instead.Fix for clone of
PcapRemoteDevice
.clone
toPcapRemoteDevice
to instantiate a new remote device from the current one's interface details.PcapRemoteDevice::clone
method returns a non-nullPcapLiveDevice
pointer that can be successfully downcasted to aPcapRemoteDevice
pointer.