private unsafe UnicastIPAddressInformationCollection GetUnicastAddresses()
        {
            UnicastIPAddressInformationCollection collection = new UnicastIPAddressInformationCollection();

            Interop.Sys.EnumerateInterfaceAddresses(
                (name, ipAddressInfo, netmaskInfo) =>
            {
                IPAddress ipAddress = IPAddressUtil.GetIPAddressFromNativeInfo(ipAddressInfo);
                if (!IPAddressUtil.IsMulticast(ipAddress))
                {
                    IPAddress netMaskAddress = IPAddressUtil.GetIPAddressFromNativeInfo(netmaskInfo);
                    collection.InternalAdd(new UnixUnicastIPAddressInformation(ipAddress, netMaskAddress));
                }
            },
                (name, ipAddressInfo, scopeId) =>
            {
                IPAddress ipAddress = IPAddressUtil.GetIPAddressFromNativeInfo(ipAddressInfo);
                if (!IPAddressUtil.IsMulticast(ipAddress))
                {
                    collection.InternalAdd(new UnixUnicastIPAddressInformation(ipAddress, IPAddress.Any));
                }
            },
                // Ignore link-layer addresses that are discovered; don't create a callback.
                null);

            return(collection);
        }
Exemplo n.º 2
0
        public unsafe override UnicastIPAddressInformationCollection GetUnicastAddresses()
        {
            UnicastIPAddressInformationCollection collection = new UnicastIPAddressInformationCollection();

            Interop.Sys.EnumerateInterfaceAddresses(
                (name, ipAddressInfo) =>
            {
                IPAddress ipAddress = IPAddressUtil.GetIPAddressFromNativeInfo(ipAddressInfo);
                if (!IPAddressUtil.IsMulticast(ipAddress))
                {
                    collection.InternalAdd(new UnixUnicastIPAddressInformation(ipAddress, ipAddressInfo->PrefixLength));
                }
            },
                (name, ipAddressInfo, scopeId) =>
            {
                IPAddress ipAddress = IPAddressUtil.GetIPAddressFromNativeInfo(ipAddressInfo);
                if (!IPAddressUtil.IsMulticast(ipAddress))
                {
                    collection.InternalAdd(new UnixUnicastIPAddressInformation(ipAddress, ipAddressInfo->PrefixLength));
                }
            },
                // Ignore link-layer addresses that are discovered; don't create a callback.
                null);

            return(collection);
        }
Exemplo n.º 3
0
        private static UnicastIPAddressInformationCollection GetUnicastAddresses(UnixNetworkInterface uni)
        {
            var collection = new UnicastIPAddressInformationCollection();

            foreach (UnixUnicastIPAddressInformation address in uni.UnicastAddress)
            {
                collection.InternalAdd(address);
            }

            return(collection);
        }
Exemplo n.º 4
0
        static UnicastIPAddressInformationCollection Win32FromUnicast(IntPtr ptr)
        {
            UnicastIPAddressInformationCollection c = new UnicastIPAddressInformationCollection();
            Win32_IP_ADAPTER_UNICAST_ADDRESS      a;

            for (IntPtr p = ptr; p != IntPtr.Zero; p = a.Next)
            {
                a = (Win32_IP_ADAPTER_UNICAST_ADDRESS)Marshal.PtrToStructure(p, typeof(Win32_IP_ADAPTER_UNICAST_ADDRESS));
                c.InternalAdd(new Win32UnicastIPAddressInformation(a));
            }
            return(c);
        }
        // Helper method that marshals the address information into the classes.
        internal static UnicastIPAddressInformationCollection MarshalUnicastIpAddressInformationCollection(IntPtr ptr)
        {
            UnicastIPAddressInformationCollection addressList = new UnicastIPAddressInformationCollection();

            while (ptr != IntPtr.Zero)
            {
                Interop.IpHlpApi.IpAdapterUnicastAddress addr = Marshal.PtrToStructure <Interop.IpHlpApi.IpAdapterUnicastAddress>(ptr);
                addressList.InternalAdd(new SystemUnicastIPAddressInformation(addr));
                ptr = addr.next;
            }

            return(addressList);
        }
        internal static UnicastIPAddressInformationCollection ToAddressInformationCollection(IntPtr ptr)
        {
            UnicastIPAddressInformationCollection informations = new UnicastIPAddressInformationCollection();

            if (ptr != IntPtr.Zero)
            {
                IPEndPoint point;
                IpAdapterUnicastAddress adapterAddress = (IpAdapterUnicastAddress)Marshal.PtrToStructure(ptr, typeof(IpAdapterUnicastAddress));
                AddressFamily           family         = (adapterAddress.address.addressLength > 0x10) ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
                SocketAddress           socketAddress  = new SocketAddress(family, adapterAddress.address.addressLength);
                Marshal.Copy(adapterAddress.address.address, socketAddress.m_Buffer, 0, adapterAddress.address.addressLength);
                if (family == AddressFamily.InterNetwork)
                {
                    point = (IPEndPoint)IPEndPoint.Any.Create(socketAddress);
                }
                else
                {
                    point = (IPEndPoint)IPEndPoint.IPv6Any.Create(socketAddress);
                }
                informations.InternalAdd(new SystemUnicastIPAddressInformation(adapterAddress, point.Address));
                while (adapterAddress.next != IntPtr.Zero)
                {
                    adapterAddress = (IpAdapterUnicastAddress)Marshal.PtrToStructure(adapterAddress.next, typeof(IpAdapterUnicastAddress));
                    family         = (adapterAddress.address.addressLength > 0x10) ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
                    socketAddress  = new SocketAddress(family, adapterAddress.address.addressLength);
                    Marshal.Copy(adapterAddress.address.address, socketAddress.m_Buffer, 0, adapterAddress.address.addressLength);
                    if (family == AddressFamily.InterNetwork)
                    {
                        point = (IPEndPoint)IPEndPoint.Any.Create(socketAddress);
                    }
                    else
                    {
                        point = (IPEndPoint)IPEndPoint.IPv6Any.Create(socketAddress);
                    }
                    informations.InternalAdd(new SystemUnicastIPAddressInformation(adapterAddress, point.Address));
                }
            }
            return(informations);
        }
Exemplo n.º 7
0
        private UnicastIPAddressInformationCollection GetUnicastAddresses()
        {
            UnicastIPAddressInformationCollection collection = new UnicastIPAddressInformationCollection();

            foreach (UnicastIPAddressInformation info in
                     OsxNetworkInterface.GetOsxNetworkInterfaces().SelectMany(oni => oni.GetIPProperties().UnicastAddresses))
            {
                // PERF: Use Interop.Sys.EnumerateInterfaceAddresses directly here.
                collection.InternalAdd(info);
            }

            return(collection);
        }
        private static UnicastIPAddressInformationCollection GetUnicastAddresses(UnixNetworkInterface uni)
        {
            var collection = new UnicastIPAddressInformationCollection();

            foreach (IPAddress address in uni.Addresses.Where((addr) => !IsMulticast(addr)))
            {
                IPAddress netMask = (address.AddressFamily == AddressFamily.InterNetwork)
                                    ? uni.GetNetMaskForIPv4Address(address)
                                    : IPAddress.Any; // Windows compatibility
                collection.InternalAdd(new UnixUnicastIPAddressInformation(address, netMask));
            }

            return(collection);
        }
        // Helper method that marshals the addressinformation into the classes
        internal static UnicastIPAddressInformationCollection MarshalUnicastIpAddressInformationCollection(IntPtr ptr)
        {
            UnicastIPAddressInformationCollection addressList = new UnicastIPAddressInformationCollection();

            while (ptr != IntPtr.Zero)
            {
                // Get the address
                IpAdapterUnicastAddress addr =
                    (IpAdapterUnicastAddress)Marshal.PtrToStructure(ptr, typeof(IpAdapterUnicastAddress));
                // Add the address to the list
                addressList.InternalAdd(new SystemUnicastIPAddressInformation(addr));
                // Move to the next address in the list
                ptr = addr.next;
            }

            return(addressList);
        }
        private static UnicastIPAddressInformationCollection GetUnicastAddressTable()
        {
            UnicastIPAddressInformationCollection informations = new UnicastIPAddressInformationCollection();

            NetworkInterface[] allNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
            for (int i = 0; i < allNetworkInterfaces.Length; i++)
            {
                foreach (UnicastIPAddressInformation information in allNetworkInterfaces[i].GetIPProperties().UnicastAddresses)
                {
                    if (!informations.Contains(information))
                    {
                        informations.InternalAdd(information);
                    }
                }
            }
            return(informations);
        }
Exemplo n.º 11
0
        private static UnicastIPAddressInformationCollection GetUnicastAddressTable()
        {
            UnicastIPAddressInformationCollection rval = new UnicastIPAddressInformationCollection();

            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
            for (int i = 0; i < interfaces.Length; ++i)
            {
                UnicastIPAddressInformationCollection addresses = interfaces[i].GetIPProperties().UnicastAddresses;

                foreach (UnicastIPAddressInformation address in addresses)
                {
                    if (!rval.Contains(address))
                    {
                        rval.InternalAdd(address);
                    }
                }
            }

            return(rval);
        }