[Dnsmail-cvs] dnsmail DNSAPI.cs,1.5,1.6
Brought to you by:
ethem
From: Ethem E. <et...@us...> - 2006-08-07 09:59:56
|
Update of /cvsroot/dnsmail/dnsmail In directory sc8-pr-cvs12.sourceforge.net:/tmp/cvs-serv27686/dnsmail Modified Files: DNSAPI.cs Log Message: Coding art. tabs, spaces, etc... :) Index: DNSAPI.cs =================================================================== RCS file: /cvsroot/dnsmail/dnsmail/DNSAPI.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DNSAPI.cs 7 Aug 2006 08:43:41 -0000 1.5 --- DNSAPI.cs 7 Aug 2006 09:59:51 -0000 1.6 *************** *** 10,17 **** using MxRecord = Erle.DnsMail.MxRecord; using MxRecordComparer = Erle.DnsMail.MxRecordComparer; ! public sealed class DNSAPI { ! private DNSAPI(){} static DNSAPI() { --- 10,17 ---- using MxRecord = Erle.DnsMail.MxRecord; using MxRecordComparer = Erle.DnsMail.MxRecordComparer; ! public sealed class DNSAPI { ! private DNSAPI() { } static DNSAPI() { *************** *** 25,33 **** localHost = null; hello = null; ! GC.Collect(); } #endregion ! #region LocalHost private static String localHost; --- 25,33 ---- localHost = null; hello = null; ! GC.Collect(); } #endregion ! #region LocalHost private static String localHost; *************** *** 52,56 **** if (hello == null) hello = NetDns.GetHostByAddress(NetDns.GetHostByName(LocalHost).AddressList[0]).HostName; ! return hello; } --- 52,56 ---- if (hello == null) hello = NetDns.GetHostByAddress(NetDns.GetHostByName(LocalHost).AddressList[0]).HostName; ! return hello; } *************** *** 75,92 **** private delegate MxRecord[] MxRecordsDelegate(string domain); private static readonly MxRecordsDelegate resolve = new MxRecordsDelegate(GetMxRecords); ! public static IAsyncResult BeginGetMxRecords(string domain, AsyncCallback callback, Object state) { ! if (domain == null) throw new ArgumentNullException("domain"); ! return resolve.BeginInvoke(domain, callback, state); } ! public static MxRecord[] EndGetMxRecords(IAsyncResult result) { ! if (result == null) throw new ArgumentNullException("result"); ! if(!result.IsCompleted) result.AsyncWaitHandle.WaitOne(); --- 75,92 ---- private delegate MxRecord[] MxRecordsDelegate(string domain); private static readonly MxRecordsDelegate resolve = new MxRecordsDelegate(GetMxRecords); ! public static IAsyncResult BeginGetMxRecords(string domain, AsyncCallback callback, Object state) { ! if (domain == null) throw new ArgumentNullException("domain"); ! return resolve.BeginInvoke(domain, callback, state); } ! public static MxRecord[] EndGetMxRecords(IAsyncResult result) { ! if (result == null) throw new ArgumentNullException("result"); ! if (!result.IsCompleted) result.AsyncWaitHandle.WaitOne(); *************** *** 106,119 **** IntPtr pQuery = IntPtr.Zero; ! UInt32 status = UnsafeNativeMethods.DnsQuery( ! domain, STRUCTURES.DNS_TYPE_MX, ! STRUCTURES.DNS_QUERY_STANDARD, ! IntPtr.Zero, ! ref pQuery, IntPtr.Zero ); ! if (status == STRUCTURES.SUCCESS && pQuery != IntPtr.Zero) { try --- 106,119 ---- IntPtr pQuery = IntPtr.Zero; ! UInt32 status = UnsafeNativeMethods.DnsQuery( ! domain, STRUCTURES.DNS_TYPE_MX, ! STRUCTURES.DNS_QUERY_STANDARD, ! IntPtr.Zero, ! ref pQuery, IntPtr.Zero ); ! if (status == STRUCTURES.SUCCESS && pQuery != IntPtr.Zero) { try *************** *** 121,135 **** STRUCTURES.DNS_RECORD dnsRec; ArrayList tmp = new ArrayList(); ! for(IntPtr pDnsRec = pQuery; pDnsRec != IntPtr.Zero; pDnsRec = dnsRec.pNext) { dnsRec = (STRUCTURES.DNS_RECORD)Marshal.PtrToStructure(pDnsRec, typeof(STRUCTURES.DNS_RECORD)); ! if( dnsRec.wType == STRUCTURES.DNS_TYPE_MX ) { - IntPtr pMxData = new IntPtr( pDnsRec.ToInt32() + STRUCTURES.DNS_RECORD.SIZE ); // jump to mxrecord - STRUCTURES.DNS_MX_DATA mxdata = (STRUCTURES.DNS_MX_DATA)Marshal.PtrToStructure(pMxData, typeof(STRUCTURES.DNS_MX_DATA)); - tmp.Add(new MxRecord(String.Copy(mxdata.pNameExchange), (short)mxdata.wPreference)); - } - else break; // no additional record } --- 121,134 ---- STRUCTURES.DNS_RECORD dnsRec; ArrayList tmp = new ArrayList(); ! for (IntPtr pDnsRec = pQuery; pDnsRec != IntPtr.Zero; pDnsRec = dnsRec.pNext) { dnsRec = (STRUCTURES.DNS_RECORD)Marshal.PtrToStructure(pDnsRec, typeof(STRUCTURES.DNS_RECORD)); ! if (dnsRec.wType != STRUCTURES.DNS_TYPE_MX) { break; // no additional record + } + IntPtr pMxData = new IntPtr(pDnsRec.ToInt32() + STRUCTURES.DNS_RECORD.SIZE); // jump to mxrecord + STRUCTURES.DNS_MX_DATA mxdata = (STRUCTURES.DNS_MX_DATA)Marshal.PtrToStructure(pMxData, typeof(STRUCTURES.DNS_MX_DATA)); + tmp.Add(new MxRecord(String.Copy(mxdata.pNameExchange), (short)mxdata.wPreference)); } *************** *** 142,158 **** // Resolve bool err = false; ! for(int i = 0; i < mxs.Length; i++) { try { IPAddress[] ipx = NetDns.GetHostByName(mxs[i].NameExchange).AddressList; - if (ipx == null || ipx.Length == 0) continue; - foreach(IPAddress ipadr in ipx) mxs[i] += ipadr; } ! catch(SocketException se) { ! if (11004 == se.ErrorCode) ! continue; // The requested name is valid, but no data of the requested type was found } catch --- 141,160 ---- // Resolve bool err = false; ! for (int i = 0; i < mxs.Length; i++) { try { IPAddress[] ipx = NetDns.GetHostByName(mxs[i].NameExchange).AddressList; + if (ipx != null && ipx.Length != 0) + { + foreach (IPAddress ipadr in ipx) + mxs[i] += ipadr; + } } ! catch (SocketException se) { ! if (11004 != se.ErrorCode) ! throw; // The requested name is valid, but no data of the requested type was found } catch |