DEV9: Add ARP logger

This commit is contained in:
TheLastRar 2024-11-12 18:39:43 +00:00
parent cc1b1d06ae
commit 63b78fad40
7 changed files with 147 additions and 0 deletions

View File

@ -286,6 +286,7 @@ set(pcsx2DEV9Sources
DEV9/ATA/ATA_State.cpp
DEV9/ATA/ATA_Transfer.cpp
DEV9/ATA/HddCreate.cpp
DEV9/InternalServers/ARP_Logger.cpp
DEV9/InternalServers/DHCP_Logger.cpp
DEV9/InternalServers/DHCP_Server.cpp
DEV9/InternalServers/DNS_Logger.cpp
@ -325,6 +326,7 @@ set(pcsx2DEV9Headers
DEV9/ATA/ATA.h
DEV9/ATA/HddCreate.h
DEV9/DEV9.h
DEV9/InternalServers/ARP_Logger.h
DEV9/InternalServers/DHCP_Logger.h
DEV9/InternalServers/DHCP_Server.h
DEV9/InternalServers/DNS_Logger.h

View File

@ -0,0 +1,92 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+
#include "ARP_Logger.h"
#include "DEV9/PacketReader/EthernetFrame.h"
#include "common/Console.h"
using namespace PacketReader;
using namespace PacketReader::ARP;
namespace InternalServers
{
void ARP_Logger::InspectRecv(Payload* payload)
{
ARP_Packet* arp = static_cast<ARP_Packet*>(payload);
LogPacket(arp);
}
void ARP_Logger::InspectSend(Payload* payload)
{
ARP_Packet* arp = static_cast<ARP_Packet*>(payload);
LogPacket(arp);
}
std::string ARP_Logger::ArrayToString(const std::unique_ptr<u8[]>& data, int length)
{
std::string str;
if (length != 0)
{
str.reserve(length * 4);
for (size_t i = 0; i < length; i++)
str += std::to_string(data[i]) + ":";
str.pop_back();
} //else leave string empty
return str;
}
const char* ARP_Logger::HardwareTypeToString(u8 op)
{
switch (op)
{
case 1:
return "Ethernet";
case 6:
return "IEEE 802";
default:
return "Unknown";
}
}
const char* ARP_Logger::ProtocolToString(u16 protocol)
{
switch (protocol)
{
case static_cast<u16>(EtherType::IPv4):
return "IPv4";
case static_cast<u16>(EtherType::ARP):
return "ARP";
default:
return "Unknown";
}
}
const char* ARP_Logger::OperationToString(u16 op)
{
switch (op)
{
case 1:
return "Request";
case 2:
return "Reply";
default:
return "Unknown";
}
}
void ARP_Logger::LogPacket(ARP_Packet* arp)
{
Console.WriteLn("DEV9: ARP: Hardware Type %s (%i)", HardwareTypeToString(arp->hardwareType), arp->hardwareType);
Console.WriteLn("DEV9: ARP: Protocol %s (%i)", ProtocolToString(arp->protocol), arp->protocol);
Console.WriteLn("DEV9: ARP: Operation %s (%i)", OperationToString(arp->op), arp->op);
Console.WriteLn("DEV9: ARP: Hardware Length %i", arp->hardwareAddressLength);
Console.WriteLn("DEV9: ARP: Protocol Length %i", arp->protocolAddressLength);
Console.WriteLn("DEV9: ARP: Sender Hardware Address %s", ArrayToString(arp->senderHardwareAddress, arp->hardwareAddressLength).c_str());
Console.WriteLn("DEV9: ARP: Sender Protocol Address %s", ArrayToString(arp->senderProtocolAddress, arp->protocolAddressLength).c_str());
Console.WriteLn("DEV9: ARP: Target Hardware Address %s", ArrayToString(arp->targetHardwareAddress, arp->hardwareAddressLength).c_str());
Console.WriteLn("DEV9: ARP: Target Protocol Address %s", ArrayToString(arp->targetProtocolAddress, arp->protocolAddressLength).c_str());
}
} // namespace InternalServers

View File

@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+
#pragma once
#include "DEV9/PacketReader/Payload.h"
#include "DEV9/PacketReader/ARP/ARP_Packet.h"
namespace InternalServers
{
class ARP_Logger
{
public:
ARP_Logger(){};
//Expects a ARP_payload
void InspectRecv(PacketReader::Payload* payload);
//Expects a ARP_payload
void InspectSend(PacketReader::Payload* payload);
private:
std::string ArrayToString(const std::unique_ptr<u8[]>& data, int length);
const char* HardwareTypeToString(u8 op); // Same as DHCP
const char* ProtocolToString(u16 protocol);
const char* OperationToString(u16 op);
void LogPacket(PacketReader::ARP::ARP_Packet* payload);
};
} // namespace InternalServers

View File

@ -17,6 +17,7 @@
#include "sockets.h"
#include "PacketReader/EthernetFrame.h"
#include "PacketReader/ARP/ARP_Packet.h"
#include "PacketReader/IP/IP_Packet.h"
#include "PacketReader/IP/UDP/UDP_Packet.h"
@ -160,6 +161,7 @@ void TermNet()
}
using namespace PacketReader;
using namespace PacketReader::ARP;
using namespace PacketReader::IP;
using namespace PacketReader::IP::UDP;
@ -233,6 +235,13 @@ void NetAdapter::InspectSend(NetPacket* pkt)
}
}
}
if (frame.protocol == static_cast<u16>(EtherType::ARP))
{
Console.WriteLn("DEV9: ARP: Packet Sent");
PayloadPtr* payload = static_cast<PayloadPtr*>(frame.GetPayload());
ARP_Packet arppkt(payload->data, payload->GetLength());
arpLogger.InspectSend(&arppkt);
}
}
}
void NetAdapter::InspectRecv(NetPacket* pkt)
@ -265,6 +274,13 @@ void NetAdapter::InspectRecv(NetPacket* pkt)
}
}
}
if (frame.protocol == static_cast<u16>(EtherType::ARP))
{
Console.WriteLn("DEV9: ARP: Packet Received");
PayloadPtr* payload = static_cast<PayloadPtr*>(frame.GetPayload());
ARP_Packet arppkt(payload->data, payload->GetLength());
arpLogger.InspectRecv(&arppkt);
}
}
}

View File

@ -24,6 +24,7 @@
#include "PacketReader/MAC_Address.h"
#include "PacketReader/IP/IP_Address.h"
#include "InternalServers/ARP_Logger.h"
#include "InternalServers/DHCP_Logger.h"
#include "InternalServers/DHCP_Server.h"
#include "InternalServers/DNS_Logger.h"
@ -100,6 +101,7 @@ private:
bool dhcpOn = false;
protected:
InternalServers::ARP_Logger arpLogger;
InternalServers::DHCP_Logger dhcpLogger;
InternalServers::DHCP_Server dhcpServer = InternalServers::DHCP_Server([&] { InternalSignalReceived(); });
InternalServers::DNS_Logger dnsLogger;

View File

@ -170,6 +170,7 @@
<ClCompile Include="DEV9\ATA\HddCreate.cpp" />
<ClCompile Include="DEV9\DEV9.cpp" />
<ClCompile Include="DEV9\flash.cpp" />
<ClCompile Include="DEV9\InternalServers\ARP_Logger.cpp" />
<ClCompile Include="DEV9\InternalServers\DHCP_Logger.cpp" />
<ClCompile Include="DEV9\InternalServers\DHCP_Server.cpp" />
<ClCompile Include="DEV9\InternalServers\DNS_Logger.cpp" />
@ -607,6 +608,7 @@
<ClInclude Include="DEV9\ATA\ATA.h" />
<ClInclude Include="DEV9\ATA\HddCreate.h" />
<ClInclude Include="DEV9\DEV9.h" />
<ClInclude Include="DEV9\InternalServers\ARP_Logger.h" />
<ClInclude Include="DEV9\InternalServers\DHCP_Logger.h" />
<ClInclude Include="DEV9\InternalServers\DHCP_Server.h" />
<ClInclude Include="DEV9\InternalServers\DNS_Logger.h" />

View File

@ -872,6 +872,9 @@
<ClCompile Include="DEV9\flash.cpp">
<Filter>System\Ps2\DEV9</Filter>
</ClCompile>
<ClCompile Include="DEV9\InternalServers\ARP_Logger.cpp">
<Filter>System\Ps2\DEV9\InternalServers</Filter>
</ClCompile>
<ClCompile Include="DEV9\InternalServers\DHCP_Logger.cpp">
<Filter>System\Ps2\DEV9\InternalServers</Filter>
</ClCompile>
@ -1757,6 +1760,9 @@
<ClInclude Include="DEV9\DEV9.h">
<Filter>System\Ps2\DEV9</Filter>
</ClInclude>
<ClInclude Include="DEV9\InternalServers\ARP_Logger.h">
<Filter>System\Ps2\DEV9\InternalServers</Filter>
</ClInclude>
<ClInclude Include="DEV9\InternalServers\DHCP_Logger.h">
<Filter>System\Ps2\DEV9\InternalServers</Filter>
</ClInclude>