Пример #1
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);
        }
        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);
        }
Пример #3
0
        // Adds any IPAddress to this interface's List of addresses.
        protected void AddAddress(IPAddress ipAddress, int prefix)
        {
            if (IPAddressUtil.IsMulticast(ipAddress))
            {
                // Deferred initialization.
                _multicastAddresses ??= new List <IPAddress>();

                _multicastAddresses.Add(ipAddress);
            }
            else
            {
                _unicastAddresses.Add(new UnixUnicastIPAddressInformation(ipAddress, prefix));
            }
        }
Пример #4
0
        private static UnicastIPAddressInformationCollection GetUnicastAddresses(UnixNetworkInterface uni)
        {
            var collection = new UnicastIPAddressInformationCollection();

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

            return(collection);
        }
Пример #5
0
        private static MulticastIPAddressInformationCollection GetMulticastAddresses(UnixNetworkInterface uni)
        {
            var collection = new MulticastIPAddressInformationCollection();

            foreach (IPAddress address in uni.Addresses)
            {
                if (IPAddressUtil.IsMulticast(address))
                {
                    collection.InternalAdd(new UnixMulticastIPAddressInformation(address));
                }
            }

            return(collection);
        }