Example #1
0
        internal static NameServerCollection Create(
            IEnumerable <DnsClient.DNS.RR> records, IEnumerable <DnsClient.DNS.RR> addresses = null)
        {
            // NS records from Authority Section
            IEnumerable <DnsClient.DNS.Records.NS> nsRecords = records.Select <DnsClient.DNS.Records.NS>();

            DnsClient.DNS.Records.NS ns1 = nsRecords.FirstOrDefault();
            if (ns1 == null)
            {
                return(Empty);
            }

            // There are NS RRs.
            NameServerCollection result = new NameServerCollection(
                (DnsDomain)ns1.Base.NAME, nsRecords.Select(ns => new NameServer(
                                                               (DnsDomain)ns.Base.NAME, (DnsDomain)ns.NSDNAME)));

            // Apply address records from Additional Section (A or AAAA) if any
            if (addresses != null)
            {
                foreach (DnsClient.DNS.Records.Address addr in addresses.Select(
                             rr => rr as DnsClient.DNS.Records.Address).Where(a => a != null))
                {
                    DnsDomain name = DnsDomain.Parse(addr.Base.NAME);
                    if (result.NameServers.ContainsKey(name))
                    {
                        result.NameServers[name].Addresses.Add(addr.ADDRESS);
                    }
                }
            }

            return(result);
        }
Example #2
0
        internal static NameServerCollection Find(DnsDomain domain,
                                                  IEnumerable <DnsClient.DNS.RR> records, IEnumerable <DnsClient.DNS.RR> addresses)
        {
            // [RFC 1034]
            // 5.3.3. Algorithm
            //
            // 2. Find the best servers to ask.
            //
            // Step 2 looks for a name server to ask for the required data.  The
            // general strategy is to look for locally-available name server RRs,
            // starting at SNAME, then the parent domain name of SNAME, the
            // grandparent, and so on toward the root.  Thus if SNAME were
            // Mockapetris.ISI.EDU, this step would look for NS RRs for
            // Mockapetris.ISI.EDU, then ISI.EDU, then EDU, and then . (the root).
            // These NS RRs list the names of hosts for a zone at or above SNAME. Copy
            // the names into SLIST.


            // NS records from Authority Section above domain (SNAME)
            IEnumerable <DnsClient.DNS.Records.NS> nservers = records.Select <
                DnsClient.DNS.Records.NS>().Where(ns => domain.IsBelow(ns.Base.NAME));

            if (!nservers.Any())
            {
                return(Empty);
            }

            // There are relevant NS RRs.
            NameServerCollection result = new NameServerCollection(
                domain, nservers.Select(ns => new NameServer(
                                            (DnsDomain)ns.Base.NAME, (DnsDomain)ns.NSDNAME)));

            // Apply address records from Additional Section (A or AAAA) if any
            if (!object.ReferenceEquals(null, addresses))
            {
                foreach (DnsClient.DNS.Records.Address addr in addresses.Select <
                             DnsClient.DNS.Records.Address>())
                {
                    DnsDomain hostname = (DnsDomain)addr.Base.NAME;
                    if (result.NameServers.ContainsKey(hostname))
                    {
                        result.NameServers[hostname].Addresses.Add(addr.ADDRESS);
                    }
                }
            }

            return(result);
        }