Exemplo n.º 1
0
        public static bool TryParse(string text, out IPAddress address)
        {
            address = null;

            if (String.IsNullOrWhiteSpace(text))
            {
                return false;
            }

            var segments = text.Split('.');

            var addressBytes = new byte[4];
            if (segments.Length == 3)
            {
                if (!ExtractThreeSegments(addressBytes, segments))
                {
                    return false;
                }
            }
            else if (segments.Length == 4)
            {
                if (!ExtractFourSegments(addressBytes, segments))
                {
                    return false;
                }
            }
            else
            {
                return false;
            }

            address = new IPAddress(addressBytes);
            return true;
        }
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;
            }
        }
Exemplo n.º 3
0
        public IPEndpoint(IPAddress address, ushort port)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            m_address = address;
            m_port = port;
            m_serviceName = m_port.ToString(CultureInfo.InvariantCulture);
        }
Exemplo n.º 4
0
        public ConnectionInfo(IPAddress address, IPNetwork network)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }

            m_address = address;
            m_network = network;
        }
Exemplo n.º 5
0
        public DhcpInfo(IPAddress gatewayAddress, IPAddress dnsServerAddress, string domainName)
        {
            if (gatewayAddress == null)
            {
                throw new ArgumentNullException("gatewayAddress");
            }
            if (dnsServerAddress == null)
            {
                throw new ArgumentNullException("dnsServerAddress");
            }

            m_gatewayAddress = gatewayAddress;
            m_dnsServerAddress = dnsServerAddress;
            m_domainName = domainName;
        }
Exemplo n.º 6
0
        public HostInfo(Guid networkAdapterId, HostName hostName, IPAddress address)
        {
            if (hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            m_networkAdapterId = networkAdapterId;
            m_hostName = hostName;
            m_address = address;
        }
Exemplo n.º 7
0
        public IPHostEntry(string hostName, IPAddress[] addresses, string[] aliases)
        {
            if (string.IsNullOrWhiteSpace(hostName))
            {
                throw new ArgumentException("Invalid host name", "hostName");
            }
            if (addresses == null)
            {
                throw new ArgumentNullException("addresses");
            }
            if (aliases == null)
            {
                throw new ArgumentNullException("aliases");
            }

            m_hostName = hostName;
            m_addresses = addresses;
            m_aliases = aliases;
        }
Exemplo n.º 8
0
 private static IPAddress GetAddress(IntPtr data, int offset = 0)
 {
     var addressBytes = (DHCPCAPI_IP_ADDRESS)Marshal.PtrToStructure(data + offset, typeof(DHCPCAPI_IP_ADDRESS));
     var result = new IPAddress(new[]
     {
         addressBytes.Value0,
         addressBytes.Value1,
         addressBytes.Value2,
         addressBytes.Value3
     });
     return result;
 }
Exemplo n.º 9
0
 private static IPAddress[] GetAddresses(IntPtr data, int addressCount)
 {
     var addresses = new IPAddress[addressCount];
     for (int i = 0, offset = 0; i < addressCount; ++i, offset += 4)
     {
         addresses[i] = GetAddress(data, offset);
     }
     return addresses;
 }
Exemplo n.º 10
0
 public IPNetwork(IPAddress networkAddress, byte prefixLength)
     : this(GetAddressValue(networkAddress), prefixLength)
 {
 }
Exemplo n.º 11
0
        private static uint GetAddressValue(IPAddress networkAddress)
        {
            if (networkAddress == null)
            {
                throw new ArgumentNullException("networkAddress");
            }

            var result = networkAddress.Value;
            return result;
        }