示例#1
0
        void AddHost(string host, string addr)
        {
            string[] parts = host.Split('.');
            Dictionary <string, HostNode> node = root;
            bool include_sub = false;
            int  end         = 0;

            if (parts[0].Length == 0)
            {
                end         = 1;
                include_sub = true;
            }
            for (int i = parts.Length - 1; i > end; ++i)
            {
                if (!node.ContainsKey(parts[i]))
                {
                    node[parts[i]] = new HostNode();
                }
                if (node[parts[i]].subnode == null)
                {
                    node[parts[i]].subnode = new Dictionary <string, HostNode>();
                }
                node = node[parts[i]].subnode;
            }
            node[parts[end]] = new HostNode(include_sub, addr);
        }
示例#2
0
        public void AddHost(string host, string addr)
        {
            IPAddress ip_addr = null;

            if (IPAddress.TryParse(host, out ip_addr))
            {
                string[] addr_parts = addr.Split(new[] { ' ', '\t' }, 2, StringSplitOptions.RemoveEmptyEntries);
                if (addr_parts.Length >= 2)
                {
                    ips.insert(new IPAddressCmp(host), new IPAddressCmp(addr_parts[0]), addr_parts[1]);
                    return;
                }
            }

            string[] parts = host.Split('.');
            Dictionary <string, HostNode> node = root;
            bool include_sub = false;
            int  end         = 0;

            if (parts[0].Length == 0)
            {
                end         = 1;
                include_sub = true;
            }
            for (int i = parts.Length - 1; i > end; --i)
            {
                if (!node.ContainsKey(parts[i]))
                {
                    node[parts[i]] = new HostNode();
                }
                if (node[parts[i]].subnode == null)
                {
                    node[parts[i]].subnode = new Dictionary <string, HostNode>();
                }
                node = node[parts[i]].subnode;
            }
            node[parts[end]] = new HostNode(include_sub, addr);
        }