Exemplo n.º 1
0
        private void SetConnectServerFromSRVRecords()
        {
            // check we have a response
            if (_SRVRecords != null && _SRVRecords.Length > 0)
            {
                //SRVRecord srv = _SRVRecords[0];
                _currentSRVRecord = PickSRVRecord();

                this.Port           = _currentSRVRecord.Port;
                this.ConnectServer  = _currentSRVRecord.Target;
            }
            else
            {
                // no SRV-Records set
                _currentSRVRecord = null;
                this.ConnectServer = null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shorthand form to make SRV querying easier, essentially wraps up the retreival
        /// of the SRV records, and sorts them by preference
        /// </summary>
        /// <param name="domain">domain name to retreive SRV RRs for</param>
        /// <param name="dnsServer">the server we're going to ask</param>
        /// <returns>An array of SRVRecords</returns>
        public static SRVRecord[] SRVLookup(string domain, IPAddress dnsServer)
        {
            // check the inputs
            if (domain == null) throw new ArgumentNullException("domain");
            if (dnsServer == null)  throw new ArgumentNullException("dnsServer");

            // create a request for this
            Request request = new Request();

            // add one question - the SRV IN lookup for the supplied domain
            request.AddQuestion(new Question(domain, DnsType.SRV, DnsClass.IN));

            // fire it off
            Response response = Lookup(request, dnsServer);

            // if we didn't get a response, then return null
            if (response == null) return null;

            // create a growable array of SRV records
            ArrayList resourceRecords = new ArrayList();

            // add each of the answers to the array
            foreach (Answer answer in response.Answers)
            {
                // if the answer is an SRV record
                if (answer.Type == DnsType.SRV)
                {
                   // add it to our array
                   resourceRecords.Add(answer.Record);
                }
            }

            // create array of MX records
            SRVRecord[] srvRecords = new SRVRecord[resourceRecords.Count];

            // copy from the array list
            resourceRecords.CopyTo(srvRecords);

            // sort into lowest preference order
            Array.Sort(srvRecords);

            // and return
            return srvRecords;
        }
Exemplo n.º 3
0
 private void RemoveSrvRecord(SRVRecord rec)
 {
     int i = 0;
     SRVRecord[] recs = new SRVRecord[_SRVRecords.Length - 1];
     foreach (SRVRecord srv in _SRVRecords)
     {
         if (!srv.Equals(rec))
         {
             recs[i] = srv;
             i++;
         }
     }
     _SRVRecords = recs;
 }