internal static string FetchResults(IAsyncResult ar) { int priority = -1; int weight = -1; SrvRecord[] array; DnsStatus dnsStatus = Dns.EndResolveToSrvRecords(ar, out array); if (dnsStatus != DnsStatus.Success) { AutoDiscoverDnsReader.DnsReaderTracer.TraceError(0L, "Failed to get results from DNS."); return(null); } int length = array.GetLength(0); if (length == 0) { AutoDiscoverDnsReader.DnsReaderTracer.TraceError(0L, "No SRV records were returned."); return(null); } AutoDiscoverDnsReader.DnsReaderTracer.TraceDebug <int>(0L, "{0} SRV records were returned.", length); bool flag = false; for (int i = 0; i < length; i++) { if (array[i].Port == 443) { priority = array[i].Priority; weight = array[i].Weight; flag = true; break; } } if (!flag) { AutoDiscoverDnsReader.DnsReaderTracer.TraceError(0L, "No SRV records were returned with SSL Port specified."); return(null); } SrvRecord[] array2 = Array.FindAll <SrvRecord>(array, (SrvRecord srvRecord) => srvRecord.Port == 443 && priority == srvRecord.Priority && weight == srvRecord.Weight); int num = 0; length = array2.GetLength(0); AutoDiscoverDnsReader.DnsReaderTracer.TraceDebug <int, int>(0L, "Found {0} SRV records with priority = {1}.", length, array2[0].Priority); if (length > 1) { num = AutoDiscoverDnsReader.randomIndexSelector.Next(length); } return(array2[num].TargetHost); }
private static Task <DnsTroubleshooter.SrvQueryResult> QuerySrvRecords(DnsTroubleshooter.DnsQueryContext context) { if (context == null) { throw new ArgumentNullException("state"); } context.SrvQuery = string.Format("_ldap._tcp.dc._msdcs.{0}", context.DomainFqdn); Dns client = DnsTroubleshooter.Client; return(Task.Factory.FromAsync <string, DnsQueryOptions, DnsTroubleshooter.SrvQueryResult>(new Func <string, DnsQueryOptions, AsyncCallback, object, IAsyncResult>(client.BeginRetrieveSrvRecords), delegate(IAsyncResult x) { ExTraceGlobals.FaultInjectionTracer.TraceTest(2244357437U); SrvRecord[] srvRecords; DnsStatus status = Dns.EndResolveToSrvRecords(x, out srvRecords); return new DnsTroubleshooter.SrvQueryResult(status, srvRecords); }, context.SrvQuery, DnsQueryOptions.UseTcpOnly | DnsQueryOptions.BypassCache, context, TaskCreationOptions.AttachedToParent)); }