private string ProcessDnsQuery(string pName, string ipDNSName, ManagedMethodProvider.IP4_ARRAY ipDNS)
        {
            IntPtr        intPtr        = IntPtr.Zero;
            IntPtr        zero          = IntPtr.Zero;
            StringBuilder stringBuilder = new StringBuilder();

            DnsApi.DnsRecordType   dnsRecordType = DnsApi.DnsRecordType.A;
            DnsApi.DnsQueryOptions options       = DnsApi.DnsQueryOptions.ByPassCache | DnsApi.DnsQueryOptions.TreatAsFqdn;
            try
            {
                intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ipDNS));
                Marshal.StructureToPtr(ipDNS, intPtr, false);
                int num = DnsApi.DnsQuery(pName, dnsRecordType, options, intPtr, ref zero, IntPtr.Zero);
                if (num == 0)
                {
                    IntPtr intPtr2 = zero;
                    do
                    {
                        DnsApi.DNS_RECORD_BASE dns_RECORD_BASE = (DnsApi.DNS_RECORD_BASE)Marshal.PtrToStructure(intPtr2, typeof(DnsApi.DNS_RECORD_BASE));
                        if (dns_RECORD_BASE.WType == (ushort)dnsRecordType)
                        {
                            DnsApi.DnsRecordType wtype = (DnsApi.DnsRecordType)dns_RECORD_BASE.WType;
                            if (wtype == DnsApi.DnsRecordType.A)
                            {
                                stringBuilder.Append(this.ConvertUINTToIP(((DnsApi.DNS_RECORD_A)Marshal.PtrToStructure(intPtr2, typeof(DnsApi.DNS_RECORD_A))).A) + ";");
                            }
                        }
                        intPtr2 = dns_RECORD_BASE.PNext;
                    }while (intPtr2 != IntPtr.Zero);
                    if (stringBuilder.Length > 0)
                    {
                        stringBuilder = (stringBuilder = new StringBuilder(stringBuilder.ToString().TrimEnd(ManagedMethodProvider.aip6AdrDelimiter)));
                    }
                }
                else if (num != 9501)
                {
                    Win32Exception ex = new Win32Exception(num);
                    throw ex;
                }
            }
            catch (Exception ex2)
            {
                throw new Exception(Strings.ErrorDNSQueryA(ipDNSName, pName, ex2.Message), ex2);
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    DnsApi.DnsRecordListFree(zero, DnsApi.DnsFreeType.DnsFreeRecordList);
                }
                if (intPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(intPtr);
                }
            }
            return(stringBuilder.ToString());
        }
예제 #2
0
 public static extern int DnsQuery(string name, DnsApi.DnsRecordType type, DnsApi.DnsQueryOptions options, IntPtr dnsServers, ref IntPtr QueryResultSet, IntPtr reserved);