From d6076a6107de2aeb79b73395c81985d5a6c5ab00 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Fri, 12 Jul 2024 18:21:47 +0100 Subject: [PATCH] DEV9: Use const in ICMP session --- .../Sessions/ICMP_Session/ICMP_Session.cpp | 25 +++++++++---------- .../DEV9/Sessions/ICMP_Session/ICMP_Session.h | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp b/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp index bb8aa21de1..f3cd67dac3 100644 --- a/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp +++ b/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp @@ -166,7 +166,7 @@ namespace Sessions #endif } - bool ICMP_Session::Ping::IsInitialised() + bool ICMP_Session::Ping::IsInitialised() const { #ifdef _WIN32 return icmpFile != INVALID_HANDLE_VALUE; @@ -190,7 +190,7 @@ namespace Sessions { ResetEvent(icmpEvent); - int count = IcmpParseReplies(icmpResponseBuffer.get(), icmpResponseBufferLen); + const int count = IcmpParseReplies(icmpResponseBuffer.get(), icmpResponseBufferLen); pxAssert(count <= 1); // Timeout @@ -202,7 +202,7 @@ namespace Sessions } // Rely on implicit object creation - ICMP_ECHO_REPLY* pingRet = reinterpret_cast(icmpResponseBuffer.get()); + const ICMP_ECHO_REPLY* pingRet = reinterpret_cast(icmpResponseBuffer.get()); // Map status to ICMP type/code switch (pingRet->Status) @@ -419,8 +419,8 @@ namespace Sessions #endif { // Rely on implicit object creation - ip* ipHeader = reinterpret_cast(icmpResponseBuffer.get()); - int headerLength = ipHeader->ip_hl << 2; + const ip* ipHeader = reinterpret_cast(icmpResponseBuffer.get()); + const int headerLength = ipHeader->ip_hl << 2; pxAssert(headerLength == 20); offset = headerLength; @@ -448,7 +448,7 @@ namespace Sessions // Check if response is for us if (icmpConnectionKind == PingType::RAW) { - ICMP_HeaderDataIdentifier headerData(icmp.headerData); + const ICMP_HeaderDataIdentifier headerData(icmp.headerData); if (headerData.identifier != icmpId) return nullptr; } @@ -473,7 +473,7 @@ namespace Sessions ICMP_Packet icmpInner(ipPayload->data, ipPayload->GetLength()); // Check if response is for us - ICMP_HeaderDataIdentifier headerData(icmpInner.headerData); + const ICMP_HeaderDataIdentifier headerData(icmpInner.headerData); if (headerData.identifier != icmpId) return nullptr; @@ -553,7 +553,7 @@ namespace Sessions } #if defined(ICMP_SOCKETS_LINUX) - int value = 1; + const int value = 1; if (setsockopt(icmpSocket, SOL_IP, IP_RECVERR, reinterpret_cast(&value), sizeof(value))) { Console.Error("DEV9: ICMP: Failed to setsockopt IP_RECVERR. Error: %d", errno); @@ -685,8 +685,7 @@ namespace Sessions for (size_t i = 0; i < pings.size(); i++) { - ICMP_Session::PingResult* pingRet = nullptr; - pingRet = pings[i]->Recv(); + const ICMP_Session::PingResult* pingRet = pings[i]->Recv(); if (pingRet != nullptr) { std::unique_ptr ping = std::move(pings[i]); @@ -710,7 +709,7 @@ namespace Sessions // Allocate fullsize buffer std::vector temp = std::vector(ping->originalPacket->GetLength()); // Allocate returned ICMP payload - int responseSize = ping->originalPacket->GetHeaderLength() + 8; + const int responseSize = ping->originalPacket->GetHeaderLength() + 8; data = new PayloadData(responseSize); // Write packet into buffer @@ -793,8 +792,8 @@ namespace Sessions retPkt = std::make_unique(&icmpPayload->data[off], icmpPayload->GetLength(), true); } - IP_Address srvIP = retPkt->sourceIP; - u8 prot = retPkt->protocol; + const IP_Address srvIP = retPkt->sourceIP; + const u8 prot = retPkt->protocol; u16 srvPort = 0; u16 ps2Port = 0; switch (prot) diff --git a/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.h b/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.h index 7d197903f0..b0acc59fac 100644 --- a/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.h +++ b/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.h @@ -61,7 +61,7 @@ namespace Sessions public: Ping(int requestSize); - bool IsInitialised(); + bool IsInitialised() const; PingResult* Recv(); bool Send(PacketReader::IP::IP_Address parAdapterIP, PacketReader::IP::IP_Address parDestIP, int parTimeToLive, PacketReader::PayloadPtr* parPayload);