Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV9: Add const to PacketReader #12062

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 14 additions & 14 deletions pcsx2/DEV9/PacketReader/ARP/ARP_PacketEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,59 @@

namespace PacketReader::ARP
{
ARP_PacketEditor::ARP_PacketEditor(PayloadPtr* pkt)
ARP_PacketEditor::ARP_PacketEditor(PayloadPtrEditor* pkt)
: basePkt{pkt}
{
}

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
24 changes: 12 additions & 12 deletions pcsx2/DEV9/PacketReader/ARP/ARP_PacketEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ namespace PacketReader::ARP
class ARP_PacketEditor
{
private:
PayloadPtr* basePkt;
PayloadPtrEditor* basePkt;

public:
ARP_PacketEditor(PayloadPtr* pkt);
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
10 changes: 5 additions & 5 deletions pcsx2/DEV9/PacketReader/EthernetFrameEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace PacketReader
//Note: we don't have to worry about the Ethernet Frame CRC as it is not included in the packet
//Note: We don't support tagged frames

payload = std::make_unique<PayloadPtr>((u8*)&basePkt->buffer[14], pkt->size - headerLength);
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]);
}

PayloadPtr* EthernetFrameEditor::GetPayload()
PayloadPtrEditor* EthernetFrameEditor::GetPayload() const
{
return payload.get();
}
Expand Down
10 changes: 5 additions & 5 deletions pcsx2/DEV9/PacketReader/EthernetFrameEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ namespace PacketReader
//Length
private:
NetPacket* basePkt;
std::unique_ptr<PayloadPtr> payload;
std::unique_ptr<PayloadPtrEditor> payload;

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;

PayloadPtr* GetPayload();
PayloadPtrEditor* GetPayload() const;
};
} // namespace PacketReader
8 changes: 4 additions & 4 deletions pcsx2/DEV9/PacketReader/IP/ICMP/ICMP_Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace PacketReader::IP::ICMP
: payload{data}
{
}
ICMP_Packet::ICMP_Packet(u8* buffer, int bufferSize)
ICMP_Packet::ICMP_Packet(const u8* buffer, int bufferSize)
{
int offset = 0;
//Bits 0-31
Expand All @@ -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
6 changes: 3 additions & 3 deletions pcsx2/DEV9/PacketReader/IP/ICMP/ICMP_Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ namespace PacketReader::IP::ICMP
public:
//Takes ownership of payload
ICMP_Packet(Payload* data);
ICMP_Packet(u8* buffer, int bufferSize);
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
Loading