System.Net.NetworkInformation.Win32IPGlobalProperties.GetTcpTable C# (CSharp) Method

GetTcpTable() private method

private GetTcpTable ( byte pTcpTable, int &pdwSize, bool bOrder ) : int
pTcpTable byte
pdwSize int
bOrder bool
return int
		static extern int GetTcpTable (byte [] pTcpTable, ref int pdwSize, bool bOrder);

Usage Example

Beispiel #1
0
        private unsafe void FillTcpTable(out List <Win32IPGlobalProperties.Win32_MIB_TCPROW> tab4, out List <Win32IPGlobalProperties.Win32_MIB_TCP6ROW> tab6)
        {
            tab4 = new List <Win32IPGlobalProperties.Win32_MIB_TCPROW>();
            int num = 0;

            Win32IPGlobalProperties.GetTcpTable(null, ref num, true);
            byte[] array = new byte[num];
            Win32IPGlobalProperties.GetTcpTable(array, ref num, true);
            int num2 = Marshal.SizeOf(typeof(Win32IPGlobalProperties.Win32_MIB_TCPROW));

            fixed(byte *ptr = ref (array != null && array.Length != 0)?ref array[0] : ref *null)
            {
                int num3 = Marshal.ReadInt32((IntPtr)((void *)ptr));

                for (int i = 0; i < num3; i++)
                {
                    Win32IPGlobalProperties.Win32_MIB_TCPROW win32_MIB_TCPROW = new Win32IPGlobalProperties.Win32_MIB_TCPROW();
                    Marshal.PtrToStructure((IntPtr)((void *)(ptr + i * num2 + 4)), win32_MIB_TCPROW);
                    tab4.Add(win32_MIB_TCPROW);
                }
            }

            tab6 = new List <Win32IPGlobalProperties.Win32_MIB_TCP6ROW>();
            if (Environment.OSVersion.Version.Major >= 6)
            {
                int num4 = 0;
                Win32IPGlobalProperties.GetTcp6Table(null, ref num4, true);
                byte[] array2 = new byte[num4];
                Win32IPGlobalProperties.GetTcp6Table(array2, ref num4, true);
                int num5 = Marshal.SizeOf(typeof(Win32IPGlobalProperties.Win32_MIB_TCP6ROW));
                fixed(byte *ptr2 = ref (array2 != null && array2.Length != 0)?ref array2[0] : ref *null)
                {
                    int num6 = Marshal.ReadInt32((IntPtr)((void *)ptr2));

                    for (int j = 0; j < num6; j++)
                    {
                        Win32IPGlobalProperties.Win32_MIB_TCP6ROW win32_MIB_TCP6ROW = new Win32IPGlobalProperties.Win32_MIB_TCP6ROW();
                        Marshal.PtrToStructure((IntPtr)((void *)(ptr2 + j * num5 + 4)), win32_MIB_TCP6ROW);
                        tab6.Add(win32_MIB_TCP6ROW);
                    }
                }
            }
        }