internal SystemIPInterfaceProperties(FixedInfo fixedInfo, IpAdapterAddresses ipAdapterAddresses)
 {
     this.dnsEnabled = fixedInfo.EnableDns;
     this.index      = ipAdapterAddresses.index;
     this.name       = ipAdapterAddresses.AdapterName;
     this.ipv6Index  = ipAdapterAddresses.ipv6Index;
     if (this.index > 0)
     {
         this.versionSupported |= IPVersion.IPv4;
     }
     if (this.ipv6Index > 0)
     {
         this.versionSupported |= IPVersion.IPv6;
     }
     this.mtu                = ipAdapterAddresses.mtu;
     this.adapterFlags       = ipAdapterAddresses.flags;
     this.dnsSuffix          = ipAdapterAddresses.dnsSuffix;
     this.dynamicDnsEnabled  = (ipAdapterAddresses.flags & AdapterFlags.DnsEnabled) > 0;
     this.multicastAddresses = SystemMulticastIPAddressInformation.ToAddressInformationCollection(ipAdapterAddresses.FirstMulticastAddress);
     this.dnsAddresses       = SystemIPAddressInformation.ToAddressCollection(ipAdapterAddresses.FirstDnsServerAddress, this.versionSupported);
     this.anycastAddresses   = SystemIPAddressInformation.ToAddressInformationCollection(ipAdapterAddresses.FirstAnycastAddress, this.versionSupported);
     this.unicastAddresses   = SystemUnicastIPAddressInformation.ToAddressInformationCollection(ipAdapterAddresses.FirstUnicastAddress);
     if (this.ipv6Index > 0)
     {
         this.ipv6Properties = new SystemIPv6InterfaceProperties(this.ipv6Index, this.mtu);
     }
 }
コード例 #2
0
        static IPAddressInformationCollection Win32FromAnycast(IntPtr ptr)
        {
            var c = new IPAddressInformationCollection();
            Win32_IP_ADAPTER_ANYCAST_ADDRESS a;

            for (IntPtr p = ptr; p != IntPtr.Zero; p = a.Next)
            {
                a = (Win32_IP_ADAPTER_ANYCAST_ADDRESS)Marshal.PtrToStructure(p, typeof(Win32_IP_ADAPTER_ANYCAST_ADDRESS));
                c.InternalAdd(new SystemIPAddressInformation(
                                  a.Address.GetIPAddress(),
                                  a.LengthFlags.IsDnsEligible,
                                  a.LengthFlags.IsTransient));
            }
            return(c);
        }
コード例 #3
0
        internal static IPAddressInformationCollection MarshalIpAddressInformationCollection(IntPtr ptr)
        {
            IPAddressInformationCollection addressList = new IPAddressInformationCollection();

            while (ptr != IntPtr.Zero)
            {
                IpAdapterAddress addressStructure =
                    (IpAdapterAddress)Marshal.PtrToStructure(ptr, typeof(IpAdapterAddress));
                IPAddress address = addressStructure.address.MarshalIPAddress();
                addressList.InternalAdd(new SystemIPAddressInformation(address, addressStructure.flags));

                ptr = addressStructure.next;
            }

            return(addressList);
        }
コード例 #4
0
        internal static IPAddressInformationCollection ToAddressInformationCollection(IntPtr ptr, IPVersion versionSupported)
        {
            IPAddressInformationCollection informations = new IPAddressInformationCollection();

            if (ptr != IntPtr.Zero)
            {
                IPEndPoint       point;
                IpAdapterAddress adapterAddress = (IpAdapterAddress)Marshal.PtrToStructure(ptr, typeof(IpAdapterAddress));
                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 SystemIPAddressInformation(adapterAddress, point.Address));
                while (adapterAddress.next != IntPtr.Zero)
                {
                    adapterAddress = (IpAdapterAddress)Marshal.PtrToStructure(adapterAddress.next, typeof(IpAdapterAddress));
                    family         = (adapterAddress.address.addressLength > 0x10) ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
                    if (((family == AddressFamily.InterNetwork) && ((versionSupported & IPVersion.IPv4) > IPVersion.None)) || ((family == AddressFamily.InterNetworkV6) && ((versionSupported & IPVersion.IPv6) > IPVersion.None)))
                    {
                        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 SystemIPAddressInformation(adapterAddress, point.Address));
                    }
                }
            }
            return(informations);
        }
コード例 #5
0
        internal SystemIPInterfaceProperties(Interop.IpHlpApi.FIXED_INFO fixedInfo, Interop.IpHlpApi.IpAdapterAddresses ipAdapterAddresses)
        {
            _adapterFlags      = ipAdapterAddresses.flags;
            _dnsSuffix         = ipAdapterAddresses.dnsSuffix;
            _dnsEnabled        = fixedInfo.enableDns;
            _dynamicDnsEnabled = ((ipAdapterAddresses.flags & Interop.IpHlpApi.AdapterFlags.DnsEnabled) > 0);

            _multicastAddresses = SystemMulticastIPAddressInformation.ToMulticastIpAddressInformationCollection(
                Interop.IpHlpApi.IpAdapterAddress.MarshalIpAddressInformationCollection(ipAdapterAddresses.firstMulticastAddress));
            _dnsAddresses     = Interop.IpHlpApi.IpAdapterAddress.MarshalIpAddressCollection(ipAdapterAddresses.firstDnsServerAddress);
            _anycastAddresses = Interop.IpHlpApi.IpAdapterAddress.MarshalIpAddressInformationCollection(
                ipAdapterAddresses.firstAnycastAddress);
            _unicastAddresses = SystemUnicastIPAddressInformation.MarshalUnicastIpAddressInformationCollection(
                ipAdapterAddresses.firstUnicastAddress);
            _winsServersAddresses = Interop.IpHlpApi.IpAdapterAddress.MarshalIpAddressCollection(
                ipAdapterAddresses.firstWinsServerAddress);
            _gatewayAddresses = SystemGatewayIPAddressInformation.ToGatewayIpAddressInformationCollection(
                Interop.IpHlpApi.IpAdapterAddress.MarshalIpAddressCollection(ipAdapterAddresses.firstGatewayAddress));

            _dhcpServers = new InternalIPAddressCollection();
            if (ipAdapterAddresses.dhcpv4Server.address != IntPtr.Zero)
            {
                _dhcpServers.InternalAdd(ipAdapterAddresses.dhcpv4Server.MarshalIPAddress());
            }

            if (ipAdapterAddresses.dhcpv6Server.address != IntPtr.Zero)
            {
                _dhcpServers.InternalAdd(ipAdapterAddresses.dhcpv6Server.MarshalIPAddress());
            }

            if ((_adapterFlags & Interop.IpHlpApi.AdapterFlags.IPv4Enabled) != 0)
            {
                _ipv4Properties = new SystemIPv4InterfaceProperties(fixedInfo, ipAdapterAddresses);
            }

            if ((_adapterFlags & Interop.IpHlpApi.AdapterFlags.IPv6Enabled) != 0)
            {
                _ipv6Properties = new SystemIPv6InterfaceProperties(ipAdapterAddresses.ipv6Index,
                                                                    ipAdapterAddresses.mtu, ipAdapterAddresses.zoneIndices);
            }
        }
コード例 #6
0
        // This constructor is for Vista and newer
        internal SystemIPInterfaceProperties(FixedInfo fixedInfo, IpAdapterAddresses ipAdapterAddresses)
        {
            adapterFlags      = ipAdapterAddresses.flags;
            dnsSuffix         = ipAdapterAddresses.dnsSuffix;
            dnsEnabled        = fixedInfo.EnableDns;
            dynamicDnsEnabled = ((ipAdapterAddresses.flags & AdapterFlags.DnsEnabled) > 0);

            multicastAddresses = SystemMulticastIPAddressInformation.ToMulticastIpAddressInformationCollection(
                IpAdapterAddress.MarshalIpAddressInformationCollection(ipAdapterAddresses.firstMulticastAddress));
            dnsAddresses     = IpAdapterAddress.MarshalIpAddressCollection(ipAdapterAddresses.firstDnsServerAddress);
            anycastAddresses = IpAdapterAddress.MarshalIpAddressInformationCollection(
                ipAdapterAddresses.firstAnycastAddress);
            unicastAddresses = SystemUnicastIPAddressInformation.MarshalUnicastIpAddressInformationCollection(
                ipAdapterAddresses.firstUnicastAddress);
            winsServersAddresses = IpAdapterAddress.MarshalIpAddressCollection(
                ipAdapterAddresses.firstWinsServerAddress);
            gatewayAddresses = SystemGatewayIPAddressInformation.ToGatewayIpAddressInformationCollection(
                IpAdapterAddress.MarshalIpAddressCollection(ipAdapterAddresses.firstGatewayAddress));

            dhcpServers = new IPAddressCollection();
            if (ipAdapterAddresses.dhcpv4Server.address != IntPtr.Zero)
            {
                dhcpServers.InternalAdd(ipAdapterAddresses.dhcpv4Server.MarshalIPAddress());
            }
            if (ipAdapterAddresses.dhcpv6Server.address != IntPtr.Zero)
            {
                dhcpServers.InternalAdd(ipAdapterAddresses.dhcpv6Server.MarshalIPAddress());
            }

            if ((adapterFlags & AdapterFlags.IPv4Enabled) != 0)
            {
                ipv4Properties = new SystemIPv4InterfaceProperties(fixedInfo, ipAdapterAddresses);
            }

            if ((adapterFlags & AdapterFlags.IPv6Enabled) != 0)
            {
                ipv6Properties = new SystemIPv6InterfaceProperties(ipAdapterAddresses.ipv6Index,
                                                                   ipAdapterAddresses.mtu, ipAdapterAddresses.zoneIndices);
            }
        }
 internal SystemIPInterfaceProperties(FixedInfo fixedInfo, IpAdapterInfo ipAdapterInfo)
 {
     this.dnsEnabled         = fixedInfo.EnableDns;
     this.name               = ipAdapterInfo.adapterName;
     this.index              = ipAdapterInfo.index;
     this.multicastAddresses = new MulticastIPAddressInformationCollection();
     this.anycastAddresses   = new IPAddressInformationCollection();
     if (this.index > 0)
     {
         this.versionSupported |= IPVersion.IPv4;
     }
     if (ComNetOS.IsWin2K)
     {
         this.ReadRegDnsSuffix();
     }
     this.unicastAddresses = new UnicastIPAddressInformationCollection();
     foreach (IPExtendedAddress address in ipAdapterInfo.ipAddressList.ToIPExtendedAddressArrayList())
     {
         this.unicastAddresses.InternalAdd(new SystemUnicastIPAddressInformation(ipAdapterInfo, address));
     }
     try
     {
         this.ipv4Properties = new SystemIPv4InterfaceProperties(fixedInfo, ipAdapterInfo);
         if ((this.dnsAddresses == null) || (this.dnsAddresses.Count == 0))
         {
             this.dnsAddresses = this.ipv4Properties.DnsAddresses;
         }
     }
     catch (NetworkInformationException exception)
     {
         if (exception.ErrorCode != 0x57L)
         {
             throw;
         }
     }
 }
        internal static MulticastIPAddressInformationCollection ToMulticastIpAddressInformationCollection(IPAddressInformationCollection addresses)
        {
            MulticastIPAddressInformationCollection multicastList = new MulticastIPAddressInformationCollection();

            foreach (IPAddressInformation addressInfo in addresses)
            {
                multicastList.InternalAdd(new SystemMulticastIPAddressInformation((SystemIPAddressInformation)addressInfo));
            }
            return(multicastList);
        }