System.Net.NetworkInformation.Win32NetworkInterface2.GetAdaptersAddresses C# (CSharp) Method

GetAdaptersAddresses() static private method

static private GetAdaptersAddresses ( ) : System.Net.NetworkInformation.Win32_IP_ADAPTER_ADDRESSES[]
return System.Net.NetworkInformation.Win32_IP_ADAPTER_ADDRESSES[]
		unsafe static Win32_IP_ADAPTER_ADDRESSES [] GetAdaptersAddresses ()
		{
			byte [] bytes = null;
			int len = 0;
			GetAdaptersAddresses (0, 0, IntPtr.Zero, bytes, ref len);
			bytes = new byte [len];
			int ret = GetAdaptersAddresses (0, 0, IntPtr.Zero, bytes, ref len);
			if (ret != 0)
				throw new NetworkInformationException (ret);

			List<Win32_IP_ADAPTER_ADDRESSES> l = new List<Win32_IP_ADAPTER_ADDRESSES> ();
			fixed (byte* ptr = bytes) {
				Win32_IP_ADAPTER_ADDRESSES info;
				for (IntPtr p = (IntPtr) ptr; p != IntPtr.Zero; p = info.Next) {
					info = new Win32_IP_ADAPTER_ADDRESSES ();
					Marshal.PtrToStructure (p, info);
					l.Add (info);
				}
			}
			return l.ToArray ();
		}

Same methods

Win32NetworkInterface2::GetAdaptersAddresses ( uint family, uint flags, IntPtr reserved, byte info, int &size ) : int

Usage Example

        private unsafe static Win32_IP_ADAPTER_ADDRESSES[] GetAdaptersAddresses()
        {
            byte[] array = null;
            int    num   = 0;

            Win32NetworkInterface2.GetAdaptersAddresses(0u, 0u, IntPtr.Zero, array, ref num);
            array = new byte[num];
            int adaptersAddresses = Win32NetworkInterface2.GetAdaptersAddresses(0u, 0u, IntPtr.Zero, array, ref num);

            if (adaptersAddresses != 0)
            {
                throw new NetworkInformationException(adaptersAddresses);
            }
            List <Win32_IP_ADAPTER_ADDRESSES> list = new List <Win32_IP_ADAPTER_ADDRESSES>();

            fixed(byte *value = ref (array != null && array.Length != 0)?ref array[0] : ref *null)
            {
                IntPtr intPtr = (IntPtr)((void *)value);

                while (intPtr != IntPtr.Zero)
                {
                    Win32_IP_ADAPTER_ADDRESSES win32_IP_ADAPTER_ADDRESSES = new Win32_IP_ADAPTER_ADDRESSES();
                    Marshal.PtrToStructure(intPtr, win32_IP_ADAPTER_ADDRESSES);
                    list.Add(win32_IP_ADAPTER_ADDRESSES);
                    intPtr = win32_IP_ADAPTER_ADDRESSES.Next;
                }
            }

            return(list.ToArray());
        }
All Usage Examples Of System.Net.NetworkInformation.Win32NetworkInterface2::GetAdaptersAddresses