Exemplo n.º 1
0
        public IPNetwork(uint value, byte prefixLength)
        {
            if (!IPNetworkHelper.IsValidNetworkPrefixLength(prefixLength))
            {
                throw new ArgumentOutOfRangeException("prefixLength");
            }

            m_prefixLength = prefixLength;

            // TODO: Consider moving GetNetworkMaskValue into constructor IPNetworkMask since we now have a separate class for it...
            m_networkMask = new IPNetworkMask(IPNetworkHelper.GetNetworkMaskValue(m_prefixLength));

            m_networkAddressValue = value & m_networkMask.Value;
            m_networkAddress = new IPAddress(m_networkAddressValue);
            if (m_prefixLength < 32)
            {
                m_firstUsableAddress = new IPAddress(m_networkAddressValue + 1);
                var wildcardMask = 0xffffffff - m_networkMask.Value;
                var broadcastAddressValue = m_networkAddressValue | wildcardMask;
                m_lastUsableAddress = new IPAddress(broadcastAddressValue - 1);
                m_broadcastAddress = new IPAddress(broadcastAddressValue);
                m_usableAddresses = new IPAddressRange(m_firstUsableAddress, m_lastUsableAddress);
            }
            else
            {
                m_usableAddresses = IPAddressRange.Empty;
            }
        }
Exemplo n.º 2
0
        public IPNetwork(uint value, byte prefixLength)
        {
            if (!IPNetworkHelper.IsValidNetworkPrefixLength(prefixLength))
            {
                throw new ArgumentOutOfRangeException("prefixLength");
            }

            m_prefixLength = prefixLength;

            // TODO: Consider moving GetNetworkMaskValue into constructor IPNetworkMask since we now have a separate class for it...
            m_networkMask = new IPNetworkMask(IPNetworkHelper.GetNetworkMaskValue(m_prefixLength));

            m_networkAddressValue = value & m_networkMask.Value;
            m_networkAddress      = new IPAddress(m_networkAddressValue);
            if (m_prefixLength < 32)
            {
                m_firstUsableAddress = new IPAddress(m_networkAddressValue + 1);
                var wildcardMask          = 0xffffffff - m_networkMask.Value;
                var broadcastAddressValue = m_networkAddressValue | wildcardMask;
                m_lastUsableAddress = new IPAddress(broadcastAddressValue - 1);
                m_broadcastAddress  = new IPAddress(broadcastAddressValue);
                m_usableAddresses   = new IPAddressRange(m_firstUsableAddress, m_lastUsableAddress);
            }
            else
            {
                m_usableAddresses = IPAddressRange.Empty;
            }
        }