コード例 #1
0
        public unsafe override IPEndPoint [] GetActiveUdpListeners()
        {
            List <IPEndPoint> list = new List <IPEndPoint> ();

            byte [] bytes4 = null;
            int     size4  = 0;

            GetUdpTable(null, ref size4, true);              // get size
            bytes4 = new byte [size4];
            GetUdpTable(bytes4, ref size4, true);            // get list

            int structSize4 = Marshal.SizeOf(typeof(Win32_MIB_UDPROW));

            fixed(byte *ptr = bytes4)
            {
                int count = Marshal.ReadInt32((IntPtr)ptr);

                for (int i = 0; i < count; i++)
                {
                    Win32_MIB_UDPROW row = new Win32_MIB_UDPROW();
                    Marshal.PtrToStructure((IntPtr)(ptr + i * structSize4 + 4), row);
                    list.Add(row.LocalEndPoint);
                }
            }

            if (Environment.OSVersion.Version.Major >= 6)               // Vista
            {
                byte [] bytes6 = null;
                int     size6  = 0;
                GetUdp6Table(null, ref size6, true);                  // get size
                bytes6 = new byte [size6];
                GetUdp6Table(bytes6, ref size6, true);                // get list

                int structSize6 = Marshal.SizeOf(typeof(Win32_MIB_UDP6ROW));

                fixed(byte *ptr = bytes6)
                {
                    int count = Marshal.ReadInt32((IntPtr)ptr);

                    for (int i = 0; i < count; i++)
                    {
                        Win32_MIB_UDP6ROW row = new Win32_MIB_UDP6ROW();
                        Marshal.PtrToStructure((IntPtr)(ptr + i * structSize6 + 4), row);
                        list.Add(row.LocalEndPoint);
                    }
                }
            }

            return(list.ToArray());
        }
コード例 #2
0
        public unsafe override IPEndPoint[] GetActiveUdpListeners()
        {
            //IL_004c: Incompatible stack types: I vs Ref
            //IL_0109: Incompatible stack types: I vs Ref
            List <IPEndPoint> list = new List <IPEndPoint>();

            byte[] array   = null;
            int    pdwSize = 0;

            GetUdpTable(null, ref pdwSize, bOrder: true);
            array = new byte[pdwSize];
            GetUdpTable(array, ref pdwSize, bOrder: true);
            int num = Marshal.SizeOf(typeof(Win32_MIB_UDPROW));

            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_UDPROW win32_MIB_UDPROW = new Win32_MIB_UDPROW();
                    Marshal.PtrToStructure((IntPtr)(void *)(ptr + i * num + 4), win32_MIB_UDPROW);
                    list.Add(win32_MIB_UDPROW.LocalEndPoint);
                }
            }

            if (Environment.OSVersion.Version.Major >= 6)
            {
                byte[] array2      = null;
                int    SizePointer = 0;
                GetUdp6Table(null, ref SizePointer, Order: true);
                array2 = new byte[SizePointer];
                GetUdp6Table(array2, ref SizePointer, Order: true);
                int num3 = Marshal.SizeOf(typeof(Win32_MIB_UDP6ROW));
                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_UDP6ROW win32_MIB_UDP6ROW = new Win32_MIB_UDP6ROW();
                        Marshal.PtrToStructure((IntPtr)(void *)(ptr2 + j * num3 + 4), win32_MIB_UDP6ROW);
                        list.Add(win32_MIB_UDP6ROW.LocalEndPoint);
                    }
                }
            }
            return(list.ToArray());
        }
コード例 #3
0
ファイル: IPGlobalProperties.cs プロジェクト: tgiphil/mono
		public unsafe override IPEndPoint [] GetActiveUdpListeners ()
		{
			List<IPEndPoint> list = new List<IPEndPoint> ();

			byte [] bytes4 = null;
			int size4 = 0;
			GetUdpTable (null, ref size4, true); // get size
			bytes4 = new byte [size4];
			GetUdpTable (bytes4, ref size4, true); // get list

			int structSize4 = Marshal.SizeOf (typeof (Win32_MIB_UDPROW));

			fixed (byte* ptr = bytes4) {
				int count = Marshal.ReadInt32 ((IntPtr) ptr);
				for (int i = 0; i < count; i++) {
					Win32_MIB_UDPROW row = new Win32_MIB_UDPROW ();
					Marshal.PtrToStructure ((IntPtr) (ptr + i * structSize4 + 4), row);
					list.Add (row.LocalEndPoint);
				}
			}

			if (Environment.OSVersion.Version.Major >= 6) { // Vista
				byte [] bytes6 = null;
				int size6 = 0;
				GetUdp6Table (null, ref size6, true); // get size
				bytes6 = new byte [size6];
				GetUdp6Table (bytes6, ref size6, true); // get list

				int structSize6 = Marshal.SizeOf (typeof (Win32_MIB_UDP6ROW));

				fixed (byte* ptr = bytes6) {
					int count = Marshal.ReadInt32 ((IntPtr) ptr);
					for (int i = 0; i < count; i++) {
						Win32_MIB_UDP6ROW row = new Win32_MIB_UDP6ROW ();
						Marshal.PtrToStructure ((IntPtr) (ptr + i * structSize6 + 4), row);
						list.Add (row.LocalEndPoint);
					}
				}
			}

			return list.ToArray ();
		}