Skip to content

Commit

Permalink
Merge pull request #7 from LimiQS/patch-1
Browse files Browse the repository at this point in the history
Ensure we use big-endian
  • Loading branch information
cocowalla authored Jan 17, 2020
2 parents ca4fbd3 + 6896e3e commit 1e29a06
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/IPPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public IPPacket(byte[] data)

if (Enum.IsDefined(typeof(ProtocolsWithPort), this.Protocol))
{
this.SourcePort = BitConverter.ToUInt16(data, this.HeaderLength);
this.DestPort = BitConverter.ToUInt16(data, this.HeaderLength + 2);
// Ensure big-endian
this.SourcePort = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, this.HeaderLength));
this.DestPort = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, this.HeaderLength + 2));
}
}
}
Expand Down

0 comments on commit 1e29a06

Please sign in to comment.