PcapPlusPlus
PcapPlusPlus copied to clipboard
Pcap device list refactoring to use smart pointers.
Part of #977.
This PR mainly aims to update PcapLiveDeviceList and PcapRemoteDeviceList to utilize cpp11's unique_ptr for dynamic memory management.
Overview of changes:
- [x] Refactor
PcapLiveDeviceListto use smart pointers internally for memory management. - [x] Refactor
PcapRemoteDeviceListto use smart pointers internally for memory management. - [x] Refactor
PcapRemoteDeviceto keep ~~its ownRemoteAuthenticationcopy or~~ a shared reference withPcapRemoteDeviceListviastd::shared_ptras it currently uses a raw pointer to share authentication with the device list. - [x] Add
shared_ptroverloads toPcapLiveDeviceListmethods. Deprecate raw pointer methods. - [x] Add
shared_ptroverloads toPcapRemoteDeviceListmethods. Deprecate raw pointer methods. - [ ] Add unit tests for smart pointer API methods for
PcapLiveDeviceList. - [ ] Add unit tests for smart pointer API methods for
PcapRemoteDeviceList. - [ ] Find a better way to keep the old iterators than keeping a duplicate list?
Additional minor changes:
- Optimized matching of IPv6 addresses to no longer copy the IPv6 address bytes.
- Marked
PcapLiveDeviceListandPCapRemoteDeviceList's copy ctors as explicitlydeletedinstead of keeping themprivate. - Moved internal helper deleters to
MemoryUtils.h.
@seladb On the task list above, regarding PcapRemoteDevice's RemoteAuthentication, should I keep the current functionality by using a shared_ptr or make each device hold a unique copy?
Edit: Decided to go with shared_ptr for now.
RemoteAuthentication
IMO, the unique copy makes sense, since once the authentication is set, it should never be possible to change by others.
RemoteAuthentication
IMO, the unique copy makes sense, since once the authentication is set, it should never be possible to change by others.
Atm, made it so the user provides a unique_ptr to the factory method that is then internally changed to shared_ptr by the device list and shared with the list's devices. So all devices use the same auth object but it should not be exposed externally, outside the device list <-> device relationship.
RemoteAuthentication
IMO, the unique copy makes sense, since once the authentication is set, it should never be possible to change by others.
Atm, made it so the user provides a
unique_ptrto the factory method that is then internally changed toshared_ptrby the device list and shared with the list's devices. So all devices use the same auth object but it should not be exposed externally, outside the device list <-> device relationship.
True, as PcapRemoteDeviceList doesn't expose PcapRemoteAuthentication, PcapRemoteAuthentication can directly be a shared object among the list and device.
This PR will be split into multiple smaller PRs as part of #1431.