@@ -26,24 +26,23 @@ namespace pcpp
2626{
2727 namespace
2828 {
29- void syncPointerVectors (std::vector<std::unique_ptr< PcapLiveDevice> > const & mainVector,
29+ void syncPointerVectors (PointerVector< PcapLiveDevice> const & mainVector,
3030 std::vector<PcapLiveDevice*>& viewVector)
3131 {
3232 viewVector.resize (mainVector.size ());
3333 // Full update of all elements of the view vector to synchronize them with the main vector.
34- std::transform (mainVector.begin (), mainVector.end (), viewVector.begin (),
35- [](const std::unique_ptr<PcapLiveDevice>& ptr) { return ptr.get (); });
34+ std::copy (mainVector.begin (), mainVector.end (), viewVector.begin ());
3635 }
3736 } // namespace
3837
39- PcapLiveDeviceList::PcapLiveDeviceList () : m_LiveDeviceList (fetchAllLocalDevices()), m_DnsServers(fetchDnsServers())
38+ PcapLiveDeviceList::PcapLiveDeviceList () : Base (fetchAllLocalDevices()), m_DnsServers(fetchDnsServers())
4039 {
41- syncPointerVectors (m_LiveDeviceList , m_LiveDeviceListView);
40+ syncPointerVectors (m_DeviceList , m_LiveDeviceListView);
4241 }
4342
44- std::vector<std::unique_ptr< PcapLiveDevice> > PcapLiveDeviceList::fetchAllLocalDevices ()
43+ PointerVector< PcapLiveDevice> PcapLiveDeviceList::fetchAllLocalDevices ()
4544 {
46- std::vector<std::unique_ptr< PcapLiveDevice> > deviceList;
45+ PointerVector< PcapLiveDevice> deviceList;
4746 std::unique_ptr<pcap_if_t , internal::PcapFreeAllDevsDeleter> interfaceList;
4847 try
4948 {
@@ -65,7 +64,7 @@ namespace pcpp
6564#else // __linux__, __APPLE__, __FreeBSD__
6665 auto dev = std::unique_ptr<PcapLiveDevice>(new PcapLiveDevice (currInterface, true , true , true ));
6766#endif
68- deviceList.push_back (std::move (dev));
67+ deviceList.pushBack (std::move (dev));
6968 }
7069 return deviceList;
7170 }
@@ -289,12 +288,11 @@ namespace pcpp
289288
290289 PcapLiveDevice* PcapLiveDeviceList::getDeviceByIp (const IPv4Address& ipAddr) const
291290 {
292- auto it = std::find_if (m_LiveDeviceList.begin (), m_LiveDeviceList.end (),
293- [&ipAddr](std::unique_ptr<PcapLiveDevice> const & devPtr) {
294- auto devIP = devPtr->getIPv4Address ();
295- return devIP == ipAddr;
296- });
297- return it != m_LiveDeviceList.end () ? it->get () : nullptr ;
291+ auto it = std::find_if (m_DeviceList.begin (), m_DeviceList.end (), [&ipAddr](PcapLiveDevice const * devPtr) {
292+ auto devIP = devPtr->getIPv4Address ();
293+ return devIP == ipAddr;
294+ });
295+ return it != m_DeviceList.end () ? *it : nullptr ;
298296 }
299297
300298 PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp (const IPv6Address& ip6Addr) const
@@ -304,12 +302,11 @@ namespace pcpp
304302
305303 PcapLiveDevice* PcapLiveDeviceList::getDeviceByIp (const IPv6Address& ip6Addr) const
306304 {
307- auto it = std::find_if (m_LiveDeviceList.begin (), m_LiveDeviceList.end (),
308- [&ip6Addr](std::unique_ptr<PcapLiveDevice> const & devPtr) {
309- auto devIP = devPtr->getIPv6Address ();
310- return devIP == ip6Addr;
311- });
312- return it != m_LiveDeviceList.end () ? it->get () : nullptr ;
305+ auto it = std::find_if (m_DeviceList.begin (), m_DeviceList.end (), [&ip6Addr](PcapLiveDevice const * devPtr) {
306+ auto devIP = devPtr->getIPv6Address ();
307+ return devIP == ip6Addr;
308+ });
309+ return it != m_DeviceList.end () ? *it : nullptr ;
313310 }
314311
315312 PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp (const std::string& ipAddrAsString) const
@@ -342,17 +339,16 @@ namespace pcpp
342339 PcapLiveDevice* PcapLiveDeviceList::getDeviceByName (const std::string& name) const
343340 {
344341 PCPP_LOG_DEBUG (" Searching all live devices..." );
345- auto devIter =
346- std::find_if (m_LiveDeviceList.begin (), m_LiveDeviceList.end (),
347- [&name](const std::unique_ptr<PcapLiveDevice>& dev) { return dev->getName () == name; });
342+ auto devIter = std::find_if (m_DeviceList.begin (), m_DeviceList.end (),
343+ [&name](PcapLiveDevice* dev) { return dev->getName () == name; });
348344
349- if (devIter == m_LiveDeviceList .end ())
345+ if (devIter == m_DeviceList .end ())
350346 {
351347 PCPP_LOG_DEBUG (" Found no live device with name '" << name << " '" );
352348 return nullptr ;
353349 }
354350
355- return devIter-> get () ;
351+ return * devIter;
356352 }
357353
358354 PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIpOrName (const std::string& ipOrName) const
@@ -382,10 +378,10 @@ namespace pcpp
382378 {
383379 m_LiveDeviceListView.clear ();
384380
385- m_LiveDeviceList = fetchAllLocalDevices ();
381+ m_DeviceList = fetchAllLocalDevices ();
386382 m_DnsServers = fetchDnsServers ();
387383
388- syncPointerVectors (m_LiveDeviceList , m_LiveDeviceListView);
384+ syncPointerVectors (m_DeviceList , m_LiveDeviceListView);
389385 }
390386
391387} // namespace pcpp
0 commit comments