Example #1
0
        internal IDictionary <NetworkAddress, NetworkAddress> CreateMapFromConfiguration()
        {
            var addresses = new Dictionary <NetworkAddress, NetworkAddress>();

            foreach (var configurationAddressString in _configurationAddresses)
            {
                if (!NetworkAddress.TryParse(configurationAddressString, out var configurationAddress))
                {
                    throw new FormatException($"The string \"{configurationAddressString}\" does not represent a valid network address.");
                }

                // got to be v6 - cannot get IPAddress to parse anything that would not be v4 or v6
                //if (!address.IsIpV6)
                //    throw new NotSupportedException($"Address family {address.IPAddress.AddressFamily} is not supported.");

                // see https://4sysops.com/archives/ipv6-tutorial-part-6-site-local-addresses-and-link-local-addresses/
                // loopback - is ::1 exclusively
                // site-local - equivalent to private IP addresses in v4 = fe:c0:...
                // link-local - hosts on the link
                // global - globally route-able addresses

                IEnumerable <NetworkAddress> networkAddresses;
                if (configurationAddress.IsIpV4 || configurationAddress.IsIpV6GlobalOrScoped)
                {
                    // v4, or v6 global or has a scope = qualified, can return
                    networkAddresses = ExpandPorts(configurationAddress);
                }
                else
                {
                    // address is v6 site-local or link-local, and has no scopeId
                    // get localhost addresses
                    networkAddresses = GetV6LocalAddresses()
                                       .SelectMany(x => ExpandPorts(configurationAddress, x));
                }

                foreach (var networkAddress in networkAddresses)
                {
                    addresses.Add(networkAddress, networkAddress);
                }
            }

            return(addresses);
        }
Example #2
0
        private IDictionary <NetworkAddress, NetworkAddress> CreateMapFromConfiguration()
        {
            var addresses = new Dictionary <NetworkAddress, NetworkAddress>();

            foreach (var configurationAddress in _configurationAddresses)
            {
                if (!NetworkAddress.TryParse(configurationAddress, out IEnumerable <NetworkAddress> networkAddresses))
                {
                    throw new FormatException($"The string \"{configurationAddress}\" does not represent a valid network address.");
                }

                foreach (var networkAddress in networkAddresses)
                {
                    addresses.Add(networkAddress, networkAddress);
                }
            }

            return(addresses);
        }