Skip to content

Commit

Permalink
DEV9: Apply const within in PacketReader
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastRar authored and lightningterror committed Dec 7, 2024
1 parent a8a170e commit 5de1c60
Show file tree
Hide file tree
Showing 28 changed files with 316 additions and 316 deletions.
2 changes: 1 addition & 1 deletion pcsx2/DEV9/PacketReader/ARP/ARP_Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace PacketReader::ARP
{
}

ARP_Packet::ARP_Packet(u8* buffer, int bufferSize)
ARP_Packet::ARP_Packet(const u8* buffer, int bufferSize)
{
int offset = 0;

Expand Down
2 changes: 1 addition & 1 deletion pcsx2/DEV9/PacketReader/ARP/ARP_Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace PacketReader::ARP
std::unique_ptr<u8[]> targetProtocolAddress;

ARP_Packet(u8 hwAddrLen, u8 procAddrLen);
ARP_Packet(u8* buffer, int bufferSize);
ARP_Packet(const u8* buffer, int bufferSize);
ARP_Packet(const ARP_Packet&);

virtual int GetLength();
Expand Down
26 changes: 13 additions & 13 deletions pcsx2/DEV9/PacketReader/ARP/ARP_PacketEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,54 @@ namespace PacketReader::ARP
{
}

u16 ARP_PacketEditor::GetHardwareType()
u16 ARP_PacketEditor::GetHardwareType() const
{
return ntohs(*(u16*)&basePkt->data[0]);
}

u16 ARP_PacketEditor::GetProtocol()
u16 ARP_PacketEditor::GetProtocol() const
{
return ntohs(*(u16*)&basePkt->data[2]);
}

u8 ARP_PacketEditor::GetHardwareAddressLength()
u8 ARP_PacketEditor::GetHardwareAddressLength() const
{
return basePkt->data[4];
}
u8 ARP_PacketEditor::GetProtocolAddressLength()
u8 ARP_PacketEditor::GetProtocolAddressLength() const
{
return basePkt->data[5];
}

u16 ARP_PacketEditor::GetOp()
u16 ARP_PacketEditor::GetOp() const
{
return ntohs(*(u16*)&basePkt->data[6]);
}

u8* ARP_PacketEditor::SenderHardwareAddress()
u8* ARP_PacketEditor::SenderHardwareAddress() const
{
return &basePkt->data[8];
}

u8* ARP_PacketEditor::SenderProtocolAddress()
u8* ARP_PacketEditor::SenderProtocolAddress() const
{
int offset = 8 + GetHardwareAddressLength();
const int offset = 8 + GetHardwareAddressLength();
return &basePkt->data[offset];
}

u8* ARP_PacketEditor::TargetHardwareAddress()
u8* ARP_PacketEditor::TargetHardwareAddress() const
{
int offset = 8 + GetHardwareAddressLength() + GetProtocolAddressLength();
const int offset = 8 + GetHardwareAddressLength() + GetProtocolAddressLength();
return &basePkt->data[offset];
}

u8* ARP_PacketEditor::TargetProtocolAddress()
u8* ARP_PacketEditor::TargetProtocolAddress() const
{
int offset = 8 + 2 * GetHardwareAddressLength() + GetProtocolAddressLength();
const int offset = 8 + 2 * GetHardwareAddressLength() + GetProtocolAddressLength();
return &basePkt->data[offset];
}

int ARP_PacketEditor::GetLength()
int ARP_PacketEditor::GetLength() const
{
return 8 + 2 * GetHardwareAddressLength() + 2 * GetProtocolAddressLength();
}
Expand Down
20 changes: 10 additions & 10 deletions pcsx2/DEV9/PacketReader/ARP/ARP_PacketEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ namespace PacketReader::ARP
public:
ARP_PacketEditor(PayloadPtrEditor* pkt);

u16 GetHardwareType();
u16 GetProtocol();
u8 GetHardwareAddressLength();
u8 GetProtocolAddressLength();
u16 GetOp();
u16 GetHardwareType() const;
u16 GetProtocol() const;
u8 GetHardwareAddressLength() const;
u8 GetProtocolAddressLength() const;
u16 GetOp() const;

u8* SenderHardwareAddress();
u8* SenderProtocolAddress();
u8* TargetHardwareAddress();
u8* TargetProtocolAddress();
u8* SenderHardwareAddress() const;
u8* SenderProtocolAddress() const;
u8* TargetHardwareAddress() const;
u8* TargetProtocolAddress() const;

int GetLength();
int GetLength() const;
};
} // namespace PacketReader::ARP
8 changes: 4 additions & 4 deletions pcsx2/DEV9/PacketReader/EthernetFrameEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace PacketReader
payload = std::make_unique<PayloadPtrEditor>((u8*)&basePkt->buffer[14], pkt->size - headerLength);
}

MAC_Address EthernetFrameEditor::GetDestinationMAC()
MAC_Address EthernetFrameEditor::GetDestinationMAC() const
{
return *(MAC_Address*)&basePkt->buffer[0];
}
Expand All @@ -31,7 +31,7 @@ namespace PacketReader
*(MAC_Address*)&basePkt->buffer[0] = value;
}

MAC_Address EthernetFrameEditor::GetSourceMAC()
MAC_Address EthernetFrameEditor::GetSourceMAC() const
{
return *(MAC_Address*)&basePkt->buffer[6];
}
Expand All @@ -40,12 +40,12 @@ namespace PacketReader
*(MAC_Address*)&basePkt->buffer[6] = value;
}

u16 EthernetFrameEditor::GetProtocol()
u16 EthernetFrameEditor::GetProtocol() const
{
return ntohs(*(u16*)&basePkt->buffer[12]);
}

PayloadPtrEditor* EthernetFrameEditor::GetPayload()
PayloadPtrEditor* EthernetFrameEditor::GetPayload() const
{
return payload.get();
}
Expand Down
8 changes: 4 additions & 4 deletions pcsx2/DEV9/PacketReader/EthernetFrameEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ namespace PacketReader
public:
EthernetFrameEditor(NetPacket* pkt);

MAC_Address GetDestinationMAC();
MAC_Address GetDestinationMAC() const;
void SetDestinationMAC(MAC_Address value);
MAC_Address GetSourceMAC();
MAC_Address GetSourceMAC() const;
void SetSourceMAC(MAC_Address value);

u16 GetProtocol();
u16 GetProtocol() const;

PayloadPtrEditor* GetPayload();
PayloadPtrEditor* GetPayload() const;
};
} // namespace PacketReader
6 changes: 3 additions & 3 deletions pcsx2/DEV9/PacketReader/IP/ICMP/ICMP_Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace PacketReader::IP::ICMP
memcpy(headerData, original.headerData, 4);
}

Payload* ICMP_Packet::GetPayload()
Payload* ICMP_Packet::GetPayload() const
{
return payload.get();
}
Expand All @@ -59,7 +59,7 @@ namespace PacketReader::IP::ICMP
return new ICMP_Packet(*this);
}

u8 ICMP_Packet::GetProtocol()
u8 ICMP_Packet::GetProtocol() const
{
return (u8)protocol;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ namespace PacketReader::IP::ICMP
if (counter != pHeaderLen)
NetLib::WriteByte08(segment, &counter, 0);

u16 csumCal = IP_Packet::InternetChecksum(segment, pHeaderLen);
const u16 csumCal = IP_Packet::InternetChecksum(segment, pHeaderLen);
delete[] segment;

return (csumCal == 0);
Expand Down
4 changes: 2 additions & 2 deletions pcsx2/DEV9/PacketReader/IP/ICMP/ICMP_Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ namespace PacketReader::IP::ICMP
ICMP_Packet(const u8* buffer, int bufferSize);
ICMP_Packet(const ICMP_Packet&);

Payload* GetPayload();
Payload* GetPayload() const;

virtual int GetLength();
virtual void WriteBytes(u8* buffer, int* offset);
virtual ICMP_Packet* Clone() const;

virtual u8 GetProtocol();
virtual u8 GetProtocol() const;

virtual bool VerifyChecksum(IP_Address srcIP, IP_Address dstIP);
virtual void CalculateChecksum(IP_Address srcIP, IP_Address dstIP);
Expand Down
14 changes: 7 additions & 7 deletions pcsx2/DEV9/PacketReader/IP/IP_Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@

namespace PacketReader::IP
{
bool IPOption::IsCopyOnFragment()
bool IPOption::IsCopyOnFragment() const
{
return ((GetCode() & (1 << 0x7)) != 0);
}
u8 IPOption::GetClass()
u8 IPOption::GetClass() const
{
return (GetCode() >> 5) & 0x3;
}
u8 IPOption::GetNumber()
u8 IPOption::GetNumber() const
{
return GetCode() & 0x1F;
}

IPopUnk::IPopUnk(u8* data, int offset)
IPopUnk::IPopUnk(const u8* data, int offset)
{
NetLib::ReadByte08(data, &offset, &code);
NetLib::ReadByte08(data, &offset, &length);

value.resize(length - 2);
NetLib::ReadByteArray(data, &offset, length - 2, &value[0]);
}
void IPopUnk::WriteBytes(u8* buffer, int* offset)
void IPopUnk::WriteBytes(u8* buffer, int* offset) const
{
NetLib::WriteByte08(buffer, offset, code);
NetLib::WriteByte08(buffer, offset, length);
Expand All @@ -38,12 +38,12 @@ namespace PacketReader::IP
: value{parValue}
{
}
IPopRouterAlert::IPopRouterAlert(u8* data, int offset)
IPopRouterAlert::IPopRouterAlert(const u8* data, int offset)
{
offset += 2;
NetLib::ReadUInt16(data, &offset, &value);
}
void IPopRouterAlert::WriteBytes(u8* buffer, int* offset)
void IPopRouterAlert::WriteBytes(u8* buffer, int* offset) const
{
NetLib::WriteByte08(buffer, offset, GetCode());
NetLib::WriteByte08(buffer, offset, GetLength());
Expand Down
34 changes: 17 additions & 17 deletions pcsx2/DEV9/PacketReader/IP/IP_Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ namespace PacketReader::IP
class BaseOption
{
public:
virtual u8 GetLength() = 0;
virtual u8 GetCode() = 0;
virtual void WriteBytes(u8* buffer, int* offset) = 0;
virtual u8 GetLength() const = 0;
virtual u8 GetCode() const = 0;
virtual void WriteBytes(u8* buffer, int* offset) const = 0;
virtual BaseOption* Clone() const = 0;
virtual ~BaseOption() {}
};

class IPOption : public BaseOption
{
public:
bool IsCopyOnFragment();
u8 GetClass(); //0 = control, 2 = debugging and measurement
u8 GetNumber();
bool IsCopyOnFragment() const;
u8 GetClass() const; //0 = control, 2 = debugging and measurement
u8 GetNumber() const;
virtual IPOption* Clone() const = 0;
};

Expand All @@ -35,12 +35,12 @@ namespace PacketReader::IP
std::vector<u8> value;

public:
IPopUnk(u8* data, int offset);
IPopUnk(const u8* data, int offset);

virtual u8 GetLength() { return length; }
virtual u8 GetCode() { return code; }
virtual u8 GetLength() const { return length; }
virtual u8 GetCode() const { return code; }

void WriteBytes(u8* buffer, int* offset);
void WriteBytes(u8* buffer, int* offset) const;

virtual IPopUnk* Clone() const
{
Expand All @@ -51,10 +51,10 @@ namespace PacketReader::IP
class IPopNOP : public IPOption
{
public:
virtual u8 GetLength() { return 1; }
virtual u8 GetCode() { return 1; }
virtual u8 GetLength() const { return 1; }
virtual u8 GetCode() const { return 1; }

virtual void WriteBytes(u8* buffer, int* offset)
virtual void WriteBytes(u8* buffer, int* offset) const
{
buffer[*offset] = GetCode();
(*offset)++;
Expand All @@ -73,12 +73,12 @@ namespace PacketReader::IP
u16 value;

IPopRouterAlert(u16 parValue);
IPopRouterAlert(u8* data, int offset);
IPopRouterAlert(const u8* data, int offset);

virtual u8 GetLength() { return 4; }
virtual u8 GetCode() { return 148; }
virtual u8 GetLength() const { return 4; }
virtual u8 GetCode() const { return 148; }

virtual void WriteBytes(u8* buffer, int* offset);
virtual void WriteBytes(u8* buffer, int* offset) const;

virtual IPopRouterAlert* Clone() const
{
Expand Down
Loading

0 comments on commit 5de1c60

Please sign in to comment.