コード例 #1
0
 internal SystemIPAddressInformation(IpAdapterUnicastAddress adapterAddress, IPAddress address)
 {
     this.dnsEligible = true;
     this.address     = address;
     this.transient   = (adapterAddress.flags & AdapterAddressFlags.Transient) > 0;
     this.dnsEligible = (adapterAddress.flags & AdapterAddressFlags.DnsEligible) > 0;
 }
 internal SystemIPAddressInformation(IpAdapterUnicastAddress adapterAddress, IPAddress address)
 {
     this.dnsEligible = true;
     this.address = address;
     this.transient = (adapterAddress.flags & AdapterAddressFlags.Transient) > 0;
     this.dnsEligible = (adapterAddress.flags & AdapterAddressFlags.DnsEligible) > 0;
 }
        internal SystemUnicastIPAddressInformation(IpAdapterUnicastAddress adapterAddress) {
            IPAddress ipAddress = adapterAddress.address.MarshalIPAddress();
            this.innerInfo = new SystemIPAddressInformation(ipAddress, adapterAddress.flags);
            this.prefixOrigin = adapterAddress.prefixOrigin;
            this.suffixOrigin = adapterAddress.suffixOrigin;
            this.dadState = adapterAddress.dadState;
            this.validLifetime = adapterAddress.validLifetime;
            this.preferredLifetime = adapterAddress.preferredLifetime;
            this.dhcpLeaseLifetime = adapterAddress.leaseLifetime;

            this.prefixLength = adapterAddress.prefixLength;

            // IPv6 returns 0.0.0.0 for consistancy with XP
            if (ipAddress.AddressFamily == AddressFamily.InterNetwork) {
                ipv4Mask = PrefixLengthToSubnetMask(prefixLength, ipAddress.AddressFamily);
            }
        }
コード例 #4
0
        // 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);
        }
コード例 #5
0
        internal SystemUnicastIPAddressInformation(IpAdapterUnicastAddress adapterAddress)
        {
            IPAddress ipAddress = adapterAddress.address.MarshalIPAddress();

            this.innerInfo         = new SystemIPAddressInformation(ipAddress, adapterAddress.flags);
            this.prefixOrigin      = adapterAddress.prefixOrigin;
            this.suffixOrigin      = adapterAddress.suffixOrigin;
            this.dadState          = adapterAddress.dadState;
            this.validLifetime     = adapterAddress.validLifetime;
            this.preferredLifetime = adapterAddress.preferredLifetime;
            this.dhcpLeaseLifetime = adapterAddress.leaseLifetime;

            this.prefixLength = adapterAddress.prefixLength;

            // IPv6 returns 0.0.0.0 for consistancy with XP
            if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
            {
                ipv4Mask = PrefixLengthToSubnetMask(prefixLength, ipAddress.AddressFamily);
            }
        }
        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);
        }
 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;
 }
 internal SystemUnicastIPAddressInformation(IpAdapterUnicastAddress adapterAddress, IPAddress ipAddress)
 {
     this.innerInfo = new SystemIPAddressInformation(adapterAddress, ipAddress);
     this.adapterAddress = adapterAddress;
     this.dhcpLeaseLifetime = adapterAddress.leaseLifetime;
 }
 internal SystemUnicastIPAddressInformation(IpAdapterUnicastAddress adapterAddress, IPAddress ipAddress)
 {
     this.innerInfo         = new SystemIPAddressInformation(adapterAddress, ipAddress);
     this.adapterAddress    = adapterAddress;
     this.dhcpLeaseLifetime = adapterAddress.leaseLifetime;
 }