mirror of https://github.com/PCSX2/pcsx2.git
DEV9: Code cleanup.
Casts, constants, unused functions, switch cases.
This commit is contained in:
parent
f69d5835b8
commit
f113a51783
|
@ -91,8 +91,8 @@ namespace Sessions
|
|||
return;
|
||||
}
|
||||
|
||||
icmpEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
if (icmpEvent == NULL)
|
||||
icmpEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
if (icmpEvent == nullptr)
|
||||
{
|
||||
Console.Error("DEV9: ICMP: Failed to Create Event");
|
||||
IcmpCloseHandle(icmpFile);
|
||||
|
|
|
@ -169,7 +169,7 @@ namespace Sessions
|
|||
memcpy(recivedData->data.get(), buffer.get(), recived);
|
||||
|
||||
std::unique_ptr<TCP_Packet> iRet = CreateBasePacket(recivedData);
|
||||
IncrementMyNumber((u32)recived);
|
||||
IncrementMyNumber(static_cast<u32>(recived));
|
||||
|
||||
iRet->SetACK(true);
|
||||
iRet->SetPSH(true);
|
||||
|
|
|
@ -193,7 +193,7 @@ namespace Sessions
|
|||
#endif
|
||||
|
||||
|
||||
const int noDelay = true; // BOOL on Windows
|
||||
constexpr int noDelay = true; // BOOL on Windows
|
||||
ret = setsockopt(client, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<const char*>(&noDelay), sizeof(noDelay));
|
||||
|
||||
if (ret != 0)
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Sessions
|
|||
return;
|
||||
}
|
||||
|
||||
const int reuseAddress = true; // BOOL on Windows
|
||||
constexpr int reuseAddress = true; // BOOL on Windows
|
||||
ret = setsockopt(client, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char*>(&reuseAddress), sizeof(reuseAddress));
|
||||
|
||||
if (ret == SOCKET_ERROR)
|
||||
|
@ -76,7 +76,7 @@ namespace Sessions
|
|||
errno);
|
||||
#endif
|
||||
|
||||
const int broadcastEnable = true; // BOOL on Windows
|
||||
constexpr int broadcastEnable = true; // BOOL on Windows
|
||||
ret = setsockopt(client, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<const char*>(&broadcastEnable), sizeof(broadcastEnable));
|
||||
|
||||
if (ret == SOCKET_ERROR)
|
||||
|
|
|
@ -225,7 +225,7 @@ namespace Sessions
|
|||
return false;
|
||||
}
|
||||
|
||||
const int reuseAddress = true; // BOOL on Windows
|
||||
constexpr int reuseAddress = true; // BOOL on Windows
|
||||
ret = setsockopt(client, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char*>(&reuseAddress), sizeof(reuseAddress));
|
||||
|
||||
if (ret == SOCKET_ERROR)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define CARD_SIZE_ECC (1024 * BLOCK_SIZE_ECC)
|
||||
|
||||
|
||||
static u32 ctrl, cmd = (u32)-1, address, id, counter, addrbyte;
|
||||
static u32 ctrl, cmd = static_cast<u32>(-1), address, id, counter, addrbyte;
|
||||
static u8 data[PAGE_SIZE_ECC], file[CARD_SIZE_ECC];
|
||||
|
||||
static void xfromman_call20_calculateXors(unsigned char buffer[128], unsigned char blah[4]);
|
||||
|
|
|
@ -208,12 +208,12 @@ void NetAdapter::InspectSend(NetPacket* pkt)
|
|||
if (EmuConfig.DEV9.EthLogDNS || EmuConfig.DEV9.EthLogDHCP)
|
||||
{
|
||||
EthernetFrame frame(pkt);
|
||||
if (frame.protocol == (u16)EtherType::IPv4)
|
||||
if (frame.protocol == static_cast<u16>(EtherType::IPv4))
|
||||
{
|
||||
PayloadPtr* payload = static_cast<PayloadPtr*>(frame.GetPayload());
|
||||
IP_Packet ippkt(payload->data, payload->GetLength());
|
||||
|
||||
if (ippkt.protocol == (u16)IP_Type::UDP)
|
||||
if (ippkt.protocol == static_cast<u16>(IP_Type::UDP))
|
||||
{
|
||||
IP_PayloadPtr* ipPayload = static_cast<IP_PayloadPtr*>(ippkt.GetPayload());
|
||||
UDP_Packet udppkt(ipPayload->data, ipPayload->GetLength());
|
||||
|
@ -240,12 +240,12 @@ void NetAdapter::InspectRecv(NetPacket* pkt)
|
|||
if (EmuConfig.DEV9.EthLogDNS || EmuConfig.DEV9.EthLogDHCP)
|
||||
{
|
||||
EthernetFrame frame(pkt);
|
||||
if (frame.protocol == (u16)EtherType::IPv4)
|
||||
if (frame.protocol == static_cast<u16>(EtherType::IPv4))
|
||||
{
|
||||
PayloadPtr* payload = static_cast<PayloadPtr*>(frame.GetPayload());
|
||||
IP_Packet ippkt(payload->data, payload->GetLength());
|
||||
|
||||
if (ippkt.protocol == (u16)IP_Type::UDP)
|
||||
if (ippkt.protocol == static_cast<u16>(IP_Type::UDP))
|
||||
{
|
||||
IP_PayloadPtr* ipPayload = static_cast<IP_PayloadPtr*>(ippkt.GetPayload());
|
||||
UDP_Packet udppkt(ipPayload->data, ipPayload->GetLength());
|
||||
|
@ -350,7 +350,7 @@ bool NetAdapter::InternalServerRecv(NetPacket* pkt)
|
|||
EthernetFrame frame(ippkt);
|
||||
frame.sourceMAC = internalMAC;
|
||||
frame.destinationMAC = ps2MAC;
|
||||
frame.protocol = (u16)EtherType::IPv4;
|
||||
frame.protocol = static_cast<u16>(EtherType::IPv4);
|
||||
frame.WritePacket(pkt);
|
||||
InspectRecv(pkt);
|
||||
return true;
|
||||
|
@ -365,7 +365,7 @@ bool NetAdapter::InternalServerRecv(NetPacket* pkt)
|
|||
EthernetFrame frame(ippkt);
|
||||
frame.sourceMAC = internalMAC;
|
||||
frame.destinationMAC = ps2MAC;
|
||||
frame.protocol = (u16)EtherType::IPv4;
|
||||
frame.protocol = static_cast<u16>(EtherType::IPv4);
|
||||
frame.WritePacket(pkt);
|
||||
InspectRecv(pkt);
|
||||
return true;
|
||||
|
@ -377,12 +377,12 @@ bool NetAdapter::InternalServerRecv(NetPacket* pkt)
|
|||
bool NetAdapter::InternalServerSend(NetPacket* pkt)
|
||||
{
|
||||
EthernetFrame frame(pkt);
|
||||
if (frame.protocol == (u16)EtherType::IPv4)
|
||||
if (frame.protocol == static_cast<u16>(EtherType::IPv4))
|
||||
{
|
||||
PayloadPtr* payload = static_cast<PayloadPtr*>(frame.GetPayload());
|
||||
IP_Packet ippkt(payload->data, payload->GetLength());
|
||||
|
||||
if (ippkt.protocol == (u16)IP_Type::UDP)
|
||||
if (ippkt.protocol == static_cast<u16>(IP_Type::UDP))
|
||||
{
|
||||
IP_PayloadPtr* ipPayload = static_cast<IP_PayloadPtr*>(ippkt.GetPayload());
|
||||
UDP_Packet udppkt(ipPayload->data, ipPayload->GetLength());
|
||||
|
@ -397,7 +397,7 @@ bool NetAdapter::InternalServerSend(NetPacket* pkt)
|
|||
|
||||
if (ippkt.destinationIP == internalIP)
|
||||
{
|
||||
if (ippkt.protocol == (u16)IP_Type::UDP)
|
||||
if (ippkt.protocol == static_cast<u16>(IP_Type::UDP))
|
||||
{
|
||||
ps2IP = ippkt.sourceIP;
|
||||
|
||||
|
|
|
@ -70,11 +70,11 @@ enum struct AdapterOptions : int
|
|||
|
||||
constexpr enum AdapterOptions operator|(const enum AdapterOptions selfValue, const enum AdapterOptions inValue)
|
||||
{
|
||||
return (enum AdapterOptions)(int(selfValue) | int(inValue));
|
||||
return static_cast<enum AdapterOptions>(static_cast<int>(selfValue) | static_cast<int>(inValue));
|
||||
}
|
||||
constexpr enum AdapterOptions operator&(const enum AdapterOptions selfValue, const enum AdapterOptions inValue)
|
||||
{
|
||||
return (enum AdapterOptions)(int(selfValue) & int(inValue));
|
||||
return static_cast<enum AdapterOptions>(static_cast<int>(selfValue) & static_cast<int>(inValue));
|
||||
}
|
||||
|
||||
class NetAdapter
|
||||
|
|
|
@ -136,7 +136,7 @@ bool PCAPAdapter::recv(NetPacket* pkt)
|
|||
pxAssert(header->len == header->caplen);
|
||||
|
||||
memcpy(pkt->buffer, pkt_data, header->len);
|
||||
pkt->size = (int)header->len;
|
||||
pkt->size = static_cast<int>(header->len);
|
||||
|
||||
if (!switched)
|
||||
SetMACBridgedRecv(pkt);
|
||||
|
@ -339,7 +339,7 @@ bool PCAPAdapter::SetMACSwitchedFilter(MAC_Address mac)
|
|||
void PCAPAdapter::SetMACBridgedRecv(NetPacket* pkt)
|
||||
{
|
||||
EthernetFrameEditor frame(pkt);
|
||||
if (frame.GetProtocol() == (u16)EtherType::IPv4) // IP
|
||||
if (frame.GetProtocol() == static_cast<u16>(EtherType::IPv4)) // IP
|
||||
{
|
||||
// Compare DEST IP in IP with the PS2's IP, if they match, change DEST MAC to ps2MAC.
|
||||
PayloadPtr* payload = frame.GetPayload();
|
||||
|
@ -347,7 +347,7 @@ void PCAPAdapter::SetMACBridgedRecv(NetPacket* pkt)
|
|||
if (ippkt.destinationIP == ps2IP)
|
||||
frame.SetDestinationMAC(ps2MAC);
|
||||
}
|
||||
if (frame.GetProtocol() == (u16)EtherType::ARP) // ARP
|
||||
if (frame.GetProtocol() == static_cast<u16>(EtherType::ARP)) // ARP
|
||||
{
|
||||
// Compare DEST IP in ARP with the PS2's IP, if they match, DEST MAC to ps2MAC on both ARP and ETH Packet headers.
|
||||
ARP_PacketEditor arpPkt(frame.GetPayload());
|
||||
|
@ -362,13 +362,13 @@ void PCAPAdapter::SetMACBridgedRecv(NetPacket* pkt)
|
|||
void PCAPAdapter::SetMACBridgedSend(NetPacket* pkt)
|
||||
{
|
||||
EthernetFrameEditor frame(pkt);
|
||||
if (frame.GetProtocol() == (u16)EtherType::IPv4) // IP
|
||||
if (frame.GetProtocol() == static_cast<u16>(EtherType::IPv4)) // IP
|
||||
{
|
||||
PayloadPtr* payload = frame.GetPayload();
|
||||
IP_Packet ippkt(payload->data, payload->GetLength());
|
||||
ps2IP = ippkt.sourceIP;
|
||||
}
|
||||
if (frame.GetProtocol() == (u16)EtherType::ARP) // ARP
|
||||
if (frame.GetProtocol() == static_cast<u16>(EtherType::ARP)) // ARP
|
||||
{
|
||||
ARP_PacketEditor arpPkt(frame.GetPayload());
|
||||
ps2IP = *(IP_Address*)arpPkt.SenderProtocolAddress();
|
||||
|
|
|
@ -37,7 +37,6 @@ public:
|
|||
|
||||
private:
|
||||
bool InitPCAP(const std::string& adapter, bool promiscuous);
|
||||
void InitPCAPDumper();
|
||||
bool SetMACSwitchedFilter(PacketReader::MAC_Address mac);
|
||||
|
||||
void SetMACBridgedRecv(NetPacket* pkt);
|
||||
|
|
|
@ -302,16 +302,14 @@ void emac3_write(u32 addr)
|
|||
value |= SMAP_E3_PHY_OP_COMP;
|
||||
int reg = value & (SMAP_E3_PHY_REG_ADDR_MSK);
|
||||
u16 val = value >> 16;
|
||||
switch (reg)
|
||||
if (reg == SMAP_DsPHYTER_BMCR)
|
||||
{
|
||||
case SMAP_DsPHYTER_BMCR:
|
||||
if (val & SMAP_PHY_BMCR_RST)
|
||||
{
|
||||
ad_reset();
|
||||
}
|
||||
val &= ~SMAP_PHY_BMCR_RST;
|
||||
val |= 0x1;
|
||||
break;
|
||||
}
|
||||
//DevCon.WriteLn("DEV9: phy_write %d: %x", reg, val);
|
||||
dev9.phyregs[reg] = val;
|
||||
|
|
|
@ -268,24 +268,24 @@ bool SocketAdapter::send(NetPacket* pkt)
|
|||
|
||||
switch (frame.protocol)
|
||||
{
|
||||
case (u16)EtherType::null:
|
||||
case static_cast<u16>(EtherType::null):
|
||||
case 0x0C00:
|
||||
//Packets with the above ethertypes get sent when the adapter is reset
|
||||
//Catch them here instead of printing an error
|
||||
return true;
|
||||
case (int)EtherType::IPv4:
|
||||
case static_cast<int>(EtherType::IPv4):
|
||||
{
|
||||
PayloadPtr* payload = static_cast<PayloadPtr*>(frame.GetPayload());
|
||||
IP_Packet ippkt(payload->data, payload->GetLength());
|
||||
|
||||
return SendIP(&ippkt);
|
||||
}
|
||||
case (u16)EtherType::ARP:
|
||||
case static_cast<u16>(EtherType::ARP):
|
||||
{
|
||||
PayloadPtr* payload = static_cast<PayloadPtr*>(frame.GetPayload());
|
||||
ARP_Packet arpPkt(payload->data, payload->GetLength());
|
||||
|
||||
if (arpPkt.protocol == (u16)EtherType::IPv4)
|
||||
if (arpPkt.protocol == static_cast<u16>(EtherType::IPv4))
|
||||
{
|
||||
if (arpPkt.op == 1) //ARP request
|
||||
{
|
||||
|
@ -304,7 +304,7 @@ bool SocketAdapter::send(NetPacket* pkt)
|
|||
EthernetFrame* retARP = new EthernetFrame(arpRet);
|
||||
retARP->destinationMAC = ps2MAC;
|
||||
retARP->sourceMAC = internalMAC;
|
||||
retARP->protocol = (u16)EtherType::ARP;
|
||||
retARP->protocol = static_cast<u16>(EtherType::ARP);
|
||||
|
||||
vRecBuffer.Enqueue(retARP);
|
||||
}
|
||||
|
@ -567,7 +567,7 @@ void SocketAdapter::HandleConnectionClosed(BaseSession* sender)
|
|||
|
||||
void SocketAdapter::HandleFixedPortClosed(BaseSession* sender)
|
||||
{
|
||||
ConnectionKey key = sender->key;
|
||||
const ConnectionKey key = sender->key;
|
||||
connections.Remove(key);
|
||||
fixedUDPPorts.Remove(key.ps2Port);
|
||||
|
||||
|
|
Loading…
Reference in New Issue