From 8eb2af5b9f590fc698615624c044897e56303405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Thu, 30 Nov 2023 16:38:52 +0300 Subject: [PATCH 01/17] fix some postfix operators --- Common++/header/LRUList.h | 2 +- Common++/src/SystemUtils.cpp | 8 +-- Common++/src/TablePrinter.cpp | 4 +- Examples/Arping/main.cpp | 4 +- Examples/DNSResolver/main.cpp | 10 ++-- Examples/DnsSpoofing/main.cpp | 14 ++--- Examples/DpdkBridge/main.cpp | 16 ++--- .../AppWorkerThread.h | 10 ++-- Examples/DpdkExample-FilterTraffic/main.cpp | 60 +++++++++---------- Examples/PcapSearch/main.cpp | 4 +- Examples/PfRingExample-FilterTraffic/main.cpp | 14 ++--- Examples/SSLAnalyzer/main.cpp | 28 ++++----- Packet++/src/BgpLayer.cpp | 50 ++++++++-------- Packet++/src/IPv4Layer.cpp | 4 +- Packet++/src/IPv6Extensions.cpp | 8 +-- Packet++/src/Packet.cpp | 4 +- Packet++/src/SSLHandshake.cpp | 26 ++++---- Packet++/src/SdpLayer.cpp | 6 +- Pcap++/src/DpdkDeviceList.cpp | 34 +++++------ Pcap++/src/PcapRemoteDeviceList.cpp | 16 ++--- Pcap++/src/PfRingDeviceList.cpp | 10 ++-- Tests/Pcap++Test/Tests/DpdkTests.cpp | 26 ++++---- Tests/Pcap++Test/Tests/PfRingTests.cpp | 6 +- cppcheckSuppressions.txt | 1 - 24 files changed, 176 insertions(+), 189 deletions(-) diff --git a/Common++/header/LRUList.h b/Common++/header/LRUList.h index b11f1389e7..37b2d895b3 100644 --- a/Common++/header/LRUList.h +++ b/Common++/header/LRUList.h @@ -66,7 +66,7 @@ namespace pcpp if (m_CacheItemsMap.size() > m_MaxSize) { ListIterator lruIter = m_CacheItemsList.end(); - lruIter--; + --lruIter; if (deletedValue != NULL) #if __cplusplus > 199711L || _MSC_VER >= 1800 diff --git a/Common++/src/SystemUtils.cpp b/Common++/src/SystemUtils.cpp index 664b15a7b7..5ca8d4198f 100644 --- a/Common++/src/SystemUtils.cpp +++ b/Common++/src/SystemUtils.cpp @@ -147,9 +147,9 @@ CoreMask getCoreMaskForAllMachineCores() CoreMask createCoreMaskFromCoreVector(std::vector cores) { CoreMask result = 0; - for (std::vector::iterator iter = cores.begin(); iter != cores.end(); iter++) + for (auto iter : cores) { - result |= iter->Mask; + result |= iter.Mask; } return result; @@ -158,9 +158,9 @@ CoreMask createCoreMaskFromCoreVector(std::vector cores) CoreMask createCoreMaskFromCoreIds(std::vector coreIds) { CoreMask result = 0; - for (std::vector::iterator iter = coreIds.begin(); iter != coreIds.end(); iter++) + for (auto iter : coreIds) { - result |= SystemCores::IdToSystemCore[*iter].Mask; + result |= SystemCores::IdToSystemCore[iter].Mask; } return result; diff --git a/Common++/src/TablePrinter.cpp b/Common++/src/TablePrinter.cpp index 19812b6e4c..acdc3a7446 100644 --- a/Common++/src/TablePrinter.cpp +++ b/Common++/src/TablePrinter.cpp @@ -89,9 +89,9 @@ void TablePrinter::printSeparator() } int totalLen = 0; - for (std::vector::iterator iter = m_ColumnWidths.begin(); iter != m_ColumnWidths.end(); iter++) + for (auto iter : m_ColumnWidths) { - totalLen += 2 + (*iter) + 1; + totalLen += 2 + iter + 1; } totalLen++; diff --git a/Examples/Arping/main.cpp b/Examples/Arping/main.cpp index d4b719e897..b51eb03381 100644 --- a/Examples/Arping/main.cpp +++ b/Examples/Arping/main.cpp @@ -89,9 +89,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (std::vector::const_iterator iter = devList.begin(); iter != devList.end(); iter++) + for (auto iter : devList) { - std::cout << " -> Name: '" << (*iter)->getName() << "' IP address: " << (*iter)->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } exit(0); } diff --git a/Examples/DNSResolver/main.cpp b/Examples/DNSResolver/main.cpp index cf95e684cc..5a42c4ff3f 100644 --- a/Examples/DNSResolver/main.cpp +++ b/Examples/DNSResolver/main.cpp @@ -76,9 +76,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (std::vector::const_iterator iter = devList.begin(); iter != devList.end(); iter++) + for (auto iter : devList) { - std::cout << " -> Name: '" << (*iter)->getName() << "' IP address: " << (*iter)->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } exit(0); } @@ -189,11 +189,11 @@ int main(int argc, char* argv[]) { const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); - for (std::vector::const_iterator iter = devList.begin(); iter != devList.end(); iter++) + for (auto iter : devList) { - if ((*iter)->getDefaultGateway().isValid()) + if (iter->getDefaultGateway().isValid()) { - dev = *iter; + dev = iter; break; } } diff --git a/Examples/DnsSpoofing/main.cpp b/Examples/DnsSpoofing/main.cpp index 268231a57e..873d5918da 100644 --- a/Examples/DnsSpoofing/main.cpp +++ b/Examples/DnsSpoofing/main.cpp @@ -128,9 +128,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (std::vector::const_iterator iter = devList.begin(); iter != devList.end(); iter++) + for (auto iter : devList) { - std::cout << " -> Name: '" << (*iter)->getName() << "' IP address: " << (*iter)->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } exit(0); } @@ -172,9 +172,9 @@ void handleDnsRequest(pcpp::RawPacket* packet, pcpp::PcapLiveDevice* dev, void* bool hostMatch = false; // go over all hosts in dnsHostsToSpoof list and see if current query matches one of them - for (std::vector::iterator iter = args->dnsHostsToSpoof.begin(); iter != args->dnsHostsToSpoof.end(); iter++) + for (auto iter : args->dnsHostsToSpoof) { - if (dnsLayer->getQuery(*iter, false) != nullptr) + if (dnsLayer->getQuery(iter, false) != nullptr) { hostMatch = true; break; @@ -288,12 +288,10 @@ void onApplicationInterrupted(void* cookie) std::sort(map2vec.begin(),map2vec.end(), &stringCountComparer); // go over all items (hosts + count) in the sorted vector and print them - for(std::vector >::iterator iter = map2vec.begin(); - iter != map2vec.end(); - iter++) + for(auto iter : map2vec) { std::stringstream values; - values << iter->first << "|" << iter->second; + values << iter.first << "|" << iter.second; printer.printRow(values.str(), '|'); } } diff --git a/Examples/DpdkBridge/main.cpp b/Examples/DpdkBridge/main.cpp index dae8604880..3cc6602df2 100644 --- a/Examples/DpdkBridge/main.cpp +++ b/Examples/DpdkBridge/main.cpp @@ -112,9 +112,9 @@ void listDpdkPorts() // go over all available DPDK devices and print info for each one std::vector deviceList = pcpp::DpdkDeviceList::getInstance().getDpdkDeviceList(); - for (std::vector::iterator iter = deviceList.begin(); iter != deviceList.end(); iter++) + for (auto iter : deviceList) { - pcpp::DpdkDevice* dev = *iter; + pcpp::DpdkDevice* dev = iter; std::cout << " " << " Port #" << dev->getDeviceId() << ":" << " MAC address='" << dev->getMacAddress() << "';" @@ -311,22 +311,22 @@ int main(int argc, char* argv[]) // collect the list of DPDK devices std::vector dpdkDevicesToUse; - for (std::vector::iterator iter = dpdkPortVec.begin(); iter != dpdkPortVec.end(); iter++) + for (auto iter : dpdkPortVec) { - pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(*iter); + pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(iter); if (dev == NULL) { - EXIT_WITH_ERROR("DPDK device for port " << *iter << " doesn't exist"); + EXIT_WITH_ERROR("DPDK device for port " << iter << " doesn't exist"); } dpdkDevicesToUse.push_back(dev); } // go over all devices and open them - for (std::vector::iterator iter = dpdkDevicesToUse.begin(); iter != dpdkDevicesToUse.end(); iter++) + for (auto iter : dpdkDevicesToUse) { - if (!(*iter)->openMultiQueues(queueQuantity, 1)) + if (!iter->openMultiQueues(queueQuantity, 1)) { - EXIT_WITH_ERROR("Couldn't open DPDK device #" << (*iter)->getDeviceId() << ", PMD '" << (*iter)->getPMDName() << "'"); + EXIT_WITH_ERROR("Couldn't open DPDK device #" << iter->getDeviceId() << ", PMD '" << iter->getPMDName() << "'"); } } diff --git a/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h b/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h index f074cf0af0..a015e9b281 100644 --- a/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h +++ b/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h @@ -74,15 +74,15 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread while (!m_Stop) { // go over all DPDK devices configured for this worker/core - for (InputDataConfig::iterator iter = m_WorkerConfig.InDataCfg.begin(); iter != m_WorkerConfig.InDataCfg.end(); iter++) + for (auto iter : m_WorkerConfig.InDataCfg) { // for each DPDK device go over all RX queues configured for this worker/core - for (std::vector::iterator iter2 = iter->second.begin(); iter2 != iter->second.end(); iter2++) + for (auto iter2 = iter.second) { - pcpp::DpdkDevice* dev = iter->first; + pcpp::DpdkDevice* dev = iter.first; // receive packets from network on the specified DPDK device and RX queue - uint16_t packetsReceived = dev->receivePackets(packetArr, MAX_RECEIVE_BURST, *iter2); + uint16_t packetsReceived = dev->receivePackets(packetArr, MAX_RECEIVE_BURST, iter2); for (int i = 0; i < packetsReceived; i++) { @@ -96,7 +96,7 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread // hash the packet by 5-tuple and look in the flow table to see whether this packet belongs to an existing or new flow uint32_t hash = pcpp::hash5Tuple(&parsedPacket); - std::map::const_iterator iter3 = m_FlowTable.find(hash); + auto iter3 = m_FlowTable.find(hash); // if packet belongs to an already existing flow if (iter3 != m_FlowTable.end() && iter3->second) diff --git a/Examples/DpdkExample-FilterTraffic/main.cpp b/Examples/DpdkExample-FilterTraffic/main.cpp index 132740048b..09fc474aea 100644 --- a/Examples/DpdkExample-FilterTraffic/main.cpp +++ b/Examples/DpdkExample-FilterTraffic/main.cpp @@ -136,9 +136,9 @@ void listDpdkPorts() // go over all available DPDK devices and print info for each one std::vector deviceList = pcpp::DpdkDeviceList::getInstance().getDpdkDeviceList(); - for (std::vector::iterator iter = deviceList.begin(); iter != deviceList.end(); iter++) + for (auto iter : deviceList) { - pcpp::DpdkDevice* dev = *iter; + pcpp::DpdkDevice* dev = iter; std::cout << " " << " Port #" << dev->getDeviceId() << ":" << " MAC address='" << dev->getMacAddress() << "';" @@ -160,11 +160,11 @@ void prepareCoreConfiguration(std::vector& dpdkDevicesToUse, // create a list of pairs of DpdkDevice and RX queues for all RX queues in all requested devices int totalNumOfRxQueues = 0; std::vector > deviceAndRxQVec; - for (std::vector::iterator iter = dpdkDevicesToUse.begin(); iter != dpdkDevicesToUse.end(); iter++) + for (auto iter : dpdkDevicesToUse) { for (int rxQueueIndex = 0; rxQueueIndex < rxQueues; rxQueueIndex++) { - std::pair curPair(*iter, rxQueueIndex); + std::pair curPair(iter, rxQueueIndex); deviceAndRxQVec.push_back(curPair); } totalNumOfRxQueues += rxQueues; @@ -177,10 +177,10 @@ void prepareCoreConfiguration(std::vector& dpdkDevicesToUse, // prepare the configuration for every core: divide the devices and RX queue for each device with the various cores int i = 0; std::vector >::iterator pairVecIter = deviceAndRxQVec.begin(); - for (std::vector::iterator iter = coresToUse.begin(); iter != coresToUse.end(); iter++) + for (auto iter : coresToUse) { - std::cout << "Using core " << (int)iter->Id << std::endl; - workerConfigArr[i].CoreId = iter->Id; + std::cout << "Using core " << (int)iter.Id << std::endl; + workerConfigArr[i].CoreId = iter.Id; workerConfigArr[i].WriteMatchedPacketsToFile = writePacketsToDisk; std::stringstream packetFileName; @@ -193,23 +193,23 @@ void prepareCoreConfiguration(std::vector& dpdkDevicesToUse, if (pairVecIter == deviceAndRxQVec.end()) break; workerConfigArr[i].InDataCfg[pairVecIter->first].push_back(pairVecIter->second); - pairVecIter++; + ++pairVecIter; } if (rxQueuesRemainder > 0 && (pairVecIter != deviceAndRxQVec.end())) { workerConfigArr[i].InDataCfg[pairVecIter->first].push_back(pairVecIter->second); - pairVecIter++; + ++pairVecIter; rxQueuesRemainder--; } // print configuration for core std::cout << " Core configuration:" << std::endl; - for (InputDataConfig::iterator iter2 = workerConfigArr[i].InDataCfg.begin(); iter2 != workerConfigArr[i].InDataCfg.end(); iter2++) + for (auto iter2 : workerConfigArr[i].InDataCfg) { - std::cout << " DPDK device#" << iter2->first->getDeviceId() << ": "; - for (std::vector::iterator iter3 = iter2->second.begin(); iter3 != iter2->second.end(); iter3++) + std::cout << " DPDK device#" << iter2.first->getDeviceId() << ": "; + for (auto iter3 : iter2.second) { - std::cout << "RX-Queue#" << *iter3 << "; "; + std::cout << "RX-Queue#" << iter3 << "; "; } std::cout << std::endl; } @@ -250,9 +250,9 @@ void onApplicationInterrupted(void* cookie) // print final stats for every worker thread plus sum of all threads and free worker threads memory PacketStats aggregatedStats; - for (std::vector::iterator iter = args->workerThreadsVector->begin(); iter != args->workerThreadsVector->end(); iter++) + for (auto iter : *(args->workerThreadsVector)) { - AppWorkerThread* thread = (AppWorkerThread*)(*iter); + AppWorkerThread* thread = (AppWorkerThread*)(iter); PacketStats threadStats = thread->getStats(); aggregatedStats.collectStats(threadStats); printer.printRow(threadStats.getStatValuesAsString("|"), '|'); @@ -489,39 +489,39 @@ int main(int argc, char* argv[]) // collect the list of DPDK devices std::vector dpdkDevicesToUse; - for (std::vector::iterator iter = dpdkPortVec.begin(); iter != dpdkPortVec.end(); iter++) + for (auto iter : dpdkPortVec) { - pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(*iter); + pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(iter); if (dev == NULL) { - EXIT_WITH_ERROR("DPDK device for port " << *iter << " doesn't exist"); + EXIT_WITH_ERROR("DPDK device for port " << iter << " doesn't exist"); } dpdkDevicesToUse.push_back(dev); } // go over all devices and open them - for (std::vector::iterator iter = dpdkDevicesToUse.begin(); iter != dpdkDevicesToUse.end(); iter++) + for (auto iter : dpdkDevicesToUse) { - if (rxQueues > (*iter)->getTotalNumOfRxQueues()) + if (rxQueues > iter->getTotalNumOfRxQueues()) { - EXIT_WITH_ERROR("Number of RX errors cannot exceed the max allowed by the device which is " << (*iter)->getTotalNumOfRxQueues()); + EXIT_WITH_ERROR("Number of RX errors cannot exceed the max allowed by the device which is " << iter->getTotalNumOfRxQueues()); } - if (txQueues > (*iter)->getTotalNumOfTxQueues()) + if (txQueues > iter->getTotalNumOfTxQueues()) { - EXIT_WITH_ERROR("Number of TX errors cannot exceed the max allowed by the device which is " << (*iter)->getTotalNumOfTxQueues()); + EXIT_WITH_ERROR("Number of TX errors cannot exceed the max allowed by the device which is " << iter->getTotalNumOfTxQueues()); } - if (!(*iter)->openMultiQueues(rxQueues, txQueues)) + if (!iter->openMultiQueues(rxQueues, txQueues)) { - EXIT_WITH_ERROR("Couldn't open DPDK device #" << (*iter)->getDeviceId() << ", PMD '" << (*iter)->getPMDName() << "'"); + EXIT_WITH_ERROR("Couldn't open DPDK device #" << iter->getDeviceId() << ", PMD '" << iter->getPMDName() << "'"); } std::cout - << "Opened device #" << (*iter)->getDeviceId() + << "Opened device #" << iter->getDeviceId() << " with " << rxQueues << " RX queues and " << txQueues << " TX queues." << " RSS hash functions:" << std::endl; - std::vector rssHashFunctions = (*iter)->rssHashFunctionMaskToString((*iter)->getConfiguredRssHashFunction()); - for(std::vector::iterator it = rssHashFunctions.begin(); it != rssHashFunctions.end(); ++it) + std::vector rssHashFunctions = iter->rssHashFunctionMaskToString(iter->getConfiguredRssHashFunction()); + for(auto it : rssHashFunctions) { - std::cout << " " << (*it) << std::endl; + std::cout << " " << it << std::endl; } } @@ -541,7 +541,7 @@ int main(int argc, char* argv[]) // create worker thread for every core std::vector workerThreadVec; int i = 0; - for (std::vector::iterator iter = coresToUse.begin(); iter != coresToUse.end(); iter++) + for (auto iter = coresToUse.begin(); iter != coresToUse.end(); iter++) { AppWorkerThread* newWorker = new AppWorkerThread(workerConfigArr[i], matchingEngine); workerThreadVec.push_back(newWorker); diff --git a/Examples/PcapSearch/main.cpp b/Examples/PcapSearch/main.cpp index 1d7b7c0ed5..81327c21bd 100644 --- a/Examples/PcapSearch/main.cpp +++ b/Examples/PcapSearch/main.cpp @@ -166,8 +166,8 @@ int searchPcap(const std::string& pcapFilePath, std::string searchCriteria, std: // print layer by layer by layer as we want to add a few spaces before each layer std::vector packetLayers; parsedPacket.toStringList(packetLayers); - for (std::vector::iterator iter = packetLayers.begin(); iter != packetLayers.end(); iter++) - (*detailedReportFile) << "\n " << (*iter); + for (auto iter : packetLayers) + (*detailedReportFile) << "\n " << iter; (*detailedReportFile) << std::endl; } diff --git a/Examples/PfRingExample-FilterTraffic/main.cpp b/Examples/PfRingExample-FilterTraffic/main.cpp index 7fe3ef9070..eb6c3aaa61 100644 --- a/Examples/PfRingExample-FilterTraffic/main.cpp +++ b/Examples/PfRingExample-FilterTraffic/main.cpp @@ -135,12 +135,12 @@ void listPfRingDevices() pcpp::Logger::getInstance().suppressLogs(); const std::vector& devList = pcpp::PfRingDeviceList::getInstance().getPfRingDevicesList(); - for (std::vector::const_iterator iter = devList.begin(); iter != devList.end(); iter++) + for (auto iter : devList) { std::ostringstream interfaceIndex; - if ((*iter)->getInterfaceIndex() <= 9999) + if (iter->getInterfaceIndex() <= 9999) { - interfaceIndex << (*iter)->getInterfaceIndex(); + interfaceIndex << iter->getInterfaceIndex(); } else { @@ -148,11 +148,11 @@ void listPfRingDevices() } std::cout - << " -> Name: " << std::left << std::setw(8) << (*iter)->getDeviceName() + << " -> Name: " << std::left << std::setw(8) << iter->getDeviceName() << " Index: " << std::setw(5) << interfaceIndex.str() - << " MAC address: " << std::setw(19) << ((*iter)->getMacAddress() == pcpp::MacAddress::Zero ? "N/A" : (*iter)->getMacAddress().toString()) - << " Available RX channels: " << std::setw(3) << (int)(*iter)->getTotalNumOfRxChannels() - << " MTU: " << (*iter)->getMtu() + << " MAC address: " << std::setw(19) << (iter->getMacAddress() == pcpp::MacAddress::Zero ? "N/A" : iter->getMacAddress().toString()) + << " Available RX channels: " << std::setw(3) << (int)iter->getTotalNumOfRxChannels() + << " MTU: " << iter->getMtu() << std::endl; } diff --git a/Examples/SSLAnalyzer/main.cpp b/Examples/SSLAnalyzer/main.cpp index 8ed220c976..b8e237aa02 100644 --- a/Examples/SSLAnalyzer/main.cpp +++ b/Examples/SSLAnalyzer/main.cpp @@ -124,9 +124,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (std::vector::const_iterator iter = devList.begin(); iter != devList.end(); iter++) + for (auto iter : devList) { - std::cout << " -> Name: '" << (*iter)->getName() << "' IP address: " << (*iter)->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } exit(0); } @@ -211,12 +211,10 @@ void printServerNames(ClientHelloStats& clientHelloStatsCollector) std::sort(map2vec.begin(),map2vec.end(), &stringCountComparer); // go over all items (names + count) in the sorted vector and print them - for(std::vector >::iterator iter = map2vec.begin(); - iter != map2vec.end(); - iter++) + for(auto iter : map2vec) { std::stringstream values; - values << iter->first << "|" << iter->second; + values << iter.first << "|" << iter.second; printer.printRow(values.str(), '|'); } } @@ -242,12 +240,10 @@ void printVersions(std::map& versionMap, const std::string& headl std::sort(map2vec.begin(),map2vec.end(), &uint16CountComparer); // go over all items (names + count) in the sorted vector and print them - for(std::vector >::iterator iter = map2vec.begin(); - iter != map2vec.end(); - iter++) + for(auto iter : map2vec) { std::stringstream values; - values << pcpp::SSLVersion(iter->first).toString() << "|" << iter->second; + values << pcpp::SSLVersion(iter.first).toString() << "|" << iter.second; printer.printRow(values.str(), '|'); } } @@ -273,12 +269,10 @@ void printCipherSuites(ServerHelloStats& serverHelloStats) std::sort(map2vec.begin(),map2vec.end(), &stringCountComparer); // go over all items (names + count) in the sorted vector and print them - for(std::vector >::iterator iter = map2vec.begin(); - iter != map2vec.end(); - iter++) + for(auto iter : map2vec) { std::stringstream values; - values << iter->first << "|" << iter->second; + values << iter.first << "|" << iter.second; printer.printRow(values.str(), '|'); } } @@ -301,12 +295,10 @@ void printPorts(SSLGeneralStats& stats) std::sort(map2vec.begin(),map2vec.end(), &uint16CountComparer); // go over all items (names + count) in the sorted vector and print them - for(std::vector >::iterator iter = map2vec.begin(); - iter != map2vec.end(); - iter++) + for(auto iter : map2vec) { std::stringstream values; - values << iter->first << "|" << iter->second; + values << iter.first << "|" << iter.second; printer.printRow(values.str(), '|'); } } diff --git a/Packet++/src/BgpLayer.cpp b/Packet++/src/BgpLayer.cpp index ddf4c91b2d..fc0fbfaf75 100644 --- a/Packet++/src/BgpLayer.cpp +++ b/Packet++/src/BgpLayer.cpp @@ -163,26 +163,26 @@ size_t BgpOpenMessageLayer::optionalParamsToByteArray(const std::vector::const_iterator iter = optionalParams.begin(); iter != optionalParams.end(); iter++) + for (auto iter : optionalParams) { - if (iter->length > 32) + if (iter.length > 32) { - PCPP_LOG_ERROR("Illegal optional parameter length " << (int)iter->length << ", must be 32 bytes or less"); + PCPP_LOG_ERROR("Illegal optional parameter length " << (int)iter.length << ", must be 32 bytes or less"); break; // illegal value } - size_t curDataSize = 2*sizeof(uint8_t) + (size_t)iter->length; + size_t curDataSize = 2*sizeof(uint8_t) + (size_t)iter.length; if (dataLen + curDataSize > maxByteArrSize) { break; } - resultByteArr[0] = iter->type; - resultByteArr[1] = iter->length; - if (iter->length > 0) + resultByteArr[0] = iter.type; + resultByteArr[1] = iter.length; + if (iter.length > 0) { - memcpy(resultByteArr + 2*sizeof(uint8_t), iter->value, iter->length); + memcpy(resultByteArr + 2*sizeof(uint8_t), iter.value, iter.length); } dataLen += curDataSize; @@ -416,13 +416,13 @@ size_t BgpUpdateMessageLayer::prefixAndIPDataToByteArray(const std::vector::const_iterator iter = prefixAndIpData.begin(); iter != prefixAndIpData.end(); iter++) + for (auto iter : prefixAndIpData) { uint8_t curData[5]; - curData[0] = iter->prefix; + curData[0] = iter.prefix; size_t curDataSize = 1; - const uint8_t* octets = iter->ipAddr.toBytes(); - if (iter->prefix == 32) + const uint8_t* octets = iter.ipAddr.toBytes(); + if (iter.prefix == 32) { curDataSize += 4; curData[1] = octets[0]; @@ -430,27 +430,27 @@ size_t BgpUpdateMessageLayer::prefixAndIPDataToByteArray(const std::vectorprefix == 24) + else if (iter.prefix == 24) { curDataSize += 3; curData[1] = octets[0]; curData[2] = octets[1]; curData[3] = octets[2]; } - else if (iter->prefix == 16) + else if (iter.prefix == 16) { curDataSize += 2; curData[1] = octets[0]; curData[2] = octets[1]; } - else if (iter->prefix == 8) + else if (iter.prefix == 8) { curDataSize += 1; curData[1] = octets[0]; } else { - PCPP_LOG_ERROR("Illegal prefix value " << (int)iter->prefix); + PCPP_LOG_ERROR("Illegal prefix value " << (int)iter.prefix); break; // illegal value } @@ -477,27 +477,27 @@ size_t BgpUpdateMessageLayer::pathAttributesToByteArray(const std::vector::const_iterator iter = pathAttributes.begin(); iter != pathAttributes.end(); iter++) + for (auto iter : pathAttributes) { - if (iter->length > 32) + if (iter.length > 32) { - PCPP_LOG_ERROR("Illegal path attribute length " << (int)iter->length); + PCPP_LOG_ERROR("Illegal path attribute length " << (int)iter.length); break; // illegal value } - size_t curDataSize = 3*sizeof(uint8_t) + (size_t)iter->length; + size_t curDataSize = 3*sizeof(uint8_t) + (size_t)iter.length; if (dataLen + curDataSize > maxByteArrSize) { break; } - resultByteArr[0] = iter->flags; - resultByteArr[1] = iter->type; - resultByteArr[2] = iter->length; - if (iter->length > 0) + resultByteArr[0] = iter.flags; + resultByteArr[1] = iter.type; + resultByteArr[2] = iter.length; + if (iter.length > 0) { - memcpy(resultByteArr + 3*sizeof(uint8_t), iter->data, iter->length); + memcpy(resultByteArr + 3*sizeof(uint8_t), iter.data, iter.length); } dataLen += curDataSize; diff --git a/Packet++/src/IPv4Layer.cpp b/Packet++/src/IPv4Layer.cpp index c1a2de8004..47fa6f1949 100644 --- a/Packet++/src/IPv4Layer.cpp +++ b/Packet++/src/IPv4Layer.cpp @@ -37,9 +37,9 @@ IPv4OptionBuilder::IPv4OptionBuilder(IPv4OptionTypes optionType, const std::vect m_RecValue[curOffset++] = 0; // init pointer value bool firstZero = false; - for (std::vector::const_iterator iter = ipList.begin(); iter != ipList.end(); iter++) + for (auto iter : ipList) { - uint32_t ipAddrAsInt = iter->toInt(); + uint32_t ipAddrAsInt = iter.toInt(); if (!firstZero) m_RecValue[0] += (uint8_t)4; diff --git a/Packet++/src/IPv6Extensions.cpp b/Packet++/src/IPv6Extensions.cpp index 2ce69ab704..c63ad63167 100644 --- a/Packet++/src/IPv6Extensions.cpp +++ b/Packet++/src/IPv6Extensions.cpp @@ -149,9 +149,9 @@ IPv6TLVOptionHeader::IPv6TLVOptionHeader(const std::vector size_t totalSize = sizeof(uint16_t); // nextHeader + headerLen - for (std::vector::const_iterator iter = options.begin(); iter != options.end(); iter++) + for (auto iter : options) { - IPv6Option option = iter->build(); + IPv6Option option = iter.build(); totalSize += option.getTotalSize(); option.purgeRecordData(); } @@ -166,9 +166,9 @@ IPv6TLVOptionHeader::IPv6TLVOptionHeader(const std::vector size_t offset = sizeof(uint16_t); - for (std::vector::const_iterator iter = options.begin(); iter != options.end(); iter++) + for (auto iter : options) { - IPv6Option option = iter->build(); + IPv6Option option = iter.build(); memcpy(getDataPtr() + offset, option.getRecordBasePtr(), option.getTotalSize()); offset += option.getTotalSize(); option.purgeRecordData(); diff --git a/Packet++/src/Packet.cpp b/Packet++/src/Packet.cpp index 339efeba5c..609bf5c6b8 100644 --- a/Packet++/src/Packet.cpp +++ b/Packet++/src/Packet.cpp @@ -793,9 +793,9 @@ std::string Packet::toString(bool timeAsLocalTime) const std::vector stringList; std::string result; toStringList(stringList, timeAsLocalTime); - for (std::vector::iterator iter = stringList.begin(); iter != stringList.end(); iter++) + for (auto iter : stringList) { - result += *iter + '\n'; + result += iter + '\n'; } return result; diff --git a/Packet++/src/SSLHandshake.cpp b/Packet++/src/SSLHandshake.cpp index 39601eecea..3d7a9420a2 100644 --- a/Packet++/src/SSLHandshake.cpp +++ b/Packet++/src/SSLHandshake.cpp @@ -1502,9 +1502,9 @@ SSLClientHelloMessage::ClientHelloTLSFingerprint SSLClientHelloMessage::generate if (supportedGroupsExt != nullptr) { std::vector supportedGroups = supportedGroupsExt->getSupportedGroups(); - for (std::vector::const_iterator iter = supportedGroups.begin(); iter != supportedGroups.end(); iter++) - if (GreaseSet.find(*iter) == GreaseSet.end()) - result.supportedGroups.push_back(*iter); + for (auto iter : supportedGroups) + if (GreaseSet.find(iter) == GreaseSet.end()) + result.supportedGroups.push_back(iter); } // extract EC point formats @@ -1536,36 +1536,36 @@ std::string SSLClientHelloMessage::ClientHelloTLSFingerprint::toString() // add cipher suites bool firstCipher = true; - for (std::vector::const_iterator iter = cipherSuites.begin(); iter != cipherSuites.end(); iter++) + for (auto iter : cipherSuites) { - tlsFingerprint << (firstCipher ? "" : "-") << *iter; + tlsFingerprint << (firstCipher ? "" : "-") << iter; firstCipher = false; } tlsFingerprint << ","; // add extensions bool firstExtension = true; - for (std::vector::const_iterator iter = extensions.begin(); iter != extensions.end(); iter++) + for (auto iter : extensions) { - tlsFingerprint << (firstExtension ? "" : "-") << *iter; + tlsFingerprint << (firstExtension ? "" : "-") << iter; firstExtension = false; } tlsFingerprint << ","; // add supported groups bool firstGroup = true; - for (std::vector::const_iterator iter = supportedGroups.begin(); iter != supportedGroups.end(); iter++) + for (auto iter : supportedGroups) { - tlsFingerprint << (firstGroup ? "" : "-") << (*iter); + tlsFingerprint << (firstGroup ? "" : "-") << iter; firstGroup = false; } tlsFingerprint << ","; // add EC point formats bool firstPointFormat = true; - for (std::vector::iterator iter = ecPointFormats.begin(); iter != ecPointFormats.end(); iter++) + for (auto iter : ecPointFormats) { - tlsFingerprint << (firstPointFormat ? "" : "-") << (int)(*iter); + tlsFingerprint << (firstPointFormat ? "" : "-") << (int)iter; firstPointFormat = false; } @@ -1793,9 +1793,9 @@ std::string SSLServerHelloMessage::ServerHelloTLSFingerprint::toString() // add extensions bool firstExtension = true; - for (std::vector::const_iterator iter = extensions.begin(); iter != extensions.end(); iter++) + for (auto iter : extensions) { - tlsFingerprint << (firstExtension ? "" : "-") << *iter; + tlsFingerprint << (firstExtension ? "" : "-") << iter; firstExtension = false; } diff --git a/Packet++/src/SdpLayer.cpp b/Packet++/src/SdpLayer.cpp index b90d61c095..983cceaa98 100644 --- a/Packet++/src/SdpLayer.cpp +++ b/Packet++/src/SdpLayer.cpp @@ -120,11 +120,11 @@ bool SdpLayer::addMediaDescription(const std::string& mediaType, uint16_t mediaP } - for (std::vector::iterator iter = mediaAttributes.begin(); iter != mediaAttributes.end(); iter++) + for (auto iter : mediaAttributes) { - if (addField(PCPP_SDP_MEDIA_ATTRIBUTE_FIELD, *iter) == nullptr) + if (addField(PCPP_SDP_MEDIA_ATTRIBUTE_FIELD, iter) == nullptr) { - PCPP_LOG_ERROR("Failed to add media attribute '" << *iter << "'"); + PCPP_LOG_ERROR("Failed to add media attribute '" << iter << "'"); return false; } } diff --git a/Pcap++/src/DpdkDeviceList.cpp b/Pcap++/src/DpdkDeviceList.cpp index 063ae58aa6..0e229141f8 100644 --- a/Pcap++/src/DpdkDeviceList.cpp +++ b/Pcap++/src/DpdkDeviceList.cpp @@ -64,9 +64,9 @@ DpdkDeviceList::DpdkDeviceList() DpdkDeviceList::~DpdkDeviceList() { - for (std::vector::iterator iter = m_DpdkDeviceList.begin(); iter != m_DpdkDeviceList.end(); iter++) + for (auto iter : m_DpdkDeviceList) { - delete (*iter); + delete iter; } m_DpdkDeviceList.clear(); @@ -223,10 +223,10 @@ DpdkDevice* DpdkDeviceList::getDeviceByPciAddress(const std::string& pciAddr) co return NULL; } - for (std::vector::const_iterator iter = m_DpdkDeviceList.begin(); iter != m_DpdkDeviceList.end(); iter++) + for (auto iter : m_DpdkDeviceList) { - if ((*iter)->getPciAddress() == pciAddr) - return (*iter); + if (iter->getPciAddress() == pciAddr) + return iter; } return NULL; @@ -369,7 +369,7 @@ bool DpdkDeviceList::startDpdkWorkerThreads(CoreMask coreMask, std::vector::iterator iter = workerThreadsVec.begin(); + auto iter = workerThreadsVec.begin(); while (iter != workerThreadsVec.end()) { SystemCore core = SystemCores::IdToSystemCore[index]; @@ -382,19 +382,19 @@ bool DpdkDeviceList::startDpdkWorkerThreads(CoreMask coreMask, std::vector::iterator iter2 = workerThreadsVec.begin(); iter2 != iter; iter2++) + for (auto iter2 : workerThreadsVec) { - (*iter)->stop(); - rte_eal_wait_lcore((*iter)->getCoreId()); - PCPP_LOG_DEBUG("Thread on core [" << (*iter)->getCoreId() << "] stopped"); + iter->stop(); + rte_eal_wait_lcore(iter->getCoreId()); + PCPP_LOG_DEBUG("Thread on core [" << iter->getCoreId() << "] stopped"); } PCPP_LOG_ERROR("Cannot create worker thread #" << core.Id << ". Error was: [" << strerror(err) << "]"); return false; } - m_WorkerThreads.push_back(*iter); + m_WorkerThreads.push_back(iter); - index++; - iter++; + ++index; + ++iter; } return true; @@ -408,11 +408,11 @@ void DpdkDeviceList::stopDpdkWorkerThreads() return; } - for (std::vector::iterator iter = m_WorkerThreads.begin(); iter != m_WorkerThreads.end(); iter++) + for (auto iter : m_WorkerThreads) { - (*iter)->stop(); - rte_eal_wait_lcore((*iter)->getCoreId()); - PCPP_LOG_DEBUG("Thread on core [" << (*iter)->getCoreId() << "] stopped"); + iter->stop(); + rte_eal_wait_lcore(iter->getCoreId()); + PCPP_LOG_DEBUG("Thread on core [" << iter->getCoreId() << "] stopped"); } m_WorkerThreads.clear(); diff --git a/Pcap++/src/PcapRemoteDeviceList.cpp b/Pcap++/src/PcapRemoteDeviceList.cpp index 94197d3513..b63923b18d 100644 --- a/Pcap++/src/PcapRemoteDeviceList.cpp +++ b/Pcap++/src/PcapRemoteDeviceList.cpp @@ -109,16 +109,16 @@ PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPv4Address& i for(ConstRemoteDeviceListIterator devIter = m_RemoteDeviceList.begin(); devIter != m_RemoteDeviceList.end(); devIter++) { PCPP_LOG_DEBUG("Searching device '" << (*devIter)->m_Name << "'. Searching all addresses..."); - for(std::vector::iterator addrIter = (*devIter)->m_Addresses.begin(); addrIter != (*devIter)->m_Addresses.end(); addrIter++) + for(auto addrIter : (*devIter)->m_Addresses) { - if (Logger::getInstance().isDebugEnabled(PcapLogModuleRemoteDevice) && addrIter->addr != NULL) + if (Logger::getInstance().isDebugEnabled(PcapLogModuleRemoteDevice) && addrIter.addr != NULL) { char addrAsString[INET6_ADDRSTRLEN]; - internal::sockaddr2string(addrIter->addr, addrAsString); + internal::sockaddr2string(addrIter.addr, addrAsString); PCPP_LOG_DEBUG("Searching address " << addrAsString); } - in_addr* currAddr = internal::sockaddr2in_addr(addrIter->addr); + in_addr* currAddr = internal::sockaddr2in_addr(addrIter.addr); if (currAddr == NULL) { PCPP_LOG_DEBUG("Address is NULL"); @@ -143,16 +143,16 @@ PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPv6Address& i for(ConstRemoteDeviceListIterator devIter = m_RemoteDeviceList.begin(); devIter != m_RemoteDeviceList.end(); devIter++) { PCPP_LOG_DEBUG("Searching device '" << (*devIter)->m_Name << "'. Searching all addresses..."); - for(std::vector::iterator addrIter = (*devIter)->m_Addresses.begin(); addrIter != (*devIter)->m_Addresses.end(); addrIter++) + for(auto addrIter : (*devIter)->m_Addresses) { - if (Logger::getInstance().isDebugEnabled(PcapLogModuleRemoteDevice) && addrIter->addr != NULL) + if (Logger::getInstance().isDebugEnabled(PcapLogModuleRemoteDevice) && addrIter.addr != NULL) { char addrAsString[INET6_ADDRSTRLEN]; - internal::sockaddr2string(addrIter->addr, addrAsString); + internal::sockaddr2string(addrIter.addr, addrAsString); PCPP_LOG_DEBUG("Searching address " << addrAsString); } - in6_addr* currAddr = internal::sockaddr2in6_addr(addrIter->addr); + in6_addr* currAddr = internal::sockaddr2in6_addr(addrIter.addr); if (currAddr == NULL) { PCPP_LOG_DEBUG("Address is NULL"); diff --git a/Pcap++/src/PfRingDeviceList.cpp b/Pcap++/src/PfRingDeviceList.cpp index 5fe1a575b7..9732b3e3b5 100644 --- a/Pcap++/src/PfRingDeviceList.cpp +++ b/Pcap++/src/PfRingDeviceList.cpp @@ -59,19 +59,19 @@ PfRingDeviceList::PfRingDeviceList() PfRingDeviceList::~PfRingDeviceList() { - for(std::vector::iterator devIter = m_PfRingDeviceList.begin(); devIter != m_PfRingDeviceList.end(); devIter++) + for(auto devIter : m_PfRingDeviceList) { - delete (*devIter); + delete devIter; } } PfRingDevice* PfRingDeviceList::getPfRingDeviceByName(const std::string &devName) const { PCPP_LOG_DEBUG("Searching all live devices..."); - for(std::vector::const_iterator devIter = m_PfRingDeviceList.begin(); devIter != m_PfRingDeviceList.end(); devIter++) + for(auto devIter : m_PfRingDeviceList) { - if ((*devIter)->getDeviceName() == devName) - return (*devIter); + if (devIter->getDeviceName() == devName) + return devIter; } PCPP_LOG_DEBUG("Found no PF_RING devices with name '" << devName << "'"); diff --git a/Tests/Pcap++Test/Tests/DpdkTests.cpp b/Tests/Pcap++Test/Tests/DpdkTests.cpp index ffe7c1fc61..5deea88592 100644 --- a/Tests/Pcap++Test/Tests/DpdkTests.cpp +++ b/Tests/Pcap++Test/Tests/DpdkTests.cpp @@ -485,25 +485,25 @@ PTF_TEST_CASE(TestDpdkMultiThread) PTF_ASSERT_EQUAL(res.size(), 0); if (PTF_IS_VERBOSE_MODE) { - for (std::map >::iterator iter = res.begin(); iter != res.end(); iter++) + for (auto iter = res) { - PTF_PRINT_VERBOSE("Same flow exists in core " << firstCoreId << " and core " << secondCoreId << ". Flow key = " << iter->first); + PTF_PRINT_VERBOSE("Same flow exists in core " << firstCoreId << " and core " << secondCoreId << ". Flow key = " << iter.first); std::ostringstream stream; - stream << "Core" << firstCoreId << "_Flow_" << std::hex << iter->first << ".pcap"; + stream << "Core" << firstCoreId << "_Flow_" << std::hex << iter.first << ".pcap"; pcpp::PcapFileWriterDevice writerDev(stream.str()); writerDev.open(); - writerDev.writePackets(iter->second.first); + writerDev.writePackets(iter.second.first); writerDev.close(); std::ostringstream stream2; - stream2 << "Core" << secondCoreId << "_Flow_" << std::hex << iter->first << ".pcap"; + stream2 << "Core" << secondCoreId << "_Flow_" << std::hex << iter.first << ".pcap"; pcpp::PcapFileWriterDevice writerDev2(stream2.str()); writerDev2.open(); - writerDev2.writePackets(iter->second.second); + writerDev2.writePackets(iter.second.second); writerDev2.close(); - iter->second.first.clear(); - iter->second.second.clear(); + iter.second.first.clear(); + iter.second.second.clear(); } } @@ -513,10 +513,10 @@ PTF_TEST_CASE(TestDpdkMultiThread) if (PTF_IS_VERBOSE_MODE) { - for(std::map::iterator iter = packetDataMultiThread[firstCoreId].FlowKeys.begin(); iter != packetDataMultiThread[firstCoreId].FlowKeys.end(); iter++) + for(auto iter : packetDataMultiThread[firstCoreId].FlowKeys) { - PTF_PRINT_VERBOSE("Key=0x" << std::hex << iter->first << "; Value=" << std::dec << iter->second.size()); - iter->second.clear(); + PTF_PRINT_VERBOSE("Key=0x" << std::hex << iter.first << "; Value=" << std::dec << iter.second.size()); + iter.second.clear(); } } @@ -804,9 +804,9 @@ PTF_TEST_CASE(TestDpdkDeviceWorkerThreads) // that total amount of packets received by all threads is greater than zero int packetCount = 0; - for (std::vector::iterator iter = workerThreadVec.begin(); iter != workerThreadVec.end(); iter++) + for (auto iter : workerThreadVec) { - DpdkTestWorkerThread* thread = (DpdkTestWorkerThread*)(*iter); + DpdkTestWorkerThread* thread = (DpdkTestWorkerThread*)iter; PTF_ASSERT_TRUE(thread->threadRanAndStopped()); packetCount += thread->getPacketCount(); PTF_PRINT_VERBOSE("Worker thread on core " << thread->getCoreId() << " captured " << thread->getPacketCount() << " packets"); diff --git a/Tests/Pcap++Test/Tests/PfRingTests.cpp b/Tests/Pcap++Test/Tests/PfRingTests.cpp index 014f637dd0..d8d12b50ad 100644 --- a/Tests/Pcap++Test/Tests/PfRingTests.cpp +++ b/Tests/Pcap++Test/Tests/PfRingTests.cpp @@ -346,11 +346,9 @@ PTF_TEST_CASE(TestPfRingDeviceMultiThread) PTF_PRINT_VERBOSE("Packets captured: " << stats.recv); PTF_PRINT_VERBOSE("Packets dropped: " << stats.drop); PTF_PRINT_VERBOSE("Total flows: " << packetDataMultiThread[i].FlowKeys.size()); - for(std::map::iterator iter = packetDataMultiThread[i].FlowKeys.begin(); - iter != packetDataMultiThread[i].FlowKeys.end(); - iter++) + for(auto iter : packetDataMultiThread[i].FlowKeys) { - PTF_PRINT_VERBOSE("Key=0x" << std::hex << iter->first << "; Value=" << std::dec << iter->second.size()); + PTF_PRINT_VERBOSE("Key=0x" << std::hex << iter.first << "; Value=" << std::dec << iter.second.size()); } } diff --git a/cppcheckSuppressions.txt b/cppcheckSuppressions.txt index 5b6bc202b7..bab0d70856 100644 --- a/cppcheckSuppressions.txt +++ b/cppcheckSuppressions.txt @@ -12,5 +12,4 @@ noExplicitConstructor:Common++/header/MacAddress.h noExplicitConstructor:Pcap++/header/PcapFileDevice.h missingOverride:* -postfixOperator:* cstyleCast:* From d02ae18bd91407dbaeb05d3aad8a95ff9cd27583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Thu, 30 Nov 2023 16:46:16 +0300 Subject: [PATCH 02/17] more postfix --- Examples/PcapSearch/main.cpp | 6 ++-- Packet++/src/IgmpLayer.cpp | 4 +-- Pcap++/src/PcapLiveDevice.cpp | 17 +++++------ Tests/Packet++Test/Tests/PacketTests.cpp | 2 +- Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp | 30 +++++++++---------- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Examples/PcapSearch/main.cpp b/Examples/PcapSearch/main.cpp index 81327c21bd..3b066f88ef 100644 --- a/Examples/PcapSearch/main.cpp +++ b/Examples/PcapSearch/main.cpp @@ -270,16 +270,16 @@ void searchDirectories(const std::string &directory, bool includeSubDirectories, // when we get to here we already covered all sub-directories and collected all the files in this directory that are required for search // go over each such file and search its packets to find the search criteria - for (std::vector::iterator iter = pcapList.begin(); iter != pcapList.end(); iter++) + for (auto iter : pcapList) { // do the actual search - int packetsFound = searchPcap(*iter, searchCriteria, detailedReportFile); + int packetsFound = searchPcap(iter, searchCriteria, detailedReportFile); // add to total matched packets totalFilesSearched++; if (packetsFound > 0) { - std::cout << packetsFound << " packets found in '" << *iter << "'" << std::endl; + std::cout << packetsFound << " packets found in '" << iter << "'" << std::endl; totalPacketsFound += packetsFound; } } diff --git a/Packet++/src/IgmpLayer.cpp b/Packet++/src/IgmpLayer.cpp index d1df38e237..f539a4e416 100644 --- a/Packet++/src/IgmpLayer.cpp +++ b/Packet++/src/IgmpLayer.cpp @@ -420,9 +420,9 @@ igmpv3_group_record* IgmpV3ReportLayer::addGroupRecordAt(uint8_t recordType, con newGroupRecord->numOfSources = htobe16(sourceAddresses.size()); int srcAddrOffset = 0; - for (std::vector::const_iterator iter = sourceAddresses.begin(); iter != sourceAddresses.end(); iter++) + for (auto iter : sourceAddresses) { - memcpy(newGroupRecord->sourceAddresses + srcAddrOffset, iter->toBytes(), sizeof(uint32_t)); + memcpy(newGroupRecord->sourceAddresses + srcAddrOffset, iter.toBytes(), sizeof(uint32_t)); srcAddrOffset += sizeof(uint32_t); } diff --git a/Pcap++/src/PcapLiveDevice.cpp b/Pcap++/src/PcapLiveDevice.cpp index ab8e69ccdd..e4a33f21eb 100644 --- a/Pcap++/src/PcapLiveDevice.cpp +++ b/Pcap++/src/PcapLiveDevice.cpp @@ -936,16 +936,16 @@ void PcapLiveDevice::setDefaultGateway() IPv4Address PcapLiveDevice::getIPv4Address() const { - for(std::vector::const_iterator addrIter = m_Addresses.begin(); addrIter != m_Addresses.end(); addrIter++) + for(auto addrIter : m_Addresses) { - if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter->addr != nullptr) + if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter.addr != nullptr) { char addrAsString[INET6_ADDRSTRLEN]; - internal::sockaddr2string(addrIter->addr, addrAsString); + internal::sockaddr2string(addrIter.addr, addrAsString); PCPP_LOG_DEBUG("Searching address " << addrAsString); } - in_addr* currAddr = internal::sockaddr2in_addr(addrIter->addr); + in_addr* currAddr = internal::sockaddr2in_addr(addrIter.addr); if (currAddr == nullptr) { PCPP_LOG_DEBUG("Address is NULL"); @@ -960,16 +960,15 @@ IPv4Address PcapLiveDevice::getIPv4Address() const IPv6Address PcapLiveDevice::getIPv6Address() const { - for (std::vector::const_iterator addrIter = m_Addresses.begin(); addrIter != m_Addresses.end(); - addrIter++) + for (auto addrIter : m_Addresses) { - if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter->addr != nullptr) + if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter.addr != nullptr) { char addrAsString[INET6_ADDRSTRLEN]; - internal::sockaddr2string(addrIter->addr, addrAsString); + internal::sockaddr2string(addrIter.addr, addrAsString); PCPP_LOG_DEBUG("Searching address " << addrAsString); } - in6_addr *currAddr = internal::sockaddr2in6_addr(addrIter->addr); + in6_addr *currAddr = internal::sockaddr2in6_addr(addrIter.addr); if (currAddr == nullptr) { PCPP_LOG_DEBUG("Address is NULL"); diff --git a/Tests/Packet++Test/Tests/PacketTests.cpp b/Tests/Packet++Test/Tests/PacketTests.cpp index a5005c2938..8c48a4d141 100644 --- a/Tests/Packet++Test/Tests/PacketTests.cpp +++ b/Tests/Packet++Test/Tests/PacketTests.cpp @@ -1019,7 +1019,7 @@ PTF_TEST_CASE(PrintPacketAndLayers) std::ostringstream layerStream; layerStream << *layer; PTF_ASSERT_EQUAL(layerStream.str(), *iter); - iter++; + ++iter; } PTF_ASSERT_TRUE(iter == expectedLayerStrings.end()); diff --git a/Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp b/Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp index f17a32c17f..d5bf4a3d93 100644 --- a/Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp +++ b/Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp @@ -183,9 +183,9 @@ static bool tcpReassemblyTest(std::vector& packetStream, TcpRea else tcpReassembly = new pcpp::TcpReassembly(tcpReassemblyMsgReadyCallback, &results); - for (std::vector::iterator iter = packetStream.begin(); iter != packetStream.end(); iter++) + for (auto iter : packetStream) { - pcpp::Packet packet(&(*iter)); + pcpp::Packet packet(&iter); tcpReassembly->reassemblePacket(packet); } @@ -668,9 +668,9 @@ PTF_TEST_CASE(TestTcpReassemblyMultipleConns) int statusIndex = 0; - for (std::vector::iterator iter = packetStream.begin(); iter != packetStream.end(); iter++) + for (auto iter : packetStream) { - pcpp::Packet packet(&(*iter)); + pcpp::Packet packet(&iter); pcpp::TcpReassembly::ReassemblyStatus status = tcpReassembly.reassemblePacket(packet); PTF_ASSERT_EQUAL(status, expectedStatuses[statusIndex++], enum); } @@ -690,7 +690,7 @@ PTF_TEST_CASE(TestTcpReassemblyMultipleConns) expectedReassemblyData = readFileIntoString(std::string("PcapExamples/three_http_streams_conn_1_output.txt")); PTF_ASSERT_EQUAL(expectedReassemblyData, iter->second.reassembledData); - iter++; + ++iter; PTF_ASSERT_EQUAL(iter->second.numOfDataPackets, 2); PTF_ASSERT_EQUAL(iter->second.numOfMessagesFromSide[0], 1); @@ -701,7 +701,7 @@ PTF_TEST_CASE(TestTcpReassemblyMultipleConns) expectedReassemblyData = readFileIntoString(std::string("PcapExamples/three_http_streams_conn_2_output.txt")); PTF_ASSERT_EQUAL(expectedReassemblyData, iter->second.reassembledData); - iter++; + ++iter; PTF_ASSERT_EQUAL(iter->second.numOfDataPackets, 2); PTF_ASSERT_EQUAL(iter->second.numOfMessagesFromSide[0], 1); @@ -840,7 +840,7 @@ PTF_TEST_CASE(TestTcpReassemblyIPv6MultConns) expectedReassemblyData = readFileIntoString(std::string("PcapExamples/one_ipv6_http_stream4.txt")); PTF_ASSERT_EQUAL(expectedReassemblyData, iter->second.reassembledData); - iter++; + ++iter; PTF_ASSERT_EQUAL(iter->second.numOfDataPackets, 10); PTF_ASSERT_EQUAL(iter->second.numOfMessagesFromSide[0], 1); @@ -858,7 +858,7 @@ PTF_TEST_CASE(TestTcpReassemblyIPv6MultConns) PTF_ASSERT_EQUAL(stats.begin()->second.connData.endTime.tv_sec, 0); PTF_ASSERT_EQUAL(stats.begin()->second.connData.endTime.tv_usec, 0); - iter++; + ++iter; PTF_ASSERT_EQUAL(iter->second.numOfDataPackets, 2); PTF_ASSERT_EQUAL(iter->second.numOfMessagesFromSide[0], 1); @@ -878,7 +878,7 @@ PTF_TEST_CASE(TestTcpReassemblyIPv6MultConns) expectedReassemblyData = readFileIntoString(std::string("PcapExamples/one_ipv6_http_stream3.txt")); PTF_ASSERT_EQUAL(expectedReassemblyData, iter->second.reassembledData); - iter++; + ++iter; PTF_ASSERT_EQUAL(iter->second.numOfDataPackets, 13); PTF_ASSERT_EQUAL(iter->second.numOfMessagesFromSide[0], 4); @@ -961,9 +961,9 @@ PTF_TEST_CASE(TestTcpReassemblyCleanup) packetStream.pop_back(); - for(std::vector::iterator iter = packetStream.begin(); iter != packetStream.end(); iter++) + for(auto iter : packetStream) { - pcpp::Packet packet(&(*iter)); + pcpp::Packet packet(&iter); tcpReassembly.reassemblePacket(packet); } @@ -1020,9 +1020,9 @@ PTF_TEST_CASE(TestTcpReassemblyMaxOOOFrags) std::vector packetStream; PTF_ASSERT_TRUE(readPcapIntoPacketVec("PcapExamples/unidirectional_tcp_stream_with_missing_packet.pcap", packetStream, errMsg)); - for(std::vector::iterator iter = packetStream.begin(); iter != packetStream.end(); iter++) + for(auto iter : packetStream) { - pcpp::Packet packet(&(*iter)); + pcpp::Packet packet(&iter); tcpReassembly1.reassemblePacket(packet); tcpReassembly2.reassemblePacket(packet); } @@ -1104,9 +1104,9 @@ PTF_TEST_CASE(TestTcpReassemblyDisableOOOCleanup) // TestTcpReassemblyDisableBas std::swap(packetStream[13], packetStream[18]); TcpReassemblyMultipleConnStats tcpReassemblyResults; - for (std::vector::iterator iter = packetStream.begin(); iter != packetStream.end(); iter++) + for (auto iter : packetStream) { - pcpp::Packet packet(&(*iter)); + pcpp::Packet packet(&iter); tcpReassembly1.reassemblePacket(packet); tcpReassembly2.reassemblePacket(packet); } From 1c91e9b83fbfdfc46b45cb4611e683f1c0d1dbb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Thu, 30 Nov 2023 16:50:51 +0300 Subject: [PATCH 03/17] const --- Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp b/Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp index d5bf4a3d93..09a9dde472 100644 --- a/Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp +++ b/Tests/Pcap++Test/Tests/TcpReassemblyTests.cpp @@ -174,7 +174,7 @@ static void tcpReassemblyConnectionEndCallback(const pcpp::ConnectionData& conne // tcpReassemblyTest() // ~~~~~~~~~~~~~~~~~~~ -static bool tcpReassemblyTest(std::vector& packetStream, TcpReassemblyMultipleConnStats& results, bool monitorOpenCloseConns, bool closeConnsManually) +static bool tcpReassemblyTest(const std::vector& packetStream, TcpReassemblyMultipleConnStats& results, bool monitorOpenCloseConns, bool closeConnsManually) { pcpp::TcpReassembly* tcpReassembly = nullptr; From b10de9d0ddc669d9cfc2c1d9a5641b7df5e9af4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Thu, 30 Nov 2023 16:51:01 +0300 Subject: [PATCH 04/17] more postfix --- Examples/TLSFingerprinting/main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Examples/TLSFingerprinting/main.cpp b/Examples/TLSFingerprinting/main.cpp index b6913f8b7f..6e6d72bb9f 100644 --- a/Examples/TLSFingerprinting/main.cpp +++ b/Examples/TLSFingerprinting/main.cpp @@ -128,9 +128,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (std::vector::const_iterator iter = devList.begin(); iter != devList.end(); iter++) + for (auto iter : devList) { - std::cout << " -> Name: '" << (*iter)->getName() << "' IP address: " << (*iter)->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } exit(0); } @@ -256,9 +256,7 @@ void printCommonTLSFingerprints(const std::map& tlsFinger std::sort(map2vec.begin(),map2vec.end(), &stringCountComparer); // go over all items (fingerprints + count) in the sorted vector and print them - for(std::vector >::iterator iter = map2vec.begin(); - iter != map2vec.end(); - iter++) + for(auto iter = map2vec.begin(); iter != map2vec.end(); ++iter) { if (iter - map2vec.begin() >= printCountItems) break; From e2f5bae9a59ba6b7db0c815f82c08a097753d08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 2 Dec 2023 21:03:21 +0300 Subject: [PATCH 05/17] use stl --- Common++/src/TablePrinter.cpp | 9 ++------- Packet++/src/Packet.cpp | 10 +++------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/Common++/src/TablePrinter.cpp b/Common++/src/TablePrinter.cpp index acdc3a7446..1fe0a792b7 100644 --- a/Common++/src/TablePrinter.cpp +++ b/Common++/src/TablePrinter.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "TablePrinter.h" #include "Logger.h" @@ -88,13 +89,7 @@ void TablePrinter::printSeparator() return; } - int totalLen = 0; - for (auto iter : m_ColumnWidths) - { - totalLen += 2 + iter + 1; - } - - totalLen++; + int totalLen = std::accumulate(m_ColumnWidths.begin(), m_ColumnWidths.end(), m_ColumnWidths.size() * 3) + 1; for (int index = 0; index < totalLen; index++) std::cout << "-"; diff --git a/Packet++/src/Packet.cpp b/Packet++/src/Packet.cpp index 609bf5c6b8..c2767e0424 100644 --- a/Packet++/src/Packet.cpp +++ b/Packet++/src/Packet.cpp @@ -14,6 +14,7 @@ #include "Logger.h" #include "EndianPortable.h" #include +#include #include #include #ifdef _MSC_VER @@ -791,14 +792,9 @@ Layer* Packet::createFirstLayer(LinkLayerType linkType) std::string Packet::toString(bool timeAsLocalTime) const { std::vector stringList; - std::string result; toStringList(stringList, timeAsLocalTime); - for (auto iter : stringList) - { - result += iter + '\n'; - } - - return result; + return std::accumulate(stringList.begin(), stringList.end(), "", + [](std::string a, const std::string &b) { return std::move(a) + b + '\n'; }); } void Packet::toStringList(std::vector& result, bool timeAsLocalTime) const From 3ec87c854d471c136ee09cad5cf5898b7470976a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 2 Dec 2023 21:03:33 +0300 Subject: [PATCH 06/17] use stl --- Examples/DNSResolver/main.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Examples/DNSResolver/main.cpp b/Examples/DNSResolver/main.cpp index 5a42c4ff3f..455813e52c 100644 --- a/Examples/DNSResolver/main.cpp +++ b/Examples/DNSResolver/main.cpp @@ -189,13 +189,11 @@ int main(int argc, char* argv[]) { const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); - for (auto iter : devList) + auto iter = std::find_if(devList.begin(), devList.end(), + [](pcpp::PcapLiveDevice *dev) { return dev->getDefaultGateway().isValid(); }); + if (iter != devList.end()) { - if (iter->getDefaultGateway().isValid()) - { - dev = iter; - break; - } + dev = *iter; } if (dev == nullptr) From deb019732bb5f75321c51d313b7d2a2962950e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 2 Dec 2023 22:04:54 +0300 Subject: [PATCH 07/17] more fixes --- Common++/header/PointerVector.h | 12 +++--- Examples/IcmpFileTransfer/Common.cpp | 4 +- Examples/PcapSplitter/main.cpp | 20 ++++----- Packet++/src/IcmpLayer.cpp | 6 +-- Pcap++/src/PcapLiveDeviceList.cpp | 42 +++++++++---------- Tests/Pcap++Test/Tests/LiveDeviceTests.cpp | 20 ++++----- .../PcppTestFramework/PcppTestFrameworkRun.h | 10 ++--- 7 files changed, 56 insertions(+), 58 deletions(-) diff --git a/Common++/header/PointerVector.h b/Common++/header/PointerVector.h index 68eed1d1f5..4ac8f5c9f6 100644 --- a/Common++/header/PointerVector.h +++ b/Common++/header/PointerVector.h @@ -44,9 +44,9 @@ namespace pcpp */ ~PointerVector() { - for (VectorIterator iter = m_Vector.begin(); iter != m_Vector.end(); iter++) + for (auto iter : m_Vector) { - delete (*iter); + delete iter; } } @@ -56,9 +56,9 @@ namespace pcpp */ PointerVector(const PointerVector& other) { - for (ConstVectorIterator iter = other.begin(); iter != other.end(); iter++) + for (auto iter : other) { - T* objCopy = new T(**iter); + T* objCopy = new T(*iter); m_Vector.push_back(objCopy); } } @@ -68,9 +68,9 @@ namespace pcpp */ void clear() { - for (VectorIterator iter = m_Vector.begin(); iter != m_Vector.end(); iter++) + for (auto iter : m_Vector) { - delete (*iter); + delete iter; } m_Vector.clear(); diff --git a/Examples/IcmpFileTransfer/Common.cpp b/Examples/IcmpFileTransfer/Common.cpp index 8998862d8f..ee1993b526 100644 --- a/Examples/IcmpFileTransfer/Common.cpp +++ b/Examples/IcmpFileTransfer/Common.cpp @@ -91,9 +91,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (std::vector::const_iterator iter = devList.begin(); iter != devList.end(); iter++) + for (auto iter : devList) { - std::cout << " -> Name: '" << (*iter)->getName() << "' IP address: " << (*iter)->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } exit(0); } diff --git a/Examples/PcapSplitter/main.cpp b/Examples/PcapSplitter/main.cpp index 7d48ee41b6..9f3cb2efbc 100644 --- a/Examples/PcapSplitter/main.cpp +++ b/Examples/PcapSplitter/main.cpp @@ -446,21 +446,21 @@ int main(int argc, char* argv[]) outputFiles[fileNum]->writePacket(*parsedPacket.getRawPacket()); // if splitter wants us to close files - go over the file numbers and close them - for (std::vector::iterator it = filesToClose.begin(); it != filesToClose.end(); it++) + for (auto it : filesToClose) { // check if that file number is in the map - if (outputFiles.find(*it) != outputFiles.end()) + if (outputFiles.find(it) != outputFiles.end()) { // close the writer - outputFiles[*it]->close(); + outputFiles[it]->close(); // free the writer memory and put null in the map record - delete outputFiles[*it]; - outputFiles[*it] = nullptr; + delete outputFiles[it]; + outputFiles[it] = nullptr; } } - packetCountSoFar++; + ++packetCountSoFar; } std::cout << "Finished. Read and written " << packetCountSoFar << " packets to " << numOfFiles << " files" << std::endl; @@ -473,12 +473,12 @@ int main(int argc, char* argv[]) delete splitter; // close the writer files which are still open - for(std::map::iterator it = outputFiles.begin(); it != outputFiles.end(); ++it) + for(auto it : outputFiles) { - if (it->second != NULL) + if (it.second != NULL) { - it->second->close(); - delete it->second; + it.second->close(); + delete it.second; } } diff --git a/Packet++/src/IcmpLayer.cpp b/Packet++/src/IcmpLayer.cpp index 061c9ed8e2..6939940654 100644 --- a/Packet++/src/IcmpLayer.cpp +++ b/Packet++/src/IcmpLayer.cpp @@ -344,10 +344,10 @@ icmp_router_advertisement* IcmpLayer::setRouterAdvertisementData(uint8_t code, u header->header->addressEntrySize = 2; icmp_router_address_structure* curPos = (icmp_router_address_structure*)((uint8_t*)header->header + sizeof(icmp_router_advertisement_hdr)); - for (std::vector::const_iterator iter = routerAddresses.begin(); iter != routerAddresses.end(); iter++) + for (auto iter : routerAddresses) { - curPos->routerAddress = iter->routerAddress; - curPos->preferenceLevel = iter->preferenceLevel; + curPos->routerAddress = iter.routerAddress; + curPos->preferenceLevel = iter.preferenceLevel; curPos += 1; } diff --git a/Pcap++/src/PcapLiveDeviceList.cpp b/Pcap++/src/PcapLiveDeviceList.cpp index c6da146dfe..62e293212b 100644 --- a/Pcap++/src/PcapLiveDeviceList.cpp +++ b/Pcap++/src/PcapLiveDeviceList.cpp @@ -30,9 +30,9 @@ PcapLiveDeviceList::PcapLiveDeviceList() PcapLiveDeviceList::~PcapLiveDeviceList() { - for(std::vector::iterator devIter = m_LiveDeviceList.begin(); devIter != m_LiveDeviceList.end(); devIter++) + for(auto devIter : m_LiveDeviceList) { - delete (*devIter); + delete devIter; } } @@ -231,19 +231,19 @@ PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const IPAddress& ipAdd PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const IPv4Address& ipAddr) const { PCPP_LOG_DEBUG("Searching all live devices..."); - for(std::vector::const_iterator devIter = m_LiveDeviceList.begin(); devIter != m_LiveDeviceList.end(); devIter++) + for(auto devIter : m_LiveDeviceList) { - PCPP_LOG_DEBUG("Searching device '" << (*devIter)->m_Name << "'. Searching all addresses..."); - for(std::vector::iterator addrIter = (*devIter)->m_Addresses.begin(); addrIter != (*devIter)->m_Addresses.end(); addrIter++) + PCPP_LOG_DEBUG("Searching device '" << devIter->m_Name << "'. Searching all addresses..."); + for(auto addrIter : devIter->m_Addresses) { - if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter->addr != nullptr) + if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter.addr != nullptr) { char addrAsString[INET6_ADDRSTRLEN]; - internal::sockaddr2string(addrIter->addr, addrAsString); + internal::sockaddr2string(addrIter.addr, addrAsString); PCPP_LOG_DEBUG("Searching address " << addrAsString); } - in_addr* currAddr = internal::sockaddr2in_addr(addrIter->addr); + in_addr* currAddr = internal::sockaddr2in_addr(addrIter.addr); if (currAddr == nullptr) { PCPP_LOG_DEBUG("Address is NULL"); @@ -253,7 +253,7 @@ PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const IPv4Address& ipA if (currAddr->s_addr == ipAddr.toInt()) { PCPP_LOG_DEBUG("Found matched address!"); - return (*devIter); + return devIter; } } } @@ -264,19 +264,19 @@ PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const IPv4Address& ipA PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const IPv6Address& ip6Addr) const { PCPP_LOG_DEBUG("Searching all live devices..."); - for(std::vector::const_iterator devIter = m_LiveDeviceList.begin(); devIter != m_LiveDeviceList.end(); devIter++) + for(auto devIter : m_LiveDeviceList) { - PCPP_LOG_DEBUG("Searching device '" << (*devIter)->m_Name << "'. Searching all addresses..."); - for(std::vector::iterator addrIter = (*devIter)->m_Addresses.begin(); addrIter != (*devIter)->m_Addresses.end(); addrIter++) + PCPP_LOG_DEBUG("Searching device '" << devIter->m_Name << "'. Searching all addresses..."); + for(auto addrIter : devIter->m_Addresses) { - if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter->addr != nullptr) + if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter.addr != nullptr) { char addrAsString[INET6_ADDRSTRLEN]; - internal::sockaddr2string(addrIter->addr, addrAsString); + internal::sockaddr2string(addrIter.addr, addrAsString); PCPP_LOG_DEBUG("Searching address " << addrAsString); } - in6_addr* currAddr = internal::sockaddr2in6_addr(addrIter->addr); + in6_addr* currAddr = internal::sockaddr2in6_addr(addrIter.addr); if (currAddr == nullptr) { PCPP_LOG_DEBUG("Address is NULL"); @@ -289,7 +289,7 @@ PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const IPv6Address& ip6 { PCPP_LOG_DEBUG("Found matched address!"); delete [] addrAsArr; - return (*devIter); + return devIter; } delete [] addrAsArr; @@ -316,10 +316,10 @@ PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const std::string& ipA PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByName(const std::string& name) const { PCPP_LOG_DEBUG("Searching all live devices..."); - for(std::vector::const_iterator devIter = m_LiveDeviceList.begin(); devIter != m_LiveDeviceList.end(); devIter++) + for(auto devIter : m_LiveDeviceList) { - if (name == (*devIter)->getName()) - return (*devIter); + if (name == devIter->getName()) + return devIter; } return nullptr; @@ -345,9 +345,9 @@ PcapLiveDeviceList* PcapLiveDeviceList::clone() void PcapLiveDeviceList::reset() { - for(std::vector::iterator devIter = m_LiveDeviceList.begin(); devIter != m_LiveDeviceList.end(); devIter++) + for(auto devIter : m_LiveDeviceList) { - delete (*devIter); + delete devIter; } m_LiveDeviceList.clear(); diff --git a/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp b/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp index 39be1ba281..0d2dc03827 100644 --- a/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp +++ b/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp @@ -154,11 +154,11 @@ PTF_TEST_CASE(TestPcapLiveDeviceList) PTF_ASSERT_FALSE(devList.empty()); pcpp::IPv4Address defaultGateway = pcpp::IPv4Address::Zero; - for(std::vector::iterator iter = devList.begin(); iter != devList.end(); iter++) + for(auto iter : devList) { - PTF_ASSERT_FALSE((*iter)->getName().empty()); + PTF_ASSERT_FALSE(iter->getName().empty()); if (defaultGateway == pcpp::IPv4Address::Zero) - defaultGateway = (*iter)->getDefaultGateway(); + defaultGateway = iter->getDefaultGateway(); } PTF_ASSERT_NOT_EQUAL(defaultGateway, pcpp::IPv4Address::Zero); @@ -172,9 +172,9 @@ PTF_TEST_CASE(TestPcapLiveDeviceList) devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); PTF_ASSERT_FALSE(devList.empty()); - for(std::vector::iterator iter = devList.begin(); iter != devList.end(); iter++) + for(auto iter : devList) { - PTF_ASSERT_FALSE((*iter)->getName().empty()); + PTF_ASSERT_FALSE(iter->getName().empty()); } pcpp::PcapLiveDeviceList *clonedDevList = pcpp::PcapLiveDeviceList::getInstance().clone(); @@ -183,8 +183,8 @@ PTF_TEST_CASE(TestPcapLiveDeviceList) std::vector clonedDevListVector = clonedDevList->getPcapLiveDevicesList(); PTF_ASSERT_EQUAL(clonedDevListVector.size(), devList.size()); - std::vector::iterator iterCloned = clonedDevListVector.begin(); - for(std::vector::iterator iter = devList.begin(); iter != devList.end(); iter++, iterCloned++) + auto iterCloned = clonedDevListVector.begin(); + for(auto iter = devList.begin(); iter != devList.end(); ++iter, ++iterCloned) { PTF_ASSERT_EQUAL((*iter)->getName(), (*iterCloned)->getName()); } @@ -312,11 +312,11 @@ PTF_TEST_CASE(TestPcapLiveDeviceNoNetworking) std::vector devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); PTF_ASSERT_FALSE(devList.empty()); - for(std::vector::iterator iter = devList.begin(); iter != devList.end(); iter++) + for(auto iter : devList) { - if (!(*iter)->getLoopback() && (*iter)->getIPv4Address() != pcpp::IPv4Address::Zero) + if (!iter->getLoopback() && iter->getIPv4Address() != pcpp::IPv4Address::Zero) { - liveDev = *iter; + liveDev = iter; break; } } diff --git a/Tests/PcppTestFramework/PcppTestFrameworkRun.h b/Tests/PcppTestFramework/PcppTestFrameworkRun.h index 5cd72ddd9b..d0f769da80 100644 --- a/Tests/PcppTestFramework/PcppTestFrameworkRun.h +++ b/Tests/PcppTestFramework/PcppTestFrameworkRun.h @@ -1,6 +1,7 @@ #ifndef PCPP_TEST_FRAMEWORK_RUN #define PCPP_TEST_FRAMEWORK_RUN +#include #include #include #include @@ -32,14 +33,11 @@ static bool __ptfCheckTags(const std::string &tagSet, const std::string &tagSetT __ptfSplitString(tagSet, tagSetVec); __ptfSplitString(tagSetToCompareWith, tagSetToCompareWithVec); - for (std::vector::const_iterator tagSetToCompareWithIter = tagSetToCompareWithVec.begin(); tagSetToCompareWithIter != tagSetToCompareWithVec.end(); tagSetToCompareWithIter++) + for (auto tagSetToCompareWithIter : tagSetToCompareWithVec) { - for (std::vector::const_iterator tagSetIter = tagSetVec.begin(); tagSetIter != tagSetVec.end(); tagSetIter++) + if (std::any_of(tagSetVec.begin(), tagSetVec.end(), [tagSetToCompareWithIter](const std::string &val){ return val == tagSetToCompareWithIter;})) { - if (*tagSetIter == *tagSetToCompareWithIter) - { - return true; - } + return true; } } From 207ea32c69da9ec46814fd62ee22aa48a8279dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 2 Dec 2023 22:12:18 +0300 Subject: [PATCH 08/17] fixes --- Common++/src/SystemUtils.cpp | 2 ++ Packet++/src/Packet.cpp | 2 +- Tests/Pcap++Test/Tests/LiveDeviceTests.cpp | 11 +++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Common++/src/SystemUtils.cpp b/Common++/src/SystemUtils.cpp index 5ca8d4198f..cc8d635970 100644 --- a/Common++/src/SystemUtils.cpp +++ b/Common++/src/SystemUtils.cpp @@ -149,6 +149,7 @@ CoreMask createCoreMaskFromCoreVector(std::vector cores) CoreMask result = 0; for (auto iter : cores) { + // cppcheck-suppress useStlAlgorithm result |= iter.Mask; } @@ -160,6 +161,7 @@ CoreMask createCoreMaskFromCoreIds(std::vector coreIds) CoreMask result = 0; for (auto iter : coreIds) { + // cppcheck-suppress useStlAlgorithm result |= SystemCores::IdToSystemCore[iter].Mask; } diff --git a/Packet++/src/Packet.cpp b/Packet++/src/Packet.cpp index c2767e0424..d4e8953f1a 100644 --- a/Packet++/src/Packet.cpp +++ b/Packet++/src/Packet.cpp @@ -793,7 +793,7 @@ std::string Packet::toString(bool timeAsLocalTime) const { std::vector stringList; toStringList(stringList, timeAsLocalTime); - return std::accumulate(stringList.begin(), stringList.end(), "", + return std::accumulate(stringList.begin(), stringList.end(), std::string(), [](std::string a, const std::string &b) { return std::move(a) + b + '\n'; }); } diff --git a/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp b/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp index 0d2dc03827..ca72088926 100644 --- a/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp +++ b/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp @@ -312,13 +312,12 @@ PTF_TEST_CASE(TestPcapLiveDeviceNoNetworking) std::vector devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); PTF_ASSERT_FALSE(devList.empty()); - for(auto iter : devList) + auto iter = std::find_if(devList.begin(), devList.end(), [](const pcpp::PcapLiveDevice *dev) { + return !dev->getLoopback() && dev->getIPv4Address() != pcpp::IPv4Address::Zero; + }); + if (iter != devList.end()) { - if (!iter->getLoopback() && iter->getIPv4Address() != pcpp::IPv4Address::Zero) - { - liveDev = iter; - break; - } + liveDev = *iter; } PTF_ASSERT_NOT_NULL(liveDev); From 325c01887086e74bfeed39ba8b0de5509489cdd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 2 Dec 2023 22:46:29 +0300 Subject: [PATCH 09/17] use more const keyword --- Common++/header/PointerVector.h | 2 +- Common++/src/SystemUtils.cpp | 4 ++-- Examples/Arping/main.cpp | 2 +- Examples/DNSResolver/main.cpp | 2 +- Examples/DnsSpoofing/main.cpp | 6 +++--- Examples/DpdkBridge/main.cpp | 6 +++--- .../AppWorkerThread.h | 4 ++-- Examples/DpdkExample-FilterTraffic/main.cpp | 20 +++++++++---------- Examples/IcmpFileTransfer/Common.cpp | 2 +- Examples/PcapSearch/main.cpp | 4 ++-- Examples/PcapSplitter/main.cpp | 4 ++-- Examples/PfRingExample-FilterTraffic/main.cpp | 2 +- Examples/SSLAnalyzer/main.cpp | 10 +++++----- Examples/TLSFingerprinting/main.cpp | 2 +- Packet++/src/BgpLayer.cpp | 6 +++--- Packet++/src/IPv4Layer.cpp | 2 +- Packet++/src/IPv6Extensions.cpp | 4 ++-- Packet++/src/IcmpLayer.cpp | 2 +- Packet++/src/IgmpLayer.cpp | 2 +- Packet++/src/SSLHandshake.cpp | 10 +++++----- Packet++/src/SdpLayer.cpp | 2 +- Pcap++/src/DpdkDeviceList.cpp | 6 +++--- Pcap++/src/PcapLiveDevice.cpp | 4 ++-- Pcap++/src/PcapLiveDeviceList.cpp | 12 +++++------ Pcap++/src/PcapRemoteDeviceList.cpp | 4 ++-- Pcap++/src/PfRingDeviceList.cpp | 2 +- Tests/Pcap++Test/Tests/DpdkTests.cpp | 6 +++--- Tests/Pcap++Test/Tests/LiveDeviceTests.cpp | 4 ++-- Tests/Pcap++Test/Tests/PfRingTests.cpp | 2 +- .../PcppTestFramework/PcppTestFrameworkRun.h | 2 +- 30 files changed, 70 insertions(+), 70 deletions(-) diff --git a/Common++/header/PointerVector.h b/Common++/header/PointerVector.h index 4ac8f5c9f6..2ecfb203c7 100644 --- a/Common++/header/PointerVector.h +++ b/Common++/header/PointerVector.h @@ -56,7 +56,7 @@ namespace pcpp */ PointerVector(const PointerVector& other) { - for (auto iter : other) + for (const auto iter : other) { T* objCopy = new T(*iter); m_Vector.push_back(objCopy); diff --git a/Common++/src/SystemUtils.cpp b/Common++/src/SystemUtils.cpp index cc8d635970..e8647485c1 100644 --- a/Common++/src/SystemUtils.cpp +++ b/Common++/src/SystemUtils.cpp @@ -147,7 +147,7 @@ CoreMask getCoreMaskForAllMachineCores() CoreMask createCoreMaskFromCoreVector(std::vector cores) { CoreMask result = 0; - for (auto iter : cores) + for (const auto &iter : cores) { // cppcheck-suppress useStlAlgorithm result |= iter.Mask; @@ -159,7 +159,7 @@ CoreMask createCoreMaskFromCoreVector(std::vector cores) CoreMask createCoreMaskFromCoreIds(std::vector coreIds) { CoreMask result = 0; - for (auto iter : coreIds) + for (const auto &iter : coreIds) { // cppcheck-suppress useStlAlgorithm result |= SystemCores::IdToSystemCore[iter].Mask; diff --git a/Examples/Arping/main.cpp b/Examples/Arping/main.cpp index b51eb03381..f65234a984 100644 --- a/Examples/Arping/main.cpp +++ b/Examples/Arping/main.cpp @@ -89,7 +89,7 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (auto iter : devList) + for (const auto &iter : devList) { std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } diff --git a/Examples/DNSResolver/main.cpp b/Examples/DNSResolver/main.cpp index 455813e52c..81fcbbae18 100644 --- a/Examples/DNSResolver/main.cpp +++ b/Examples/DNSResolver/main.cpp @@ -76,7 +76,7 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (auto iter : devList) + for (const auto &iter : devList) { std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } diff --git a/Examples/DnsSpoofing/main.cpp b/Examples/DnsSpoofing/main.cpp index 873d5918da..9c088f41c3 100644 --- a/Examples/DnsSpoofing/main.cpp +++ b/Examples/DnsSpoofing/main.cpp @@ -128,7 +128,7 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (auto iter : devList) + for (const auto &iter : devList) { std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } @@ -172,7 +172,7 @@ void handleDnsRequest(pcpp::RawPacket* packet, pcpp::PcapLiveDevice* dev, void* bool hostMatch = false; // go over all hosts in dnsHostsToSpoof list and see if current query matches one of them - for (auto iter : args->dnsHostsToSpoof) + for (const auto &iter : args->dnsHostsToSpoof) { if (dnsLayer->getQuery(iter, false) != nullptr) { @@ -288,7 +288,7 @@ void onApplicationInterrupted(void* cookie) std::sort(map2vec.begin(),map2vec.end(), &stringCountComparer); // go over all items (hosts + count) in the sorted vector and print them - for(auto iter : map2vec) + for(const auto &iter : map2vec) { std::stringstream values; values << iter.first << "|" << iter.second; diff --git a/Examples/DpdkBridge/main.cpp b/Examples/DpdkBridge/main.cpp index 3cc6602df2..4b9eccb3ae 100644 --- a/Examples/DpdkBridge/main.cpp +++ b/Examples/DpdkBridge/main.cpp @@ -112,7 +112,7 @@ void listDpdkPorts() // go over all available DPDK devices and print info for each one std::vector deviceList = pcpp::DpdkDeviceList::getInstance().getDpdkDeviceList(); - for (auto iter : deviceList) + for (const auto &iter : deviceList) { pcpp::DpdkDevice* dev = iter; std::cout << " " @@ -311,7 +311,7 @@ int main(int argc, char* argv[]) // collect the list of DPDK devices std::vector dpdkDevicesToUse; - for (auto iter : dpdkPortVec) + for (const auto &iter : dpdkPortVec) { pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(iter); if (dev == NULL) @@ -322,7 +322,7 @@ int main(int argc, char* argv[]) } // go over all devices and open them - for (auto iter : dpdkDevicesToUse) + for (const auto &iter : dpdkDevicesToUse) { if (!iter->openMultiQueues(queueQuantity, 1)) { diff --git a/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h b/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h index a015e9b281..442900fe08 100644 --- a/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h +++ b/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h @@ -74,10 +74,10 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread while (!m_Stop) { // go over all DPDK devices configured for this worker/core - for (auto iter : m_WorkerConfig.InDataCfg) + for (const auto &iter : m_WorkerConfig.InDataCfg) { // for each DPDK device go over all RX queues configured for this worker/core - for (auto iter2 = iter.second) + for (const auto &iter2 = iter.second) { pcpp::DpdkDevice* dev = iter.first; diff --git a/Examples/DpdkExample-FilterTraffic/main.cpp b/Examples/DpdkExample-FilterTraffic/main.cpp index 09fc474aea..90a870e569 100644 --- a/Examples/DpdkExample-FilterTraffic/main.cpp +++ b/Examples/DpdkExample-FilterTraffic/main.cpp @@ -136,7 +136,7 @@ void listDpdkPorts() // go over all available DPDK devices and print info for each one std::vector deviceList = pcpp::DpdkDeviceList::getInstance().getDpdkDeviceList(); - for (auto iter : deviceList) + for (const auto &iter : deviceList) { pcpp::DpdkDevice* dev = iter; std::cout << " " @@ -160,7 +160,7 @@ void prepareCoreConfiguration(std::vector& dpdkDevicesToUse, // create a list of pairs of DpdkDevice and RX queues for all RX queues in all requested devices int totalNumOfRxQueues = 0; std::vector > deviceAndRxQVec; - for (auto iter : dpdkDevicesToUse) + for (const auto &iter : dpdkDevicesToUse) { for (int rxQueueIndex = 0; rxQueueIndex < rxQueues; rxQueueIndex++) { @@ -177,7 +177,7 @@ void prepareCoreConfiguration(std::vector& dpdkDevicesToUse, // prepare the configuration for every core: divide the devices and RX queue for each device with the various cores int i = 0; std::vector >::iterator pairVecIter = deviceAndRxQVec.begin(); - for (auto iter : coresToUse) + for (const auto &iter : coresToUse) { std::cout << "Using core " << (int)iter.Id << std::endl; workerConfigArr[i].CoreId = iter.Id; @@ -204,10 +204,10 @@ void prepareCoreConfiguration(std::vector& dpdkDevicesToUse, // print configuration for core std::cout << " Core configuration:" << std::endl; - for (auto iter2 : workerConfigArr[i].InDataCfg) + for (const auto &iter2 : workerConfigArr[i].InDataCfg) { std::cout << " DPDK device#" << iter2.first->getDeviceId() << ": "; - for (auto iter3 : iter2.second) + for (const auto &iter3 : iter2.second) { std::cout << "RX-Queue#" << iter3 << "; "; } @@ -250,7 +250,7 @@ void onApplicationInterrupted(void* cookie) // print final stats for every worker thread plus sum of all threads and free worker threads memory PacketStats aggregatedStats; - for (auto iter : *(args->workerThreadsVector)) + for (const auto &iter : *(args->workerThreadsVector)) { AppWorkerThread* thread = (AppWorkerThread*)(iter); PacketStats threadStats = thread->getStats(); @@ -489,7 +489,7 @@ int main(int argc, char* argv[]) // collect the list of DPDK devices std::vector dpdkDevicesToUse; - for (auto iter : dpdkPortVec) + for (const auto &iter : dpdkPortVec) { pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(iter); if (dev == NULL) @@ -500,7 +500,7 @@ int main(int argc, char* argv[]) } // go over all devices and open them - for (auto iter : dpdkDevicesToUse) + for (const auto &iter : dpdkDevicesToUse) { if (rxQueues > iter->getTotalNumOfRxQueues()) { @@ -519,7 +519,7 @@ int main(int argc, char* argv[]) << " with " << rxQueues << " RX queues and " << txQueues << " TX queues." << " RSS hash functions:" << std::endl; std::vector rssHashFunctions = iter->rssHashFunctionMaskToString(iter->getConfiguredRssHashFunction()); - for(auto it : rssHashFunctions) + for(const auto &it : rssHashFunctions) { std::cout << " " << it << std::endl; } @@ -541,7 +541,7 @@ int main(int argc, char* argv[]) // create worker thread for every core std::vector workerThreadVec; int i = 0; - for (auto iter = coresToUse.begin(); iter != coresToUse.end(); iter++) + for (auto iter = coresToUse.begin(); iter != coresToUse.end(); ++iter) { AppWorkerThread* newWorker = new AppWorkerThread(workerConfigArr[i], matchingEngine); workerThreadVec.push_back(newWorker); diff --git a/Examples/IcmpFileTransfer/Common.cpp b/Examples/IcmpFileTransfer/Common.cpp index ee1993b526..ad82eabbfc 100644 --- a/Examples/IcmpFileTransfer/Common.cpp +++ b/Examples/IcmpFileTransfer/Common.cpp @@ -91,7 +91,7 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (auto iter : devList) + for (const auto &iter : devList) { std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } diff --git a/Examples/PcapSearch/main.cpp b/Examples/PcapSearch/main.cpp index 3b066f88ef..fa25eeed82 100644 --- a/Examples/PcapSearch/main.cpp +++ b/Examples/PcapSearch/main.cpp @@ -166,7 +166,7 @@ int searchPcap(const std::string& pcapFilePath, std::string searchCriteria, std: // print layer by layer by layer as we want to add a few spaces before each layer std::vector packetLayers; parsedPacket.toStringList(packetLayers); - for (auto iter : packetLayers) + for (const auto &iter : packetLayers) (*detailedReportFile) << "\n " << iter; (*detailedReportFile) << std::endl; } @@ -270,7 +270,7 @@ void searchDirectories(const std::string &directory, bool includeSubDirectories, // when we get to here we already covered all sub-directories and collected all the files in this directory that are required for search // go over each such file and search its packets to find the search criteria - for (auto iter : pcapList) + for (const auto &iter : pcapList) { // do the actual search int packetsFound = searchPcap(iter, searchCriteria, detailedReportFile); diff --git a/Examples/PcapSplitter/main.cpp b/Examples/PcapSplitter/main.cpp index 9f3cb2efbc..3eb9b7ffe5 100644 --- a/Examples/PcapSplitter/main.cpp +++ b/Examples/PcapSplitter/main.cpp @@ -446,7 +446,7 @@ int main(int argc, char* argv[]) outputFiles[fileNum]->writePacket(*parsedPacket.getRawPacket()); // if splitter wants us to close files - go over the file numbers and close them - for (auto it : filesToClose) + for (const auto &it : filesToClose) { // check if that file number is in the map if (outputFiles.find(it) != outputFiles.end()) @@ -473,7 +473,7 @@ int main(int argc, char* argv[]) delete splitter; // close the writer files which are still open - for(auto it : outputFiles) + for(const auto &it : outputFiles) { if (it.second != NULL) { diff --git a/Examples/PfRingExample-FilterTraffic/main.cpp b/Examples/PfRingExample-FilterTraffic/main.cpp index eb6c3aaa61..1e6fcf4ec8 100644 --- a/Examples/PfRingExample-FilterTraffic/main.cpp +++ b/Examples/PfRingExample-FilterTraffic/main.cpp @@ -135,7 +135,7 @@ void listPfRingDevices() pcpp::Logger::getInstance().suppressLogs(); const std::vector& devList = pcpp::PfRingDeviceList::getInstance().getPfRingDevicesList(); - for (auto iter : devList) + for (const auto &iter : devList) { std::ostringstream interfaceIndex; if (iter->getInterfaceIndex() <= 9999) diff --git a/Examples/SSLAnalyzer/main.cpp b/Examples/SSLAnalyzer/main.cpp index b8e237aa02..d8c8e44bf9 100644 --- a/Examples/SSLAnalyzer/main.cpp +++ b/Examples/SSLAnalyzer/main.cpp @@ -124,7 +124,7 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (auto iter : devList) + for (const auto &iter : devList) { std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } @@ -211,7 +211,7 @@ void printServerNames(ClientHelloStats& clientHelloStatsCollector) std::sort(map2vec.begin(),map2vec.end(), &stringCountComparer); // go over all items (names + count) in the sorted vector and print them - for(auto iter : map2vec) + for(const auto &iter : map2vec) { std::stringstream values; values << iter.first << "|" << iter.second; @@ -240,7 +240,7 @@ void printVersions(std::map& versionMap, const std::string& headl std::sort(map2vec.begin(),map2vec.end(), &uint16CountComparer); // go over all items (names + count) in the sorted vector and print them - for(auto iter : map2vec) + for(const auto &iter : map2vec) { std::stringstream values; values << pcpp::SSLVersion(iter.first).toString() << "|" << iter.second; @@ -269,7 +269,7 @@ void printCipherSuites(ServerHelloStats& serverHelloStats) std::sort(map2vec.begin(),map2vec.end(), &stringCountComparer); // go over all items (names + count) in the sorted vector and print them - for(auto iter : map2vec) + for(const auto &iter : map2vec) { std::stringstream values; values << iter.first << "|" << iter.second; @@ -295,7 +295,7 @@ void printPorts(SSLGeneralStats& stats) std::sort(map2vec.begin(),map2vec.end(), &uint16CountComparer); // go over all items (names + count) in the sorted vector and print them - for(auto iter : map2vec) + for(const auto &iter : map2vec) { std::stringstream values; values << iter.first << "|" << iter.second; diff --git a/Examples/TLSFingerprinting/main.cpp b/Examples/TLSFingerprinting/main.cpp index 6e6d72bb9f..da7ae03a55 100644 --- a/Examples/TLSFingerprinting/main.cpp +++ b/Examples/TLSFingerprinting/main.cpp @@ -128,7 +128,7 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (auto iter : devList) + for (const auto &iter : devList) { std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; } diff --git a/Packet++/src/BgpLayer.cpp b/Packet++/src/BgpLayer.cpp index fc0fbfaf75..407e8c1d8e 100644 --- a/Packet++/src/BgpLayer.cpp +++ b/Packet++/src/BgpLayer.cpp @@ -163,7 +163,7 @@ size_t BgpOpenMessageLayer::optionalParamsToByteArray(const std::vector 32) { @@ -416,7 +416,7 @@ size_t BgpUpdateMessageLayer::prefixAndIPDataToByteArray(const std::vector 32) { diff --git a/Packet++/src/IPv4Layer.cpp b/Packet++/src/IPv4Layer.cpp index 47fa6f1949..df32b85953 100644 --- a/Packet++/src/IPv4Layer.cpp +++ b/Packet++/src/IPv4Layer.cpp @@ -37,7 +37,7 @@ IPv4OptionBuilder::IPv4OptionBuilder(IPv4OptionTypes optionType, const std::vect m_RecValue[curOffset++] = 0; // init pointer value bool firstZero = false; - for (auto iter : ipList) + for (const auto &iter : ipList) { uint32_t ipAddrAsInt = iter.toInt(); diff --git a/Packet++/src/IPv6Extensions.cpp b/Packet++/src/IPv6Extensions.cpp index c63ad63167..21274f854c 100644 --- a/Packet++/src/IPv6Extensions.cpp +++ b/Packet++/src/IPv6Extensions.cpp @@ -149,7 +149,7 @@ IPv6TLVOptionHeader::IPv6TLVOptionHeader(const std::vector size_t totalSize = sizeof(uint16_t); // nextHeader + headerLen - for (auto iter : options) + for (const auto &iter : options) { IPv6Option option = iter.build(); totalSize += option.getTotalSize(); @@ -166,7 +166,7 @@ IPv6TLVOptionHeader::IPv6TLVOptionHeader(const std::vector size_t offset = sizeof(uint16_t); - for (auto iter : options) + for (const auto &iter : options) { IPv6Option option = iter.build(); memcpy(getDataPtr() + offset, option.getRecordBasePtr(), option.getTotalSize()); diff --git a/Packet++/src/IcmpLayer.cpp b/Packet++/src/IcmpLayer.cpp index 6939940654..564ad4bfd3 100644 --- a/Packet++/src/IcmpLayer.cpp +++ b/Packet++/src/IcmpLayer.cpp @@ -344,7 +344,7 @@ icmp_router_advertisement* IcmpLayer::setRouterAdvertisementData(uint8_t code, u header->header->addressEntrySize = 2; icmp_router_address_structure* curPos = (icmp_router_address_structure*)((uint8_t*)header->header + sizeof(icmp_router_advertisement_hdr)); - for (auto iter : routerAddresses) + for (const auto &iter : routerAddresses) { curPos->routerAddress = iter.routerAddress; curPos->preferenceLevel = iter.preferenceLevel; diff --git a/Packet++/src/IgmpLayer.cpp b/Packet++/src/IgmpLayer.cpp index f539a4e416..d49e1d6c30 100644 --- a/Packet++/src/IgmpLayer.cpp +++ b/Packet++/src/IgmpLayer.cpp @@ -420,7 +420,7 @@ igmpv3_group_record* IgmpV3ReportLayer::addGroupRecordAt(uint8_t recordType, con newGroupRecord->numOfSources = htobe16(sourceAddresses.size()); int srcAddrOffset = 0; - for (auto iter : sourceAddresses) + for (const auto &iter : sourceAddresses) { memcpy(newGroupRecord->sourceAddresses + srcAddrOffset, iter.toBytes(), sizeof(uint32_t)); srcAddrOffset += sizeof(uint32_t); diff --git a/Packet++/src/SSLHandshake.cpp b/Packet++/src/SSLHandshake.cpp index 3d7a9420a2..4ffc73d8b6 100644 --- a/Packet++/src/SSLHandshake.cpp +++ b/Packet++/src/SSLHandshake.cpp @@ -1502,7 +1502,7 @@ SSLClientHelloMessage::ClientHelloTLSFingerprint SSLClientHelloMessage::generate if (supportedGroupsExt != nullptr) { std::vector supportedGroups = supportedGroupsExt->getSupportedGroups(); - for (auto iter : supportedGroups) + for (const auto &iter : supportedGroups) if (GreaseSet.find(iter) == GreaseSet.end()) result.supportedGroups.push_back(iter); } @@ -1536,7 +1536,7 @@ std::string SSLClientHelloMessage::ClientHelloTLSFingerprint::toString() // add cipher suites bool firstCipher = true; - for (auto iter : cipherSuites) + for (const auto &iter : cipherSuites) { tlsFingerprint << (firstCipher ? "" : "-") << iter; firstCipher = false; @@ -1545,7 +1545,7 @@ std::string SSLClientHelloMessage::ClientHelloTLSFingerprint::toString() // add extensions bool firstExtension = true; - for (auto iter : extensions) + for (const auto &iter : extensions) { tlsFingerprint << (firstExtension ? "" : "-") << iter; firstExtension = false; @@ -1554,7 +1554,7 @@ std::string SSLClientHelloMessage::ClientHelloTLSFingerprint::toString() // add supported groups bool firstGroup = true; - for (auto iter : supportedGroups) + for (const auto &iter : supportedGroups) { tlsFingerprint << (firstGroup ? "" : "-") << iter; firstGroup = false; @@ -1793,7 +1793,7 @@ std::string SSLServerHelloMessage::ServerHelloTLSFingerprint::toString() // add extensions bool firstExtension = true; - for (auto iter : extensions) + for (const auto &iter : extensions) { tlsFingerprint << (firstExtension ? "" : "-") << iter; firstExtension = false; diff --git a/Packet++/src/SdpLayer.cpp b/Packet++/src/SdpLayer.cpp index 983cceaa98..6e5e1fd397 100644 --- a/Packet++/src/SdpLayer.cpp +++ b/Packet++/src/SdpLayer.cpp @@ -120,7 +120,7 @@ bool SdpLayer::addMediaDescription(const std::string& mediaType, uint16_t mediaP } - for (auto iter : mediaAttributes) + for (const auto &iter : mediaAttributes) { if (addField(PCPP_SDP_MEDIA_ATTRIBUTE_FIELD, iter) == nullptr) { diff --git a/Pcap++/src/DpdkDeviceList.cpp b/Pcap++/src/DpdkDeviceList.cpp index 0e229141f8..64e9b6e42c 100644 --- a/Pcap++/src/DpdkDeviceList.cpp +++ b/Pcap++/src/DpdkDeviceList.cpp @@ -223,7 +223,7 @@ DpdkDevice* DpdkDeviceList::getDeviceByPciAddress(const std::string& pciAddr) co return NULL; } - for (auto iter : m_DpdkDeviceList) + for (const auto &iter : m_DpdkDeviceList) { if (iter->getPciAddress() == pciAddr) return iter; @@ -382,7 +382,7 @@ bool DpdkDeviceList::startDpdkWorkerThreads(CoreMask coreMask, std::vectorstop(); rte_eal_wait_lcore(iter->getCoreId()); @@ -408,7 +408,7 @@ void DpdkDeviceList::stopDpdkWorkerThreads() return; } - for (auto iter : m_WorkerThreads) + for (const auto &iter : m_WorkerThreads) { iter->stop(); rte_eal_wait_lcore(iter->getCoreId()); diff --git a/Pcap++/src/PcapLiveDevice.cpp b/Pcap++/src/PcapLiveDevice.cpp index e4a33f21eb..73999fb14b 100644 --- a/Pcap++/src/PcapLiveDevice.cpp +++ b/Pcap++/src/PcapLiveDevice.cpp @@ -936,7 +936,7 @@ void PcapLiveDevice::setDefaultGateway() IPv4Address PcapLiveDevice::getIPv4Address() const { - for(auto addrIter : m_Addresses) + for(const auto &addrIter : m_Addresses) { if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter.addr != nullptr) { @@ -960,7 +960,7 @@ IPv4Address PcapLiveDevice::getIPv4Address() const IPv6Address PcapLiveDevice::getIPv6Address() const { - for (auto addrIter : m_Addresses) + for (const auto &addrIter : m_Addresses) { if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter.addr != nullptr) { diff --git a/Pcap++/src/PcapLiveDeviceList.cpp b/Pcap++/src/PcapLiveDeviceList.cpp index 62e293212b..e7eee7d47d 100644 --- a/Pcap++/src/PcapLiveDeviceList.cpp +++ b/Pcap++/src/PcapLiveDeviceList.cpp @@ -30,7 +30,7 @@ PcapLiveDeviceList::PcapLiveDeviceList() PcapLiveDeviceList::~PcapLiveDeviceList() { - for(auto devIter : m_LiveDeviceList) + for(const auto &devIter : m_LiveDeviceList) { delete devIter; } @@ -231,10 +231,10 @@ PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const IPAddress& ipAdd PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const IPv4Address& ipAddr) const { PCPP_LOG_DEBUG("Searching all live devices..."); - for(auto devIter : m_LiveDeviceList) + for(const auto &devIter : m_LiveDeviceList) { PCPP_LOG_DEBUG("Searching device '" << devIter->m_Name << "'. Searching all addresses..."); - for(auto addrIter : devIter->m_Addresses) + for(const auto &addrIter : devIter->m_Addresses) { if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter.addr != nullptr) { @@ -264,10 +264,10 @@ PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const IPv4Address& ipA PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const IPv6Address& ip6Addr) const { PCPP_LOG_DEBUG("Searching all live devices..."); - for(auto devIter : m_LiveDeviceList) + for(const auto &devIter : m_LiveDeviceList) { PCPP_LOG_DEBUG("Searching device '" << devIter->m_Name << "'. Searching all addresses..."); - for(auto addrIter : devIter->m_Addresses) + for(const auto &addrIter : devIter->m_Addresses) { if (Logger::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && addrIter.addr != nullptr) { @@ -316,7 +316,7 @@ PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const std::string& ipA PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByName(const std::string& name) const { PCPP_LOG_DEBUG("Searching all live devices..."); - for(auto devIter : m_LiveDeviceList) + for(const auto &devIter : m_LiveDeviceList) { if (name == devIter->getName()) return devIter; diff --git a/Pcap++/src/PcapRemoteDeviceList.cpp b/Pcap++/src/PcapRemoteDeviceList.cpp index b63923b18d..7fa25e0984 100644 --- a/Pcap++/src/PcapRemoteDeviceList.cpp +++ b/Pcap++/src/PcapRemoteDeviceList.cpp @@ -109,7 +109,7 @@ PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPv4Address& i for(ConstRemoteDeviceListIterator devIter = m_RemoteDeviceList.begin(); devIter != m_RemoteDeviceList.end(); devIter++) { PCPP_LOG_DEBUG("Searching device '" << (*devIter)->m_Name << "'. Searching all addresses..."); - for(auto addrIter : (*devIter)->m_Addresses) + for(const auto &addrIter : (*devIter)->m_Addresses) { if (Logger::getInstance().isDebugEnabled(PcapLogModuleRemoteDevice) && addrIter.addr != NULL) { @@ -143,7 +143,7 @@ PcapRemoteDevice* PcapRemoteDeviceList::getRemoteDeviceByIP(const IPv6Address& i for(ConstRemoteDeviceListIterator devIter = m_RemoteDeviceList.begin(); devIter != m_RemoteDeviceList.end(); devIter++) { PCPP_LOG_DEBUG("Searching device '" << (*devIter)->m_Name << "'. Searching all addresses..."); - for(auto addrIter : (*devIter)->m_Addresses) + for(const auto &addrIter : (*devIter)->m_Addresses) { if (Logger::getInstance().isDebugEnabled(PcapLogModuleRemoteDevice) && addrIter.addr != NULL) { diff --git a/Pcap++/src/PfRingDeviceList.cpp b/Pcap++/src/PfRingDeviceList.cpp index 9732b3e3b5..6008d7dd45 100644 --- a/Pcap++/src/PfRingDeviceList.cpp +++ b/Pcap++/src/PfRingDeviceList.cpp @@ -68,7 +68,7 @@ PfRingDeviceList::~PfRingDeviceList() PfRingDevice* PfRingDeviceList::getPfRingDeviceByName(const std::string &devName) const { PCPP_LOG_DEBUG("Searching all live devices..."); - for(auto devIter : m_PfRingDeviceList) + for(const auto &devIter : m_PfRingDeviceList) { if (devIter->getDeviceName() == devName) return devIter; diff --git a/Tests/Pcap++Test/Tests/DpdkTests.cpp b/Tests/Pcap++Test/Tests/DpdkTests.cpp index 5deea88592..a9468c4ed3 100644 --- a/Tests/Pcap++Test/Tests/DpdkTests.cpp +++ b/Tests/Pcap++Test/Tests/DpdkTests.cpp @@ -485,7 +485,7 @@ PTF_TEST_CASE(TestDpdkMultiThread) PTF_ASSERT_EQUAL(res.size(), 0); if (PTF_IS_VERBOSE_MODE) { - for (auto iter = res) + for (const auto &iter : res) { PTF_PRINT_VERBOSE("Same flow exists in core " << firstCoreId << " and core " << secondCoreId << ". Flow key = " << iter.first); std::ostringstream stream; @@ -513,7 +513,7 @@ PTF_TEST_CASE(TestDpdkMultiThread) if (PTF_IS_VERBOSE_MODE) { - for(auto iter : packetDataMultiThread[firstCoreId].FlowKeys) + for(const auto &iter : packetDataMultiThread[firstCoreId].FlowKeys) { PTF_PRINT_VERBOSE("Key=0x" << std::hex << iter.first << "; Value=" << std::dec << iter.second.size()); iter.second.clear(); @@ -804,7 +804,7 @@ PTF_TEST_CASE(TestDpdkDeviceWorkerThreads) // that total amount of packets received by all threads is greater than zero int packetCount = 0; - for (auto iter : workerThreadVec) + for (const auto &iter : workerThreadVec) { DpdkTestWorkerThread* thread = (DpdkTestWorkerThread*)iter; PTF_ASSERT_TRUE(thread->threadRanAndStopped()); diff --git a/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp b/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp index ca72088926..abe70123f1 100644 --- a/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp +++ b/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp @@ -154,7 +154,7 @@ PTF_TEST_CASE(TestPcapLiveDeviceList) PTF_ASSERT_FALSE(devList.empty()); pcpp::IPv4Address defaultGateway = pcpp::IPv4Address::Zero; - for(auto iter : devList) + for(const auto &iter : devList) { PTF_ASSERT_FALSE(iter->getName().empty()); if (defaultGateway == pcpp::IPv4Address::Zero) @@ -172,7 +172,7 @@ PTF_TEST_CASE(TestPcapLiveDeviceList) devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); PTF_ASSERT_FALSE(devList.empty()); - for(auto iter : devList) + for(const auto &iter : devList) { PTF_ASSERT_FALSE(iter->getName().empty()); } diff --git a/Tests/Pcap++Test/Tests/PfRingTests.cpp b/Tests/Pcap++Test/Tests/PfRingTests.cpp index d8d12b50ad..1d4c529995 100644 --- a/Tests/Pcap++Test/Tests/PfRingTests.cpp +++ b/Tests/Pcap++Test/Tests/PfRingTests.cpp @@ -346,7 +346,7 @@ PTF_TEST_CASE(TestPfRingDeviceMultiThread) PTF_PRINT_VERBOSE("Packets captured: " << stats.recv); PTF_PRINT_VERBOSE("Packets dropped: " << stats.drop); PTF_PRINT_VERBOSE("Total flows: " << packetDataMultiThread[i].FlowKeys.size()); - for(auto iter : packetDataMultiThread[i].FlowKeys) + for(const auto &iter : packetDataMultiThread[i].FlowKeys) { PTF_PRINT_VERBOSE("Key=0x" << std::hex << iter.first << "; Value=" << std::dec << iter.second.size()); } diff --git a/Tests/PcppTestFramework/PcppTestFrameworkRun.h b/Tests/PcppTestFramework/PcppTestFrameworkRun.h index d0f769da80..4b46b49536 100644 --- a/Tests/PcppTestFramework/PcppTestFrameworkRun.h +++ b/Tests/PcppTestFramework/PcppTestFrameworkRun.h @@ -33,7 +33,7 @@ static bool __ptfCheckTags(const std::string &tagSet, const std::string &tagSetT __ptfSplitString(tagSet, tagSetVec); __ptfSplitString(tagSetToCompareWith, tagSetToCompareWithVec); - for (auto tagSetToCompareWithIter : tagSetToCompareWithVec) + for (const auto &tagSetToCompareWithIter : tagSetToCompareWithVec) { if (std::any_of(tagSetVec.begin(), tagSetVec.end(), [tagSetToCompareWithIter](const std::string &val){ return val == tagSetToCompareWithIter;})) { From 25dfb5841bcf53cdef5379acd5de017c5321a9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 9 Dec 2023 16:10:11 +0300 Subject: [PATCH 10/17] more meaningful names --- Common++/src/SystemUtils.cpp | 8 +-- Examples/Arping/main.cpp | 4 +- Examples/DNSResolver/main.cpp | 4 +- Examples/DnsSpoofing/main.cpp | 8 +-- Examples/DpdkBridge/main.cpp | 10 ++-- Examples/DpdkExample-FilterTraffic/main.cpp | 37 +++++++------- Examples/IcmpFileTransfer/Common.cpp | 4 +- Examples/PcapSearch/main.cpp | 4 +- Examples/PcapSplitter/main.cpp | 10 ++-- Examples/PfRingExample-FilterTraffic/main.cpp | 14 +++--- Examples/SSLAnalyzer/main.cpp | 4 +- Examples/TLSFingerprinting/main.cpp | 4 +- Packet++/src/BgpLayer.cpp | 50 +++++++++---------- Packet++/src/IPv4Layer.cpp | 4 +- Packet++/src/IgmpLayer.cpp | 4 +- Pcap++/src/DpdkDeviceList.cpp | 26 +++++----- 16 files changed, 97 insertions(+), 98 deletions(-) diff --git a/Common++/src/SystemUtils.cpp b/Common++/src/SystemUtils.cpp index e8647485c1..6f8dde916f 100644 --- a/Common++/src/SystemUtils.cpp +++ b/Common++/src/SystemUtils.cpp @@ -147,10 +147,10 @@ CoreMask getCoreMaskForAllMachineCores() CoreMask createCoreMaskFromCoreVector(std::vector cores) { CoreMask result = 0; - for (const auto &iter : cores) + for (const auto &core : cores) { // cppcheck-suppress useStlAlgorithm - result |= iter.Mask; + result |= core.Mask; } return result; @@ -159,10 +159,10 @@ CoreMask createCoreMaskFromCoreVector(std::vector cores) CoreMask createCoreMaskFromCoreIds(std::vector coreIds) { CoreMask result = 0; - for (const auto &iter : coreIds) + for (const auto &coreId : coreIds) { // cppcheck-suppress useStlAlgorithm - result |= SystemCores::IdToSystemCore[iter].Mask; + result |= SystemCores::IdToSystemCore[coreId].Mask; } return result; diff --git a/Examples/Arping/main.cpp b/Examples/Arping/main.cpp index f65234a984..73277544f7 100644 --- a/Examples/Arping/main.cpp +++ b/Examples/Arping/main.cpp @@ -89,9 +89,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (const auto &iter : devList) + for (const auto &dev : devList) { - std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << dev->getName() << "' IP address: " << dev->getIPv4Address().toString() << std::endl; } exit(0); } diff --git a/Examples/DNSResolver/main.cpp b/Examples/DNSResolver/main.cpp index 81fcbbae18..c5ac92ec4a 100644 --- a/Examples/DNSResolver/main.cpp +++ b/Examples/DNSResolver/main.cpp @@ -76,9 +76,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (const auto &iter : devList) + for (const auto &dev : devList) { - std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << dev->getName() << "' IP address: " << dev->getIPv4Address().toString() << std::endl; } exit(0); } diff --git a/Examples/DnsSpoofing/main.cpp b/Examples/DnsSpoofing/main.cpp index 9c088f41c3..7443714e93 100644 --- a/Examples/DnsSpoofing/main.cpp +++ b/Examples/DnsSpoofing/main.cpp @@ -128,9 +128,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (const auto &iter : devList) + for (const auto &dev : devList) { - std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << dev->getName() << "' IP address: " << dev->getIPv4Address().toString() << std::endl; } exit(0); } @@ -172,9 +172,9 @@ void handleDnsRequest(pcpp::RawPacket* packet, pcpp::PcapLiveDevice* dev, void* bool hostMatch = false; // go over all hosts in dnsHostsToSpoof list and see if current query matches one of them - for (const auto &iter : args->dnsHostsToSpoof) + for (const auto &host : args->dnsHostsToSpoof) { - if (dnsLayer->getQuery(iter, false) != nullptr) + if (dnsLayer->getQuery(host, false) != nullptr) { hostMatch = true; break; diff --git a/Examples/DpdkBridge/main.cpp b/Examples/DpdkBridge/main.cpp index 4b9eccb3ae..8c58c980bb 100644 --- a/Examples/DpdkBridge/main.cpp +++ b/Examples/DpdkBridge/main.cpp @@ -311,22 +311,22 @@ int main(int argc, char* argv[]) // collect the list of DPDK devices std::vector dpdkDevicesToUse; - for (const auto &iter : dpdkPortVec) + for (const auto &port : dpdkPortVec) { pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(iter); if (dev == NULL) { - EXIT_WITH_ERROR("DPDK device for port " << iter << " doesn't exist"); + EXIT_WITH_ERROR("DPDK device for port " << port << " doesn't exist"); } dpdkDevicesToUse.push_back(dev); } // go over all devices and open them - for (const auto &iter : dpdkDevicesToUse) + for (const auto &dev : dpdkDevicesToUse) { - if (!iter->openMultiQueues(queueQuantity, 1)) + if (!dev->openMultiQueues(queueQuantity, 1)) { - EXIT_WITH_ERROR("Couldn't open DPDK device #" << iter->getDeviceId() << ", PMD '" << iter->getPMDName() << "'"); + EXIT_WITH_ERROR("Couldn't open DPDK device #" << dev->getDeviceId() << ", PMD '" << dev->getPMDName() << "'"); } } diff --git a/Examples/DpdkExample-FilterTraffic/main.cpp b/Examples/DpdkExample-FilterTraffic/main.cpp index 90a870e569..bbeacce543 100644 --- a/Examples/DpdkExample-FilterTraffic/main.cpp +++ b/Examples/DpdkExample-FilterTraffic/main.cpp @@ -136,9 +136,8 @@ void listDpdkPorts() // go over all available DPDK devices and print info for each one std::vector deviceList = pcpp::DpdkDeviceList::getInstance().getDpdkDeviceList(); - for (const auto &iter : deviceList) + for (const auto &dev : deviceList) { - pcpp::DpdkDevice* dev = iter; std::cout << " " << " Port #" << dev->getDeviceId() << ":" << " MAC address='" << dev->getMacAddress() << "';" @@ -177,10 +176,10 @@ void prepareCoreConfiguration(std::vector& dpdkDevicesToUse, // prepare the configuration for every core: divide the devices and RX queue for each device with the various cores int i = 0; std::vector >::iterator pairVecIter = deviceAndRxQVec.begin(); - for (const auto &iter : coresToUse) + for (const auto &core : coresToUse) { - std::cout << "Using core " << (int)iter.Id << std::endl; - workerConfigArr[i].CoreId = iter.Id; + std::cout << "Using core " << (int)core.Id << std::endl; + workerConfigArr[i].CoreId = core.Id; workerConfigArr[i].WriteMatchedPacketsToFile = writePacketsToDisk; std::stringstream packetFileName; @@ -489,39 +488,39 @@ int main(int argc, char* argv[]) // collect the list of DPDK devices std::vector dpdkDevicesToUse; - for (const auto &iter : dpdkPortVec) + for (const auto &port : dpdkPortVec) { - pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(iter); + pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(port); if (dev == NULL) { - EXIT_WITH_ERROR("DPDK device for port " << iter << " doesn't exist"); + EXIT_WITH_ERROR("DPDK device for port " << port << " doesn't exist"); } dpdkDevicesToUse.push_back(dev); } // go over all devices and open them - for (const auto &iter : dpdkDevicesToUse) + for (const auto &dev : dpdkDevicesToUse) { - if (rxQueues > iter->getTotalNumOfRxQueues()) + if (rxQueues > dev->getTotalNumOfRxQueues()) { - EXIT_WITH_ERROR("Number of RX errors cannot exceed the max allowed by the device which is " << iter->getTotalNumOfRxQueues()); + EXIT_WITH_ERROR("Number of RX errors cannot exceed the max allowed by the device which is " << dev->getTotalNumOfRxQueues()); } - if (txQueues > iter->getTotalNumOfTxQueues()) + if (txQueues > dev->getTotalNumOfTxQueues()) { - EXIT_WITH_ERROR("Number of TX errors cannot exceed the max allowed by the device which is " << iter->getTotalNumOfTxQueues()); + EXIT_WITH_ERROR("Number of TX errors cannot exceed the max allowed by the device which is " << dev->getTotalNumOfTxQueues()); } - if (!iter->openMultiQueues(rxQueues, txQueues)) + if (!dev->openMultiQueues(rxQueues, txQueues)) { - EXIT_WITH_ERROR("Couldn't open DPDK device #" << iter->getDeviceId() << ", PMD '" << iter->getPMDName() << "'"); + EXIT_WITH_ERROR("Couldn't open DPDK device #" << dev->getDeviceId() << ", PMD '" << dev->getPMDName() << "'"); } std::cout - << "Opened device #" << iter->getDeviceId() + << "Opened device #" << dev->getDeviceId() << " with " << rxQueues << " RX queues and " << txQueues << " TX queues." << " RSS hash functions:" << std::endl; - std::vector rssHashFunctions = iter->rssHashFunctionMaskToString(iter->getConfiguredRssHashFunction()); - for(const auto &it : rssHashFunctions) + std::vector rssHashFunctions = dev->rssHashFunctionMaskToString(dev->getConfiguredRssHashFunction()); + for(const auto &hashFunc : rssHashFunctions) { - std::cout << " " << it << std::endl; + std::cout << " " << hashFunc << std::endl; } } diff --git a/Examples/IcmpFileTransfer/Common.cpp b/Examples/IcmpFileTransfer/Common.cpp index ad82eabbfc..f990e6eacf 100644 --- a/Examples/IcmpFileTransfer/Common.cpp +++ b/Examples/IcmpFileTransfer/Common.cpp @@ -91,9 +91,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (const auto &iter : devList) + for (const auto &dev : devList) { - std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << dev->getName() << "' IP address: " << dev->getIPv4Address().toString() << std::endl; } exit(0); } diff --git a/Examples/PcapSearch/main.cpp b/Examples/PcapSearch/main.cpp index fa25eeed82..b294cec71e 100644 --- a/Examples/PcapSearch/main.cpp +++ b/Examples/PcapSearch/main.cpp @@ -166,8 +166,8 @@ int searchPcap(const std::string& pcapFilePath, std::string searchCriteria, std: // print layer by layer by layer as we want to add a few spaces before each layer std::vector packetLayers; parsedPacket.toStringList(packetLayers); - for (const auto &iter : packetLayers) - (*detailedReportFile) << "\n " << iter; + for (const auto &layer : packetLayers) + (*detailedReportFile) << "\n " << layer; (*detailedReportFile) << std::endl; } diff --git a/Examples/PcapSplitter/main.cpp b/Examples/PcapSplitter/main.cpp index 3eb9b7ffe5..7cd742a3b3 100644 --- a/Examples/PcapSplitter/main.cpp +++ b/Examples/PcapSplitter/main.cpp @@ -446,17 +446,17 @@ int main(int argc, char* argv[]) outputFiles[fileNum]->writePacket(*parsedPacket.getRawPacket()); // if splitter wants us to close files - go over the file numbers and close them - for (const auto &it : filesToClose) + for (const auto &fileId : filesToClose) { // check if that file number is in the map - if (outputFiles.find(it) != outputFiles.end()) + if (outputFiles.find(fileId) != outputFiles.end()) { // close the writer - outputFiles[it]->close(); + outputFiles[fileId]->close(); // free the writer memory and put null in the map record - delete outputFiles[it]; - outputFiles[it] = nullptr; + delete outputFiles[fileId]; + outputFiles[fileId] = nullptr; } } diff --git a/Examples/PfRingExample-FilterTraffic/main.cpp b/Examples/PfRingExample-FilterTraffic/main.cpp index 1e6fcf4ec8..06fc4df465 100644 --- a/Examples/PfRingExample-FilterTraffic/main.cpp +++ b/Examples/PfRingExample-FilterTraffic/main.cpp @@ -135,12 +135,12 @@ void listPfRingDevices() pcpp::Logger::getInstance().suppressLogs(); const std::vector& devList = pcpp::PfRingDeviceList::getInstance().getPfRingDevicesList(); - for (const auto &iter : devList) + for (const auto &dev : devList) { std::ostringstream interfaceIndex; - if (iter->getInterfaceIndex() <= 9999) + if (dev->getInterfaceIndex() <= 9999) { - interfaceIndex << iter->getInterfaceIndex(); + interfaceIndex << dev->getInterfaceIndex(); } else { @@ -148,11 +148,11 @@ void listPfRingDevices() } std::cout - << " -> Name: " << std::left << std::setw(8) << iter->getDeviceName() + << " -> Name: " << std::left << std::setw(8) << dev->getDeviceName() << " Index: " << std::setw(5) << interfaceIndex.str() - << " MAC address: " << std::setw(19) << (iter->getMacAddress() == pcpp::MacAddress::Zero ? "N/A" : iter->getMacAddress().toString()) - << " Available RX channels: " << std::setw(3) << (int)iter->getTotalNumOfRxChannels() - << " MTU: " << iter->getMtu() + << " MAC address: " << std::setw(19) << (dev->getMacAddress() == pcpp::MacAddress::Zero ? "N/A" : iter->getMacAddress().toString()) + << " Available RX channels: " << std::setw(3) << (int)dev->getTotalNumOfRxChannels() + << " MTU: " << dev->getMtu() << std::endl; } diff --git a/Examples/SSLAnalyzer/main.cpp b/Examples/SSLAnalyzer/main.cpp index d8c8e44bf9..3cc6ad9a70 100644 --- a/Examples/SSLAnalyzer/main.cpp +++ b/Examples/SSLAnalyzer/main.cpp @@ -124,9 +124,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (const auto &iter : devList) + for (const auto &dev : devList) { - std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << dev->getName() << "' IP address: " << dev->getIPv4Address().toString() << std::endl; } exit(0); } diff --git a/Examples/TLSFingerprinting/main.cpp b/Examples/TLSFingerprinting/main.cpp index da7ae03a55..a85fcb238d 100644 --- a/Examples/TLSFingerprinting/main.cpp +++ b/Examples/TLSFingerprinting/main.cpp @@ -128,9 +128,9 @@ void listInterfaces() const std::vector& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList(); std::cout << std::endl << "Network interfaces:" << std::endl; - for (const auto &iter : devList) + for (const auto &dev : devList) { - std::cout << " -> Name: '" << iter->getName() << "' IP address: " << iter->getIPv4Address().toString() << std::endl; + std::cout << " -> Name: '" << dev->getName() << "' IP address: " << dev->getIPv4Address().toString() << std::endl; } exit(0); } diff --git a/Packet++/src/BgpLayer.cpp b/Packet++/src/BgpLayer.cpp index 407e8c1d8e..bff92be631 100644 --- a/Packet++/src/BgpLayer.cpp +++ b/Packet++/src/BgpLayer.cpp @@ -163,26 +163,26 @@ size_t BgpOpenMessageLayer::optionalParamsToByteArray(const std::vector 32) + if (param.length > 32) { - PCPP_LOG_ERROR("Illegal optional parameter length " << (int)iter.length << ", must be 32 bytes or less"); + PCPP_LOG_ERROR("Illegal optional parameter length " << (int)param.length << ", must be 32 bytes or less"); break; // illegal value } - size_t curDataSize = 2*sizeof(uint8_t) + (size_t)iter.length; + size_t curDataSize = 2*sizeof(uint8_t) + (size_t)param.length; if (dataLen + curDataSize > maxByteArrSize) { break; } - resultByteArr[0] = iter.type; - resultByteArr[1] = iter.length; - if (iter.length > 0) + resultByteArr[0] = param.type; + resultByteArr[1] = param.length; + if (param.length > 0) { - memcpy(resultByteArr + 2*sizeof(uint8_t), iter.value, iter.length); + memcpy(resultByteArr + 2*sizeof(uint8_t), param.value, param.length); } dataLen += curDataSize; @@ -416,13 +416,13 @@ size_t BgpUpdateMessageLayer::prefixAndIPDataToByteArray(const std::vector 32) + if (attribute.length > 32) { - PCPP_LOG_ERROR("Illegal path attribute length " << (int)iter.length); + PCPP_LOG_ERROR("Illegal path attribute length " << (int)attribute.length); break; // illegal value } - size_t curDataSize = 3*sizeof(uint8_t) + (size_t)iter.length; + size_t curDataSize = 3*sizeof(uint8_t) + (size_t)attribute.length; if (dataLen + curDataSize > maxByteArrSize) { break; } - resultByteArr[0] = iter.flags; - resultByteArr[1] = iter.type; - resultByteArr[2] = iter.length; - if (iter.length > 0) + resultByteArr[0] = attribute.flags; + resultByteArr[1] = attribute.type; + resultByteArr[2] = attribute.length; + if (attribute.length > 0) { - memcpy(resultByteArr + 3*sizeof(uint8_t), iter.data, iter.length); + memcpy(resultByteArr + 3*sizeof(uint8_t), attribute.data, attribute.length); } dataLen += curDataSize; diff --git a/Packet++/src/IPv4Layer.cpp b/Packet++/src/IPv4Layer.cpp index df32b85953..777af11e96 100644 --- a/Packet++/src/IPv4Layer.cpp +++ b/Packet++/src/IPv4Layer.cpp @@ -37,9 +37,9 @@ IPv4OptionBuilder::IPv4OptionBuilder(IPv4OptionTypes optionType, const std::vect m_RecValue[curOffset++] = 0; // init pointer value bool firstZero = false; - for (const auto &iter : ipList) + for (const auto &ipAddr : ipList) { - uint32_t ipAddrAsInt = iter.toInt(); + uint32_t ipAddrAsInt = ipAddr.toInt(); if (!firstZero) m_RecValue[0] += (uint8_t)4; diff --git a/Packet++/src/IgmpLayer.cpp b/Packet++/src/IgmpLayer.cpp index d49e1d6c30..96253b1248 100644 --- a/Packet++/src/IgmpLayer.cpp +++ b/Packet++/src/IgmpLayer.cpp @@ -420,9 +420,9 @@ igmpv3_group_record* IgmpV3ReportLayer::addGroupRecordAt(uint8_t recordType, con newGroupRecord->numOfSources = htobe16(sourceAddresses.size()); int srcAddrOffset = 0; - for (const auto &iter : sourceAddresses) + for (const auto &address : sourceAddresses) { - memcpy(newGroupRecord->sourceAddresses + srcAddrOffset, iter.toBytes(), sizeof(uint32_t)); + memcpy(newGroupRecord->sourceAddresses + srcAddrOffset, address.toBytes(), sizeof(uint32_t)); srcAddrOffset += sizeof(uint32_t); } diff --git a/Pcap++/src/DpdkDeviceList.cpp b/Pcap++/src/DpdkDeviceList.cpp index 64e9b6e42c..de4595c5b5 100644 --- a/Pcap++/src/DpdkDeviceList.cpp +++ b/Pcap++/src/DpdkDeviceList.cpp @@ -64,9 +64,9 @@ DpdkDeviceList::DpdkDeviceList() DpdkDeviceList::~DpdkDeviceList() { - for (auto iter : m_DpdkDeviceList) + for (auto dev : m_DpdkDeviceList) { - delete iter; + delete dev; } m_DpdkDeviceList.clear(); @@ -223,10 +223,10 @@ DpdkDevice* DpdkDeviceList::getDeviceByPciAddress(const std::string& pciAddr) co return NULL; } - for (const auto &iter : m_DpdkDeviceList) + for (const auto &dev : m_DpdkDeviceList) { - if (iter->getPciAddress() == pciAddr) - return iter; + if (dev->getPciAddress() == pciAddr) + return dev; } return NULL; @@ -382,11 +382,11 @@ bool DpdkDeviceList::startDpdkWorkerThreads(CoreMask coreMask, std::vectorstop(); - rte_eal_wait_lcore(iter->getCoreId()); - PCPP_LOG_DEBUG("Thread on core [" << iter->getCoreId() << "] stopped"); + thread->stop(); + rte_eal_wait_lcore(thread->getCoreId()); + PCPP_LOG_DEBUG("Thread on core [" << thread->getCoreId() << "] stopped"); } PCPP_LOG_ERROR("Cannot create worker thread #" << core.Id << ". Error was: [" << strerror(err) << "]"); return false; @@ -408,11 +408,11 @@ void DpdkDeviceList::stopDpdkWorkerThreads() return; } - for (const auto &iter : m_WorkerThreads) + for (const auto &thread : m_WorkerThreads) { - iter->stop(); - rte_eal_wait_lcore(iter->getCoreId()); - PCPP_LOG_DEBUG("Thread on core [" << iter->getCoreId() << "] stopped"); + thread->stop(); + rte_eal_wait_lcore(thread->getCoreId()); + PCPP_LOG_DEBUG("Thread on core [" << thread->getCoreId() << "] stopped"); } m_WorkerThreads.clear(); From 66ce310b1a8855df6228caf96885bb10cb70b58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 9 Dec 2023 16:28:53 +0300 Subject: [PATCH 11/17] suppress new stl warnings --- Pcap++/src/DpdkDeviceList.cpp | 11 +++++++---- Pcap++/src/PcapLiveDeviceList.cpp | 11 +++++++---- Pcap++/src/PfRingDeviceList.cpp | 12 +++++++----- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Pcap++/src/DpdkDeviceList.cpp b/Pcap++/src/DpdkDeviceList.cpp index de4595c5b5..0cb638389a 100644 --- a/Pcap++/src/DpdkDeviceList.cpp +++ b/Pcap++/src/DpdkDeviceList.cpp @@ -223,13 +223,16 @@ DpdkDevice* DpdkDeviceList::getDeviceByPciAddress(const std::string& pciAddr) co return NULL; } - for (const auto &dev : m_DpdkDeviceList) + auto devIter = std::find_if(m_DpdkDeviceList.begin(), m_DpdkDeviceList.end(), + [&pciAddr](const DpdkDevice *dev) { return dev->getPciAddress() == pciAddr; }); + + if (devIter == m_DpdkDeviceList.end()) { - if (dev->getPciAddress() == pciAddr) - return dev; + PCPP_LOG_DEBUG("Found no DPDK devices with PCI address '" << pciAddr << "'"); + return nullptr; } - return NULL; + return *devIter; } bool DpdkDeviceList::verifyHugePagesAndDpdkDriver() diff --git a/Pcap++/src/PcapLiveDeviceList.cpp b/Pcap++/src/PcapLiveDeviceList.cpp index e7eee7d47d..c2012429e6 100644 --- a/Pcap++/src/PcapLiveDeviceList.cpp +++ b/Pcap++/src/PcapLiveDeviceList.cpp @@ -316,13 +316,16 @@ PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIp(const std::string& ipA PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByName(const std::string& name) const { PCPP_LOG_DEBUG("Searching all live devices..."); - for(const auto &devIter : m_LiveDeviceList) + auto devIter = std::find_if(m_LiveDeviceList.begin(), m_LiveDeviceList.end(), + [&name](const PcapLiveDevice *dev) { return dev->getName() == name; }); + + if (devIter == m_LiveDeviceList.end()) { - if (name == devIter->getName()) - return devIter; + PCPP_LOG_DEBUG("Found no live device with name '" << name << "'"); + return nullptr; } - return nullptr; + return *devIter; } PcapLiveDevice* PcapLiveDeviceList::getPcapLiveDeviceByIpOrName(const std::string& ipOrName) const diff --git a/Pcap++/src/PfRingDeviceList.cpp b/Pcap++/src/PfRingDeviceList.cpp index 6008d7dd45..33e571a82e 100644 --- a/Pcap++/src/PfRingDeviceList.cpp +++ b/Pcap++/src/PfRingDeviceList.cpp @@ -68,14 +68,16 @@ PfRingDeviceList::~PfRingDeviceList() PfRingDevice* PfRingDeviceList::getPfRingDeviceByName(const std::string &devName) const { PCPP_LOG_DEBUG("Searching all live devices..."); - for(const auto &devIter : m_PfRingDeviceList) + auto devIter = std::find_if(m_PfRingDeviceList.begin(), m_PfRingDeviceList.end(), + [&devName](const PfRingDevice *dev) { return dev->getName() == devName; }); + + if (devIter == m_PfRingDeviceList.end()) { - if (devIter->getDeviceName() == devName) - return devIter; + PCPP_LOG_DEBUG("Found no PF_RING devices with name '" << devName << "'"); + return nullptr; } - PCPP_LOG_DEBUG("Found no PF_RING devices with name '" << devName << "'"); - return NULL; + return *devIter; } void PfRingDeviceList::calcPfRingVersion(void* ring) From d1a60ce9ea5147bec7aedef805abdb2839602874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 9 Dec 2023 16:46:28 +0300 Subject: [PATCH 12/17] fix for const warn --- Common++/header/SystemUtils.h | 4 ++-- Common++/src/SystemUtils.cpp | 4 ++-- Packet++/header/SdpLayer.h | 2 +- Packet++/src/SdpLayer.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Common++/header/SystemUtils.h b/Common++/header/SystemUtils.h index afbf9a40c2..e30cce8297 100644 --- a/Common++/header/SystemUtils.h +++ b/Common++/header/SystemUtils.h @@ -207,7 +207,7 @@ namespace pcpp * @param[in] cores A vector of SystemCore instances * @return A core mask representing these cores */ - CoreMask createCoreMaskFromCoreVector(std::vector cores); + CoreMask createCoreMaskFromCoreVector(const std::vector &cores); /** @@ -215,7 +215,7 @@ namespace pcpp * @param[in] coreIds A vector of core IDs * @return A core mask representing these cores */ - CoreMask createCoreMaskFromCoreIds(std::vector coreIds); + CoreMask createCoreMaskFromCoreIds(const std::vector &coreIds); /** diff --git a/Common++/src/SystemUtils.cpp b/Common++/src/SystemUtils.cpp index 6f8dde916f..0bc9fdf0d0 100644 --- a/Common++/src/SystemUtils.cpp +++ b/Common++/src/SystemUtils.cpp @@ -144,7 +144,7 @@ CoreMask getCoreMaskForAllMachineCores() return result; } -CoreMask createCoreMaskFromCoreVector(std::vector cores) +CoreMask createCoreMaskFromCoreVector(const std::vector &cores) { CoreMask result = 0; for (const auto &core : cores) @@ -156,7 +156,7 @@ CoreMask createCoreMaskFromCoreVector(std::vector cores) return result; } -CoreMask createCoreMaskFromCoreIds(std::vector coreIds) +CoreMask createCoreMaskFromCoreIds(const std::vector &coreIds) { CoreMask result = 0; for (const auto &coreId : coreIds) diff --git a/Packet++/header/SdpLayer.h b/Packet++/header/SdpLayer.h index 9ae16e6559..256f741fee 100644 --- a/Packet++/header/SdpLayer.h +++ b/Packet++/header/SdpLayer.h @@ -149,7 +149,7 @@ namespace pcpp * translated into a 'media-attribute' field (a=) * @return True if all fields were added properly or false if at least one field was failed to be added */ - bool addMediaDescription(const std::string& mediaType, uint16_t mediaPort, const std::string& mediaProtocol, const std::string& mediaFormat, std::vector mediaAttributes); + bool addMediaDescription(const std::string& mediaType, uint16_t mediaPort, const std::string& mediaProtocol, const std::string& mediaFormat, const std::vector &mediaAttributes); // overridden methods diff --git a/Packet++/src/SdpLayer.cpp b/Packet++/src/SdpLayer.cpp index 6e5e1fd397..9a346175ea 100644 --- a/Packet++/src/SdpLayer.cpp +++ b/Packet++/src/SdpLayer.cpp @@ -107,7 +107,7 @@ uint16_t SdpLayer::getMediaPort(const std::string& mediaType) const return 0; } -bool SdpLayer::addMediaDescription(const std::string& mediaType, uint16_t mediaPort, const std::string& mediaProtocol, const std::string& mediaFormat, std::vector mediaAttributes) +bool SdpLayer::addMediaDescription(const std::string& mediaType, uint16_t mediaPort, const std::string& mediaProtocol, const std::string& mediaFormat, const std::vector &mediaAttributes) { std::stringstream portStream; portStream << mediaPort; From 5b6fee6caa54767fc0286c1362fb2be32a70e727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 9 Dec 2023 16:56:56 +0300 Subject: [PATCH 13/17] minor fixes --- Pcap++/src/DpdkDeviceList.cpp | 2 +- Pcap++/src/PfRingDeviceList.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Pcap++/src/DpdkDeviceList.cpp b/Pcap++/src/DpdkDeviceList.cpp index 0cb638389a..408bda677c 100644 --- a/Pcap++/src/DpdkDeviceList.cpp +++ b/Pcap++/src/DpdkDeviceList.cpp @@ -394,7 +394,7 @@ bool DpdkDeviceList::startDpdkWorkerThreads(CoreMask coreMask, std::vectorgetName() == devName; }); + [&devName](const PfRingDevice *dev) { return dev->getDeviceName() == devName; }); if (devIter == m_PfRingDeviceList.end()) { From 31ec3de1ec4fa97b9d159d88a6690ca91920aa04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 9 Dec 2023 19:49:15 +0300 Subject: [PATCH 14/17] minor fix --- Examples/DpdkExample-FilterTraffic/AppWorkerThread.h | 2 +- Examples/PfRingExample-FilterTraffic/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h b/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h index 442900fe08..059a108b56 100644 --- a/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h +++ b/Examples/DpdkExample-FilterTraffic/AppWorkerThread.h @@ -77,7 +77,7 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread for (const auto &iter : m_WorkerConfig.InDataCfg) { // for each DPDK device go over all RX queues configured for this worker/core - for (const auto &iter2 = iter.second) + for (const auto &iter2 : iter.second) { pcpp::DpdkDevice* dev = iter.first; diff --git a/Examples/PfRingExample-FilterTraffic/main.cpp b/Examples/PfRingExample-FilterTraffic/main.cpp index 06fc4df465..0469936d9f 100644 --- a/Examples/PfRingExample-FilterTraffic/main.cpp +++ b/Examples/PfRingExample-FilterTraffic/main.cpp @@ -150,7 +150,7 @@ void listPfRingDevices() std::cout << " -> Name: " << std::left << std::setw(8) << dev->getDeviceName() << " Index: " << std::setw(5) << interfaceIndex.str() - << " MAC address: " << std::setw(19) << (dev->getMacAddress() == pcpp::MacAddress::Zero ? "N/A" : iter->getMacAddress().toString()) + << " MAC address: " << std::setw(19) << (dev->getMacAddress() == pcpp::MacAddress::Zero ? "N/A" : dev->getMacAddress().toString()) << " Available RX channels: " << std::setw(3) << (int)dev->getTotalNumOfRxChannels() << " MTU: " << dev->getMtu() << std::endl; From bd1fba24d507c5f60c2149421e7d8e89bd6d9468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 9 Dec 2023 19:53:34 +0300 Subject: [PATCH 15/17] minor fix --- Examples/DpdkBridge/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/DpdkBridge/main.cpp b/Examples/DpdkBridge/main.cpp index 8c58c980bb..02dec1aada 100644 --- a/Examples/DpdkBridge/main.cpp +++ b/Examples/DpdkBridge/main.cpp @@ -313,7 +313,7 @@ int main(int argc, char* argv[]) std::vector dpdkDevicesToUse; for (const auto &port : dpdkPortVec) { - pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(iter); + pcpp::DpdkDevice* dev = pcpp::DpdkDeviceList::getInstance().getDeviceByPort(port); if (dev == NULL) { EXIT_WITH_ERROR("DPDK device for port " << port << " doesn't exist"); From e3028b641131c4b2e517aaec8db53c456b686992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Sat, 9 Dec 2023 20:06:04 +0300 Subject: [PATCH 16/17] not const --- Tests/Pcap++Test/Tests/DpdkTests.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Pcap++Test/Tests/DpdkTests.cpp b/Tests/Pcap++Test/Tests/DpdkTests.cpp index a9468c4ed3..417b714a65 100644 --- a/Tests/Pcap++Test/Tests/DpdkTests.cpp +++ b/Tests/Pcap++Test/Tests/DpdkTests.cpp @@ -485,7 +485,7 @@ PTF_TEST_CASE(TestDpdkMultiThread) PTF_ASSERT_EQUAL(res.size(), 0); if (PTF_IS_VERBOSE_MODE) { - for (const auto &iter : res) + for (auto &iter : res) { PTF_PRINT_VERBOSE("Same flow exists in core " << firstCoreId << " and core " << secondCoreId << ". Flow key = " << iter.first); std::ostringstream stream; @@ -513,7 +513,7 @@ PTF_TEST_CASE(TestDpdkMultiThread) if (PTF_IS_VERBOSE_MODE) { - for(const auto &iter : packetDataMultiThread[firstCoreId].FlowKeys) + for(auto &iter : packetDataMultiThread[firstCoreId].FlowKeys) { PTF_PRINT_VERBOSE("Key=0x" << std::hex << iter.first << "; Value=" << std::dec << iter.second.size()); iter.second.clear(); @@ -804,7 +804,7 @@ PTF_TEST_CASE(TestDpdkDeviceWorkerThreads) // that total amount of packets received by all threads is greater than zero int packetCount = 0; - for (const auto &iter : workerThreadVec) + for (auto &iter : workerThreadVec) { DpdkTestWorkerThread* thread = (DpdkTestWorkerThread*)iter; PTF_ASSERT_TRUE(thread->threadRanAndStopped()); From e38dfa1336c05705ae390c26f509918f37fae765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20=C3=87etin?= Date: Thu, 14 Dec 2023 11:01:53 +0300 Subject: [PATCH 17/17] update comment --- Common++/src/TablePrinter.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Common++/src/TablePrinter.cpp b/Common++/src/TablePrinter.cpp index 1fe0a792b7..153801def2 100644 --- a/Common++/src/TablePrinter.cpp +++ b/Common++/src/TablePrinter.cpp @@ -89,12 +89,8 @@ void TablePrinter::printSeparator() return; } - int totalLen = std::accumulate(m_ColumnWidths.begin(), m_ColumnWidths.end(), m_ColumnWidths.size() * 3) + 1; - - for (int index = 0; index < totalLen; index++) - std::cout << "-"; - - std::cout << std::endl; + auto totalLen = std::accumulate(m_ColumnWidths.begin(), m_ColumnWidths.end(), m_ColumnWidths.size() * 3) + 1; + std::cout << std::string(totalLen, '-') << std::endl; } void TablePrinter::closeTable()