diff --git a/pcsx2/DEV9/AdapterUtils.cpp b/pcsx2/DEV9/AdapterUtils.cpp index f34d3bf952..830aa50c74 100644 --- a/pcsx2/DEV9/AdapterUtils.cpp +++ b/pcsx2/DEV9/AdapterUtils.cpp @@ -45,7 +45,7 @@ using namespace PacketReader::IP; bool AdapterUtils::GetWin32Adapter(const std::string& name, PIP_ADAPTER_ADDRESSES adapter, std::unique_ptr* buffer) { int neededSize = 128; - std::unique_ptr AdapterInfo = std::make_unique(neededSize); + std::unique_ptr adapterInfo = std::make_unique(neededSize); ULONG dwBufLen = sizeof(IP_ADAPTER_ADDRESSES) * neededSize; PIP_ADAPTER_ADDRESSES pAdapterInfo; @@ -54,14 +54,14 @@ bool AdapterUtils::GetWin32Adapter(const std::string& name, PIP_ADAPTER_ADDRESSE AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_INCLUDE_GATEWAYS, NULL, - AdapterInfo.get(), + adapterInfo.get(), &dwBufLen); if (dwStatus == ERROR_BUFFER_OVERFLOW) { DevCon.WriteLn("DEV9: GetWin32Adapter() buffer too small, resizing"); neededSize = dwBufLen / sizeof(IP_ADAPTER_ADDRESSES) + 1; - AdapterInfo = std::make_unique(neededSize); + adapterInfo = std::make_unique(neededSize); dwBufLen = sizeof(IP_ADAPTER_ADDRESSES) * neededSize; DevCon.WriteLn("DEV9: New size %i", neededSize); @@ -69,31 +69,32 @@ bool AdapterUtils::GetWin32Adapter(const std::string& name, PIP_ADAPTER_ADDRESSE AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_INCLUDE_GATEWAYS, NULL, - AdapterInfo.get(), + adapterInfo.get(), &dwBufLen); } if (dwStatus != ERROR_SUCCESS) return false; - pAdapterInfo = AdapterInfo.get(); + pAdapterInfo = adapterInfo.get(); do { if (strcmp(pAdapterInfo->AdapterName, name.c_str()) == 0) { *adapter = *pAdapterInfo; - buffer->swap(AdapterInfo); + buffer->swap(adapterInfo); return true; } pAdapterInfo = pAdapterInfo->Next; } while (pAdapterInfo); + return false; } bool AdapterUtils::GetWin32AdapterAuto(PIP_ADAPTER_ADDRESSES adapter, std::unique_ptr* buffer) { int neededSize = 128; - std::unique_ptr AdapterInfo = std::make_unique(neededSize); + std::unique_ptr adapterInfo = std::make_unique(neededSize); ULONG dwBufLen = sizeof(IP_ADAPTER_ADDRESSES) * neededSize; PIP_ADAPTER_ADDRESSES pAdapter; @@ -102,7 +103,7 @@ bool AdapterUtils::GetWin32AdapterAuto(PIP_ADAPTER_ADDRESSES adapter, std::uniqu AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_INCLUDE_GATEWAYS, NULL, - AdapterInfo.get(), + adapterInfo.get(), &dwBufLen); if (dwStatus == ERROR_BUFFER_OVERFLOW) @@ -110,7 +111,7 @@ bool AdapterUtils::GetWin32AdapterAuto(PIP_ADAPTER_ADDRESSES adapter, std::uniqu DevCon.WriteLn("DEV9: PCAPGetWin32Adapter() buffer too small, resizing"); // neededSize = dwBufLen / sizeof(IP_ADAPTER_ADDRESSES) + 1; - AdapterInfo = std::make_unique(neededSize); + adapterInfo = std::make_unique(neededSize); dwBufLen = sizeof(IP_ADAPTER_ADDRESSES) * neededSize; DevCon.WriteLn("DEV9: New size %i", neededSize); @@ -118,45 +119,45 @@ bool AdapterUtils::GetWin32AdapterAuto(PIP_ADAPTER_ADDRESSES adapter, std::uniqu AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_INCLUDE_GATEWAYS, NULL, - AdapterInfo.get(), + adapterInfo.get(), &dwBufLen); } if (dwStatus != ERROR_SUCCESS) return 0; - pAdapter = AdapterInfo.get(); + pAdapter = adapterInfo.get(); do { if (pAdapter->IfType != IF_TYPE_SOFTWARE_LOOPBACK && pAdapter->OperStatus == IfOperStatusUp) { - //Search for an adapter with; - //IPv4 Address - //DNS - //Gateway + // Search for an adapter with; + // IPv4 Address, + // DNS, + // Gateway. bool hasIPv4 = false; bool hasDNS = false; bool hasGateway = false; - //IPv4 + // IPv4. if (GetAdapterIP(pAdapter).has_value()) hasIPv4 = true; - //DNS + // DNS. if (GetDNS(pAdapter).size() > 0) hasDNS = true; - //Gateway + // Gateway. if (GetGateways(pAdapter).size() > 0) hasGateway = true; if (hasIPv4 && hasDNS && hasGateway) { *adapter = *pAdapter; - buffer->swap(AdapterInfo); + buffer->swap(adapterInfo); return true; } } @@ -212,9 +213,9 @@ bool AdapterUtils::GetIfAdapterAuto(ifaddrs* adapter, ifaddrs** buffer) if ((pAdapter->ifa_flags & IFF_LOOPBACK) == 0 && (pAdapter->ifa_flags & IFF_UP) != 0) { - //Search for an adapter with; - //IPv4 Address - //Gateway + // Search for an adapter with; + // IPv4 Address, + // Gateway. bool hasIPv4 = false; bool hasGateway = false; @@ -241,7 +242,7 @@ bool AdapterUtils::GetIfAdapterAuto(ifaddrs* adapter, ifaddrs** buffer) } #endif -//AdapterIP +// AdapterIP. #ifdef _WIN32 std::optional AdapterUtils::GetAdapterIP(PIP_ADAPTER_ADDRESSES adapter) { @@ -279,7 +280,7 @@ std::optional AdapterUtils::GetAdapterIP(ifaddrs* adapter) } #endif -//Gateways +// Gateways. #ifdef _WIN32 std::vector AdapterUtils::GetGateways(PIP_ADAPTER_ADDRESSES adapter) { @@ -305,8 +306,8 @@ std::vector AdapterUtils::GetGateways(PIP_ADAPTER_ADDRESSES adapter) #ifdef __linux__ std::vector AdapterUtils::GetGateways(ifaddrs* adapter) { - ///proc/net/route contains some information about gateway addresses, - //and separates the information about by each interface. + // /proc/net/route contains some information about gateway addresses, + // and separates the information about by each interface. if (adapter == nullptr) return {}; @@ -325,8 +326,8 @@ std::vector AdapterUtils::GetGateways(ifaddrs* adapter) routeLines.push_back(line); route.close(); - //Columns are as follows (first-line header): - //Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT + // Columns are as follows (first-line header): + // Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT. for (size_t i = 1; i < routeLines.size(); i++) { std::string line = routeLines[i]; @@ -356,7 +357,7 @@ std::vector AdapterUtils::GetGateways(ifaddrs* adapter) std::vector collection; - //Get index for our adapter by matching the adapter name + // Get index for our adapter by matching the adapter name. int ifIndex = -1; struct if_nameindex* ifNI; @@ -379,14 +380,14 @@ std::vector AdapterUtils::GetGateways(ifaddrs* adapter) } if_freenameindex(ifNI); - //Check if we found the adapter + // Check if we found the adapter. if (ifIndex == -1) { Console.Error("DEV9: Failed to get index for adapter"); return collection; } - //Find the gateway by looking though the routing information + // Find the gateway by looking though the routing information. int name[] = {CTL_NET, PF_ROUTE, 0, AF_INET, NET_RT_DUMP, 0}; size_t bufferLen = 0; @@ -396,7 +397,7 @@ std::vector AdapterUtils::GetGateways(ifaddrs* adapter) return collection; } - //len is an estimate, double it to be safe + // bufferLen is an estimate, double it to be safe. bufferLen *= 2; std::unique_ptr buffer = std::make_unique(bufferLen); @@ -416,7 +417,7 @@ std::vector AdapterUtils::GetGateways(ifaddrs* adapter) sockaddr* sockaddrs = (sockaddr*)(hdr + 1); pxAssert(sockaddrs[RTAX_DST].sa_family == AF_INET); - //Default gateway has no destination address + // Default gateway has no destination address. sockaddr_in* sockaddr = (sockaddr_in*)&sockaddrs[RTAX_DST]; if (sockaddr->sin_addr.s_addr != 0) continue; @@ -437,7 +438,7 @@ std::vector AdapterUtils::GetGateways(ifaddrs* adapter) #endif #endif -//DNS +// DNS. #ifdef _WIN32 std::vector AdapterUtils::GetDNS(PIP_ADAPTER_ADDRESSES adapter) { @@ -462,7 +463,7 @@ std::vector AdapterUtils::GetDNS(PIP_ADAPTER_ADDRESSES adapter) #elif defined(__POSIX__) std::vector AdapterUtils::GetDNS(ifaddrs* adapter) { - //On Linux and OSX, DNS is system wide, not adapter specific, so we can ignore adapter + // On Linux and OSX, DNS is system wide, not adapter specific, so we can ignore the adapter parameter. // Parse /etc/resolv.conf for all of the "nameserver" entries. // These are the DNS servers the machine is configured to use. diff --git a/pcsx2/DEV9/AdapterUtils.h b/pcsx2/DEV9/AdapterUtils.h index ee59034a22..52b902111a 100644 --- a/pcsx2/DEV9/AdapterUtils.h +++ b/pcsx2/DEV9/AdapterUtils.h @@ -35,7 +35,7 @@ namespace AdapterUtils bool GetWin32AdapterAuto(PIP_ADAPTER_ADDRESSES adapter, std::unique_ptr* buffer); std::optional GetAdapterIP(PIP_ADAPTER_ADDRESSES adapter); - //Mask + // Mask. std::vector GetGateways(PIP_ADAPTER_ADDRESSES adapter); std::vector GetDNS(PIP_ADAPTER_ADDRESSES adapter); #elif defined(__POSIX__) @@ -43,7 +43,7 @@ namespace AdapterUtils bool GetIfAdapterAuto(ifaddrs* adapter, ifaddrs** buffer); std::optional GetAdapterIP(ifaddrs* adapter); - //Mask + // Mask. std::vector GetGateways(ifaddrs* adapter); std::vector GetDNS(ifaddrs* adapter); #endif