From af785be330ffd7a29b8e891ceb4ac5cef7b61c73 Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Sun, 30 Jun 2024 20:11:15 +0300 Subject: [PATCH 1/8] Refactor PcapRemoteDeviceList with smart pointers - Introduced `createRemoteDeviceList` static methods in `PcapRemoteDeviceList` for creating and managing remote device lists using `std::unique_ptr`, enhancing memory management and safety. - Modified existing `getRemoteDeviceList` methods to utilize new `createRemoteDeviceList` methods, maintaining backward compatibility by returning raw pointers through `.release()`. - Adopted smart pointers (`std::unique_ptr`) in the implementation for automatic memory cleanup, reducing the risk of memory leaks and improving code maintainability. - Modernized the codebase by leveraging C++11 smart pointers, simplifying resource management and providing a clearer, more flexible API for handling remote device lists with and without authentication. --- Pcap++/header/PcapRemoteDeviceList.h | 40 ++++++++++++++++++++++++++++ Pcap++/src/PcapRemoteDeviceList.cpp | 16 +++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/Pcap++/header/PcapRemoteDeviceList.h b/Pcap++/header/PcapRemoteDeviceList.h index 4d9e09a3d3..faefda0723 100644 --- a/Pcap++/header/PcapRemoteDeviceList.h +++ b/Pcap++/header/PcapRemoteDeviceList.h @@ -73,6 +73,25 @@ namespace pcpp */ static PcapRemoteDeviceList* getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port); + /** + * A static method for creating a PcapRemoteDeviceList instance for a specific remote machine. + * This methods creates the instance and populates it with PcapRemoteDevice instances. + * Each PcapRemoteDevice instance correspons to a network interface on the remote machine. + * + * This method overload is for remote daemons which don't require authentication for accessing them. + * For daemons which do require authentication use the other method overload. + * + * @param[in] ipAddress The IP address of the remote machine through which clients can connect to the rpcapd + * daemon + * @param[in] port The port of the remote machine through which clients can connect to the rpcapd daemon + * @return A smart pointer to the newly created PcapRemoteDeviceList, or nullptr if (an appropriate error will be printed + * to log in each case): + * - WinPcap/Npcap encountered an error in creating the remote connection string + * - WinPcap/Npcap encountered an error connecting to the rpcapd daemon on the remote machine or retrieving + * devices on the remote machine + */ + static std::unique_ptr createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port); + /** * An overload of the previous getRemoteDeviceList() method but with authentication support. This method is suitable for connecting to * remote daemons which require authentication for accessing them @@ -87,6 +106,27 @@ namespace pcpp */ static PcapRemoteDeviceList* getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication* remoteAuth); + /** + * A static method for creating a PcapRemoteDeviceList instance for a specific remote machine. + * This methods creates the instance and populates it with PcapRemoteDevice instances. + * Each PcapRemoteDevice instance correspons to a network interface on the remote machine. + * + * This method overload is for remote daemons which require authentication for accessing them. + * If no authentication is required, use the other method overload. + * + * @param[in] ipAddress The IP address of the remote machine through which clients can connect to the rpcapd + * daemon + * @param[in] port The port of the remote machine through which clients can connect to the rpcapd daemon + * @param[in] remoteAuth A pointer to the authentication object which contains the username and password for + * connecting to the remote daemon + * @return A smart pointer to the newly created PcapRemoteDeviceList, or nullptr if (an appropriate error will be printed + * to log in each case): + * - WinPcap/Npcap encountered an error in creating the remote connection string + * - WinPcap/Npcap encountered an error connecting to the rpcapd daemon on the remote machine or retrieving + * devices on the remote machine + */ + static std::unique_ptr createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication* remoteAuth); + /** * @return The IP address of the remote machine */ diff --git a/Pcap++/src/PcapRemoteDeviceList.cpp b/Pcap++/src/PcapRemoteDeviceList.cpp index e852e6c297..23a3f66d2b 100644 --- a/Pcap++/src/PcapRemoteDeviceList.cpp +++ b/Pcap++/src/PcapRemoteDeviceList.cpp @@ -50,10 +50,22 @@ namespace pcpp PcapRemoteDeviceList* PcapRemoteDeviceList::getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port) { - return PcapRemoteDeviceList::getRemoteDeviceList(ipAddress, port, NULL); + auto result = PcapRemoteDeviceList::createRemoteDeviceList(ipAddress, port); + return result.release(); +} + +std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port) +{ + return PcapRemoteDeviceList::createRemoteDeviceList(ipAddress, port, nullptr); } PcapRemoteDeviceList* PcapRemoteDeviceList::getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication* remoteAuth) +{ + auto result = PcapRemoteDeviceList::createRemoteDeviceList(ipAddress, port, remoteAuth); + return result.release(); +} + +std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication* remoteAuth) { pcap_rmtauth* pRmAuth = nullptr; pcap_rmtauth rmAuth; @@ -75,7 +87,7 @@ PcapRemoteDeviceList* PcapRemoteDeviceList::getRemoteDeviceList(const IPAddress& return nullptr; } - PcapRemoteDeviceList* resultList = new PcapRemoteDeviceList(); + std::unique_ptr resultList = std::unique_ptr(new PcapRemoteDeviceList()); resultList->setRemoteMachineIpAddress(ipAddress); resultList->setRemoteMachinePort(port); resultList->setRemoteAuthentication(remoteAuth); From d610fbea4f6b9b18fc38948c46776f2ac384e168 Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Sun, 30 Jun 2024 20:15:03 +0300 Subject: [PATCH 2/8] Refactor iterator type aliases in PcapRemoteDeviceList Modernized the syntax for defining iterator and const iterator type aliases in `PcapRemoteDeviceList.h` within the `pcpp` namespace. Replaced traditional `typedef` with the `using` syntax for `RemoteDeviceListIterator` and `ConstRemoteDeviceListIterator`. These changes enhance code readability and align with modern C++ best practices without altering functionality. --- Pcap++/header/PcapRemoteDeviceList.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pcap++/header/PcapRemoteDeviceList.h b/Pcap++/header/PcapRemoteDeviceList.h index faefda0723..0caf7c2e7b 100644 --- a/Pcap++/header/PcapRemoteDeviceList.h +++ b/Pcap++/header/PcapRemoteDeviceList.h @@ -44,12 +44,12 @@ namespace pcpp /** * Iterator object that can be used for iterating all PcapRemoteDevice in list */ - typedef typename std::vector::iterator RemoteDeviceListIterator; + using RemoteDeviceListIterator = typename std::vector::iterator; /** * Const iterator object that can be used for iterating all PcapRemoteDevice in a constant list */ - typedef typename std::vector::const_iterator ConstRemoteDeviceListIterator; + using ConstRemoteDeviceListIterator = typename std::vector::const_iterator; PcapRemoteDeviceList(const PcapRemoteDeviceList&) = delete; PcapRemoteDeviceList(PcapRemoteDeviceList&&) noexcept = delete; From 6f5cc0dfc967c371e016dc13c995867053f31752 Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Sun, 30 Jun 2024 23:29:22 +0300 Subject: [PATCH 3/8] Enhance PcapRemoteDeviceList construction - Removed the default constructor of 'PcapRemoteDeviceList'. - Added a new constructor to `PcapRemoteDeviceList` for initializing with detailed remote machine info and authentication. - Corrected typographical errors in comments for better documentation clarity. - Improved const-correctness in `createRemoteDeviceList` by changing `remoteAuth` parameter type. - Refactored device creation logic in `createRemoteDeviceList` for clearer error handling and separation of concerns. - Enhanced error handling in device creation to prevent memory leaks on exceptions. - Transitioned to using `std::shared_ptr` for better memory management in device creation. - Simplified authentication object handling by converting to `std::shared_ptr` early in the device creation process. --- Pcap++/header/PcapRemoteDeviceList.h | 20 +++++++------ Pcap++/src/PcapRemoteDeviceList.cpp | 44 ++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/Pcap++/header/PcapRemoteDeviceList.h b/Pcap++/header/PcapRemoteDeviceList.h index 0caf7c2e7b..714dd9a194 100644 --- a/Pcap++/header/PcapRemoteDeviceList.h +++ b/Pcap++/header/PcapRemoteDeviceList.h @@ -34,7 +34,9 @@ namespace pcpp std::shared_ptr m_RemoteAuthentication; // private c'tor. User should create the list via static methods PcapRemoteDeviceList::getRemoteDeviceList() - PcapRemoteDeviceList() : m_RemoteMachinePort(0), m_RemoteAuthentication(nullptr) {} + PcapRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, + std::shared_ptr remoteAuth, + std::vector deviceList); void setRemoteMachineIpAddress(const IPAddress& ipAddress); void setRemoteMachinePort(uint16_t port); @@ -76,11 +78,11 @@ namespace pcpp /** * A static method for creating a PcapRemoteDeviceList instance for a specific remote machine. * This methods creates the instance and populates it with PcapRemoteDevice instances. - * Each PcapRemoteDevice instance correspons to a network interface on the remote machine. - * - * This method overload is for remote daemons which don't require authentication for accessing them. + * Each PcapRemoteDevice instance corresponds to a network interface on the remote machine. + * + * This method overload is for remote daemons which don't require authentication for accessing them. * For daemons which do require authentication use the other method overload. - * + * * @param[in] ipAddress The IP address of the remote machine through which clients can connect to the rpcapd * daemon * @param[in] port The port of the remote machine through which clients can connect to the rpcapd daemon @@ -109,11 +111,11 @@ namespace pcpp /** * A static method for creating a PcapRemoteDeviceList instance for a specific remote machine. * This methods creates the instance and populates it with PcapRemoteDevice instances. - * Each PcapRemoteDevice instance correspons to a network interface on the remote machine. - * + * Each PcapRemoteDevice instance corresponds to a network interface on the remote machine. + * * This method overload is for remote daemons which require authentication for accessing them. * If no authentication is required, use the other method overload. - * + * * @param[in] ipAddress The IP address of the remote machine through which clients can connect to the rpcapd * daemon * @param[in] port The port of the remote machine through which clients can connect to the rpcapd daemon @@ -125,7 +127,7 @@ namespace pcpp * - WinPcap/Npcap encountered an error connecting to the rpcapd daemon on the remote machine or retrieving * devices on the remote machine */ - static std::unique_ptr createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication* remoteAuth); + static std::unique_ptr createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication const* remoteAuth); /** * @return The IP address of the remote machine diff --git a/Pcap++/src/PcapRemoteDeviceList.cpp b/Pcap++/src/PcapRemoteDeviceList.cpp index 23a3f66d2b..210623e1e1 100644 --- a/Pcap++/src/PcapRemoteDeviceList.cpp +++ b/Pcap++/src/PcapRemoteDeviceList.cpp @@ -48,6 +48,13 @@ namespace pcpp } } +PcapRemoteDeviceList::PcapRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, std::shared_ptr remoteAuth, std::vector deviceList) + : m_RemoteDeviceList(std::move(deviceList)) + , m_RemoteMachineIpAddress(ipAddress) + , m_RemoteMachinePort(port) + , m_RemoteAuthentication(std::move(remoteAuth)) +{} + PcapRemoteDeviceList* PcapRemoteDeviceList::getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port) { auto result = PcapRemoteDeviceList::createRemoteDeviceList(ipAddress, port); @@ -65,14 +72,16 @@ PcapRemoteDeviceList* PcapRemoteDeviceList::getRemoteDeviceList(const IPAddress& return result.release(); } -std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication* remoteAuth) +std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication const* remoteAuth) { + std::shared_ptr sRemoteAuth; pcap_rmtauth* pRmAuth = nullptr; pcap_rmtauth rmAuth; if (remoteAuth != nullptr) { PCPP_LOG_DEBUG("Authentication requested. Username: " << remoteAuth->userName << ", Password: " << remoteAuth->password); - rmAuth = remoteAuth->getPcapRmAuth(); + sRemoteAuth = std::make_shared(*remoteAuth); + rmAuth = sRemoteAuth->getPcapRmAuth(); pRmAuth = &rmAuth; } @@ -87,20 +96,29 @@ std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceLi return nullptr; } - std::unique_ptr resultList = std::unique_ptr(new PcapRemoteDeviceList()); - resultList->setRemoteMachineIpAddress(ipAddress); - resultList->setRemoteMachinePort(port); - resultList->setRemoteAuthentication(remoteAuth); - - - for (pcap_if_t* currInterface = interfaceList.get(); currInterface != nullptr; currInterface = currInterface->next) + std::vector devices; + try + { + for (pcap_if_t* currInterface = interfaceList.get(); currInterface != nullptr; currInterface = currInterface->next) + { + auto pNewRemoteDevice = std::unique_ptr(new PcapRemoteDevice(currInterface, sRemoteAuth, ipAddress, port)); + // Release is called after pushback to prevent memory leaks if vector reallocation fails. + // cppcheck-suppress danglingLifetime + devices.push_back(pNewRemoteDevice.get()); + pNewRemoteDevice.release(); + } + } + catch (const std::exception& e) { - PcapRemoteDevice* pNewRemoteDevice = new PcapRemoteDevice(currInterface, resultList->m_RemoteAuthentication, - resultList->getRemoteMachineIpAddress(), resultList->getRemoteMachinePort()); - resultList->m_RemoteDeviceList.push_back(pNewRemoteDevice); + for (auto dev : devices) + { + delete dev; + } + PCPP_LOG_ERROR("Error creating remote devices: " << e.what()); + return nullptr; } - return resultList; + return std::unique_ptr(new PcapRemoteDeviceList(ipAddress, port, sRemoteAuth, devices)); } PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const std::string& ipAddrAsString) const From 1a257b7b0284880a1251d27282f130a2d5a7b317 Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Sun, 30 Jun 2024 23:32:06 +0300 Subject: [PATCH 4/8] Removed unused setter methods. --- Pcap++/header/PcapRemoteDeviceList.h | 4 ---- Pcap++/src/PcapRemoteDeviceList.cpp | 20 -------------------- 2 files changed, 24 deletions(-) diff --git a/Pcap++/header/PcapRemoteDeviceList.h b/Pcap++/header/PcapRemoteDeviceList.h index 714dd9a194..8435ac7583 100644 --- a/Pcap++/header/PcapRemoteDeviceList.h +++ b/Pcap++/header/PcapRemoteDeviceList.h @@ -38,10 +38,6 @@ namespace pcpp std::shared_ptr remoteAuth, std::vector deviceList); - void setRemoteMachineIpAddress(const IPAddress& ipAddress); - void setRemoteMachinePort(uint16_t port); - void setRemoteAuthentication(const PcapRemoteAuthentication* remoteAuth); - public: /** * Iterator object that can be used for iterating all PcapRemoteDevice in list diff --git a/Pcap++/src/PcapRemoteDeviceList.cpp b/Pcap++/src/PcapRemoteDeviceList.cpp index 210623e1e1..5ac4e44a21 100644 --- a/Pcap++/src/PcapRemoteDeviceList.cpp +++ b/Pcap++/src/PcapRemoteDeviceList.cpp @@ -220,26 +220,6 @@ PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPv6Address& i } -void PcapRemoteDeviceList::setRemoteMachineIpAddress(const IPAddress& ipAddress) -{ - m_RemoteMachineIpAddress = ipAddress; -} - -void PcapRemoteDeviceList::setRemoteMachinePort(uint16_t port) -{ - m_RemoteMachinePort = port; -} - -void PcapRemoteDeviceList::setRemoteAuthentication(const PcapRemoteAuthentication* remoteAuth) -{ - if (remoteAuth != nullptr) - m_RemoteAuthentication = std::shared_ptr(new PcapRemoteAuthentication(*remoteAuth)); - else - { - m_RemoteAuthentication = nullptr; - } -} - PcapRemoteDeviceList::~PcapRemoteDeviceList() { while (m_RemoteDeviceList.size() > 0) From 6916da3ca6a2466bee2739705e6a02e0afe9864c Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Sun, 30 Jun 2024 23:36:25 +0300 Subject: [PATCH 5/8] Refactor PcapRemoteDeviceList creation - Included DeprecationUtils.h in PcapRemoteDeviceList.h to mark certain functionalities as deprecated, indicating a move towards newer alternatives. - Updated the private constructor comment in PcapRemoteDeviceList to recommend using `createRemoteDeviceList` for instance creation, reflecting a shift to a new factory method. - Deprecated two static factory functions, `getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port)` and `getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication* remoteAuth)`, in favor of `createRemoteDeviceList`, enhancing memory safety and functionality. --- Pcap++/header/PcapRemoteDeviceList.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Pcap++/header/PcapRemoteDeviceList.h b/Pcap++/header/PcapRemoteDeviceList.h index 8435ac7583..3b00bd2738 100644 --- a/Pcap++/header/PcapRemoteDeviceList.h +++ b/Pcap++/header/PcapRemoteDeviceList.h @@ -5,6 +5,7 @@ #include #include "IpAddress.h" #include "PcapRemoteDevice.h" +#include "DeprecationUtils.h" /// @file @@ -33,7 +34,7 @@ namespace pcpp uint16_t m_RemoteMachinePort; std::shared_ptr m_RemoteAuthentication; - // private c'tor. User should create the list via static methods PcapRemoteDeviceList::getRemoteDeviceList() + // private c'tor. User should create the list via static methods PcapRemoteDeviceList::createRemoteDeviceList() PcapRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, std::shared_ptr remoteAuth, std::vector deviceList); @@ -68,7 +69,9 @@ namespace pcpp * - IP address provided is NULL or not valid * - WinPcap/Npcap encountered an error in creating the remote connection string * - WinPcap/Npcap encountered an error connecting to the rpcapd daemon on the remote machine or retrieving devices on the remote machine + * @deprecated This factory function has been deprecated in favor of 'createRemoteDeviceList' factory for better memory safety. */ + PCPP_DEPRECATED("Please use 'createRemoteDeviceList' factory method instead.") static PcapRemoteDeviceList* getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port); /** @@ -101,7 +104,9 @@ namespace pcpp * - IP address provided is NULL or not valid * - WinPcap/Npcap encountered an error in creating the remote connection string * - WinPcap/Npcap encountered an error connecting to the rpcapd daemon on the remote machine or retrieving devices on the remote machine + * @deprecated This factory function has been deprecated in favor of 'createRemoteDeviceList' factory for better memory safety. */ + PCPP_DEPRECATED("Please use 'createRemoteDeviceList' factory method instead.") static PcapRemoteDeviceList* getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication* remoteAuth); /** From edfa5dee62bebaf1d41875ecd9d0e0b0a5921e96 Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Thu, 4 Jul 2024 00:25:57 +0300 Subject: [PATCH 6/8] Clarified variable name. --- Pcap++/src/PcapRemoteDeviceList.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pcap++/src/PcapRemoteDeviceList.cpp b/Pcap++/src/PcapRemoteDeviceList.cpp index 5ac4e44a21..7700c30af4 100644 --- a/Pcap++/src/PcapRemoteDeviceList.cpp +++ b/Pcap++/src/PcapRemoteDeviceList.cpp @@ -110,9 +110,9 @@ std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceLi } catch (const std::exception& e) { - for (auto dev : devices) + for (auto device : devices) { - delete dev; + delete device; } PCPP_LOG_ERROR("Error creating remote devices: " << e.what()); return nullptr; From 4f66704c8d2eedafeeefca6807429d0da694f374 Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Thu, 4 Jul 2024 00:28:12 +0300 Subject: [PATCH 7/8] Renamed sRemoteAuth to remoteAuthCopy. --- Pcap++/src/PcapRemoteDeviceList.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Pcap++/src/PcapRemoteDeviceList.cpp b/Pcap++/src/PcapRemoteDeviceList.cpp index 7700c30af4..4a1e9eabd8 100644 --- a/Pcap++/src/PcapRemoteDeviceList.cpp +++ b/Pcap++/src/PcapRemoteDeviceList.cpp @@ -74,14 +74,14 @@ PcapRemoteDeviceList* PcapRemoteDeviceList::getRemoteDeviceList(const IPAddress& std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication const* remoteAuth) { - std::shared_ptr sRemoteAuth; + std::shared_ptr remoteAuthCopy; pcap_rmtauth* pRmAuth = nullptr; pcap_rmtauth rmAuth; if (remoteAuth != nullptr) { PCPP_LOG_DEBUG("Authentication requested. Username: " << remoteAuth->userName << ", Password: " << remoteAuth->password); - sRemoteAuth = std::make_shared(*remoteAuth); - rmAuth = sRemoteAuth->getPcapRmAuth(); + remoteAuthCopy = std::make_shared(*remoteAuth); + rmAuth = remoteAuthCopy->getPcapRmAuth(); pRmAuth = &rmAuth; } @@ -101,7 +101,7 @@ std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceLi { for (pcap_if_t* currInterface = interfaceList.get(); currInterface != nullptr; currInterface = currInterface->next) { - auto pNewRemoteDevice = std::unique_ptr(new PcapRemoteDevice(currInterface, sRemoteAuth, ipAddress, port)); + auto pNewRemoteDevice = std::unique_ptr(new PcapRemoteDevice(currInterface, remoteAuthCopy, ipAddress, port)); // Release is called after pushback to prevent memory leaks if vector reallocation fails. // cppcheck-suppress danglingLifetime devices.push_back(pNewRemoteDevice.get()); @@ -118,7 +118,7 @@ std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceLi return nullptr; } - return std::unique_ptr(new PcapRemoteDeviceList(ipAddress, port, sRemoteAuth, devices)); + return std::unique_ptr(new PcapRemoteDeviceList(ipAddress, port, remoteAuthCopy, devices)); } PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const std::string& ipAddrAsString) const From cf3d1c26e9c46408db842d00e57c816294c8371c Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Sun, 7 Jul 2024 07:27:40 +0300 Subject: [PATCH 8/8] Updated variable name to conform with pointer naming conventions. --- Pcap++/src/PcapRemoteDeviceList.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Pcap++/src/PcapRemoteDeviceList.cpp b/Pcap++/src/PcapRemoteDeviceList.cpp index 4a1e9eabd8..bc479a2caf 100644 --- a/Pcap++/src/PcapRemoteDeviceList.cpp +++ b/Pcap++/src/PcapRemoteDeviceList.cpp @@ -74,14 +74,14 @@ PcapRemoteDeviceList* PcapRemoteDeviceList::getRemoteDeviceList(const IPAddress& std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication const* remoteAuth) { - std::shared_ptr remoteAuthCopy; + std::shared_ptr pRemoteAuthCopy; pcap_rmtauth* pRmAuth = nullptr; pcap_rmtauth rmAuth; if (remoteAuth != nullptr) { PCPP_LOG_DEBUG("Authentication requested. Username: " << remoteAuth->userName << ", Password: " << remoteAuth->password); - remoteAuthCopy = std::make_shared(*remoteAuth); - rmAuth = remoteAuthCopy->getPcapRmAuth(); + pRemoteAuthCopy = std::make_shared(*remoteAuth); + rmAuth = pRemoteAuthCopy->getPcapRmAuth(); pRmAuth = &rmAuth; } @@ -101,7 +101,7 @@ std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceLi { for (pcap_if_t* currInterface = interfaceList.get(); currInterface != nullptr; currInterface = currInterface->next) { - auto pNewRemoteDevice = std::unique_ptr(new PcapRemoteDevice(currInterface, remoteAuthCopy, ipAddress, port)); + auto pNewRemoteDevice = std::unique_ptr(new PcapRemoteDevice(currInterface, pRemoteAuthCopy, ipAddress, port)); // Release is called after pushback to prevent memory leaks if vector reallocation fails. // cppcheck-suppress danglingLifetime devices.push_back(pNewRemoteDevice.get()); @@ -118,7 +118,7 @@ std::unique_ptr PcapRemoteDeviceList::createRemoteDeviceLi return nullptr; } - return std::unique_ptr(new PcapRemoteDeviceList(ipAddress, port, remoteAuthCopy, devices)); + return std::unique_ptr(new PcapRemoteDeviceList(ipAddress, port, pRemoteAuthCopy, devices)); } PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const std::string& ipAddrAsString) const