// FIXME: it might be getting wrong table. I'm getting // different results from .NET 2.0. unsafe void FillTcpTable(out List <Win32_MIB_TCPROW> tab4, out List <Win32_MIB_TCP6ROW> tab6) { tab4 = new List <Win32_MIB_TCPROW> (); int size4 = 0; GetTcpTable(null, ref size4, true); // get size byte [] bytes4 = new byte [size4]; GetTcpTable(bytes4, ref size4, true); // get list int structSize4 = Marshal.SizeOf(typeof(Win32_MIB_TCPROW)); fixed(byte *ptr = bytes4) { int count = Marshal.ReadInt32((IntPtr)ptr); for (int i = 0; i < count; i++) { Win32_MIB_TCPROW row = new Win32_MIB_TCPROW(); Marshal.PtrToStructure((IntPtr)(ptr + i * structSize4 + 4), row); tab4.Add(row); } } tab6 = new List <Win32_MIB_TCP6ROW> (); if (Environment.OSVersion.Version.Major >= 6) // Vista { int size6 = 0; GetTcp6Table(null, ref size6, true); // get size byte [] bytes6 = new byte [size6]; GetTcp6Table(bytes6, ref size6, true); // get list int structSize6 = Marshal.SizeOf(typeof(Win32_MIB_TCP6ROW)); fixed(byte *ptr = bytes6) { int count = Marshal.ReadInt32((IntPtr)ptr); for (int i = 0; i < count; i++) { Win32_MIB_TCP6ROW row = new Win32_MIB_TCP6ROW(); Marshal.PtrToStructure((IntPtr)(ptr + i * structSize6 + 4), row); tab6.Add(row); } } } }
private unsafe void FillTcpTable(out List <Win32_MIB_TCPROW> tab4, out List <Win32_MIB_TCP6ROW> tab6) { //IL_004b: Incompatible stack types: I vs Ref //IL_0104: Incompatible stack types: I vs Ref tab4 = new List <Win32_MIB_TCPROW>(); int pdwSize = 0; GetTcpTable(null, ref pdwSize, bOrder: true); byte[] array = new byte[pdwSize]; GetTcpTable(array, ref pdwSize, bOrder: true); int num = Marshal.SizeOf(typeof(Win32_MIB_TCPROW)); fixed(byte *ptr = &((array != null && array.Length != 0) ? ref array[0] : ref *(byte *)null)) { int num2 = Marshal.ReadInt32((IntPtr)(void *)ptr); for (int i = 0; i < num2; i++) { Win32_MIB_TCPROW win32_MIB_TCPROW = new Win32_MIB_TCPROW(); Marshal.PtrToStructure((IntPtr)(void *)(ptr + i * num + 4), win32_MIB_TCPROW); tab4.Add(win32_MIB_TCPROW); } } tab6 = new List <Win32_MIB_TCP6ROW>(); if (Environment.OSVersion.Version.Major >= 6) { int SizePointer = 0; GetTcp6Table(null, ref SizePointer, Order: true); byte[] array2 = new byte[SizePointer]; GetTcp6Table(array2, ref SizePointer, Order: true); int num3 = Marshal.SizeOf(typeof(Win32_MIB_TCP6ROW)); fixed(byte *ptr2 = &((array2 != null && array2.Length != 0) ? ref array2[0] : ref *(byte *)null)) { int num4 = Marshal.ReadInt32((IntPtr)(void *)ptr2); for (int j = 0; j < num4; j++) { Win32_MIB_TCP6ROW win32_MIB_TCP6ROW = new Win32_MIB_TCP6ROW(); Marshal.PtrToStructure((IntPtr)(void *)(ptr2 + j * num3 + 4), win32_MIB_TCP6ROW); tab6.Add(win32_MIB_TCP6ROW); } } } }
// FIXME: it might be getting wrong table. I'm getting // different results from .NET 2.0. unsafe void FillTcpTable (out List<Win32_MIB_TCPROW> tab4, out List<Win32_MIB_TCP6ROW> tab6) { tab4 = new List<Win32_MIB_TCPROW> (); int size4 = 0; GetTcpTable (null, ref size4, true); // get size byte [] bytes4 = new byte [size4]; GetTcpTable (bytes4, ref size4, true); // get list int structSize4 = Marshal.SizeOf (typeof (Win32_MIB_TCPROW)); fixed (byte* ptr = bytes4) { int count = Marshal.ReadInt32 ((IntPtr) ptr); for (int i = 0; i < count; i++) { Win32_MIB_TCPROW row = new Win32_MIB_TCPROW (); Marshal.PtrToStructure ((IntPtr) (ptr + i * structSize4 + 4), row); tab4.Add (row); } } tab6 = new List<Win32_MIB_TCP6ROW> (); if (Environment.OSVersion.Version.Major >= 6) { // Vista int size6 = 0; GetTcp6Table (null, ref size6, true); // get size byte [] bytes6 = new byte [size6]; GetTcp6Table (bytes6, ref size6, true); // get list int structSize6 = Marshal.SizeOf (typeof (Win32_MIB_TCP6ROW)); fixed (byte* ptr = bytes6) { int count = Marshal.ReadInt32 ((IntPtr) ptr); for (int i = 0; i < count; i++) { Win32_MIB_TCP6ROW row = new Win32_MIB_TCP6ROW (); Marshal.PtrToStructure ((IntPtr) (ptr + i * structSize6 + 4), row); tab6.Add (row); } } } }