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

Fix a couple of endianness issues with plNetAddress #1500

Merged
merged 2 commits into from
Oct 13, 2023
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
6 changes: 4 additions & 2 deletions Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ ST::string plNetAddress::AsString() const

void plNetAddress::Read(hsStream * s)
{
fHost = s->ReadLE32();
// No endianness conversion here - fHost is always big-endian in memory and in the stream!
s->Read(sizeof(fHost), &fHost);
fPort = s->ReadLE16();

// Family is always kInet
Expand All @@ -97,7 +98,8 @@ void plNetAddress::Read(hsStream * s)

void plNetAddress::Write(hsStream * s)
{
s->WriteLE32(fHost);
// No endianness conversion here - fHost is always big-endian in memory and in the stream!
s->Write(sizeof(fHost), &fHost);
s->WriteLE16(fPort);

s->WriteLE16(static_cast<uint16_t>(Family::kInet));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ bool RecvMsg<Auth2Cli_ServerAddr>(const uint8_t in[], unsigned, void*)
hsLockGuard(s_critsect);
if (s_active) {
s_active->token = msg.token;
s_active->addr.SetHost(msg.srvAddr);
s_active->addr.SetHost(hsToBE32(msg.srvAddr));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing we need to byteswap here because the server is (incorrectly) sending the address in LE rather than network order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's "correct" in the sense that it's consistent with the rest of the auth server protocol - IPv4 addresses are treated as integers, so they are transmitted little-endian. It's definitely a weird choice though.

An extra twist is that the NetCli receive machinery also does an implicit endianness conversion before the message gets here. So the IPv4 address is received little-endian, then implicitly converted to host byte order, and finally explicitly converted to big-endian. Fun!


LogMsg(kLogPerf, "SrvAuth addr: {}", s_active->addr.GetHostString());
}
Expand Down