Skip to content

Commit d8025cb

Browse files
committed
Swap bytes for tcp port number (case 1165578)
1 parent 0295d49 commit d8025cb

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

mcs/class/System/System.Net.NetworkInformation/IPGlobalProperties.cs

+10-12
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,6 @@ class Win32IPGlobalProperties : IPGlobalProperties
384384
public const int AF_INET = 2;
385385
public const int AF_INET6 = 23;
386386

387-
// FIXME: it might be getting wrong table. I'm getting
388-
// different results from .NET 2.0.
389387
unsafe void FillTcpTable (out List<Win32_MIB_TCPROW> tab4, out List<Win32_MIB_TCP6ROW> tab6)
390388
{
391389
tab4 = new List<Win32_MIB_TCPROW> ();
@@ -651,16 +649,16 @@ class Win32_MIB_TCPROW
651649
{
652650
public TcpState State;
653651
public uint LocalAddr;
654-
public int LocalPort;
652+
public uint LocalPort;
655653
public uint RemoteAddr;
656-
public int RemotePort;
654+
public uint RemotePort;
657655

658656
public IPEndPoint LocalEndPoint {
659-
get { return new IPEndPoint (LocalAddr, LocalPort); }
657+
get { return new IPEndPoint (LocalAddr, ntohs((ushort)LocalPort)); }
660658
}
661659

662660
public IPEndPoint RemoteEndPoint {
663-
get { return new IPEndPoint (RemoteAddr, RemotePort); }
661+
get { return new IPEndPoint (RemoteAddr, ntohs((ushort)RemotePort)); }
664662
}
665663

666664
public TcpConnectionInformation TcpInfo {
@@ -674,17 +672,17 @@ class Win32_MIB_TCP6ROW
674672
public TcpState State;
675673
public Win32_IN6_ADDR LocalAddr;
676674
public uint LocalScopeId;
677-
public int LocalPort;
675+
public uint LocalPort;
678676
public Win32_IN6_ADDR RemoteAddr;
679677
public uint RemoteScopeId;
680-
public int RemotePort;
678+
public uint RemotePort;
681679

682680
public IPEndPoint LocalEndPoint {
683-
get { return new IPEndPoint (new IPAddress (LocalAddr.Bytes, LocalScopeId), LocalPort); }
681+
get { return new IPEndPoint (new IPAddress (LocalAddr.Bytes, LocalScopeId), ntohs((ushort)LocalPort)); }
684682
}
685683

686684
public IPEndPoint RemoteEndPoint {
687-
get { return new IPEndPoint (new IPAddress (RemoteAddr.Bytes, RemoteScopeId), RemotePort); }
685+
get { return new IPEndPoint (new IPAddress (RemoteAddr.Bytes, RemoteScopeId), ntohs((ushort)RemotePort)); }
688686
}
689687

690688
public TcpConnectionInformation TcpInfo {
@@ -708,10 +706,10 @@ class Win32_MIB_UDP6ROW
708706
{
709707
public Win32_IN6_ADDR LocalAddr;
710708
public uint LocalScopeId;
711-
public int LocalPort;
709+
public uint LocalPort;
712710

713711
public IPEndPoint LocalEndPoint {
714-
get { return new IPEndPoint (new IPAddress (LocalAddr.Bytes, LocalScopeId), LocalPort); }
712+
get { return new IPEndPoint (new IPAddress (LocalAddr.Bytes, LocalScopeId), ntohs((ushort)LocalPort)); }
715713
}
716714
}
717715
}

0 commit comments

Comments
 (0)