diff --git a/src/IPPacket.cs b/src/IPPacket.cs index 3cb2cec..7a9ac8e 100644 --- a/src/IPPacket.cs +++ b/src/IPPacket.cs @@ -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)); } } }