public string getMXRecord(string s) { string rsl = ""; try { ArrayList dnsServers = new ArrayList(); dnsServers.Add(getLocalDnsAddresses()); DnsLite dl = new DnsLite(); dl.setDnsServers(dnsServers); ArrayList results; results = dl.getMXRecords(s); for (int i = 0; i < results.Count; i++) { MXRecord mx = (MXRecord)results[i]; rsl = mx.exchange; } results = null; } catch (Exception) { //Console.WriteLine("Caught exception : " + e); } return(rsl); }
//for un packing the byte array public ArrayList makeResponse() { ArrayList mxRecords = new ArrayList(); MXRecord mxRecord; //NOTE: we are ignoring the unnecessary fields. // and takes only the data required to build // MX records. int qCount = ((data[4] & 0xFF) << 8) | (data[5] & 0xFF); if (qCount < 0) { throw new IOException("invalid question count"); } int aCount = ((data[6] & 0xFF) << 8) | (data[7] & 0xFF); if (aCount < 0) { throw new IOException("invalid answer count"); } position = 12; for (int i = 0; i < qCount; ++i) { name = ""; position = proc(position); position += 4; } for (int i = 0; i < aCount; ++i) { name = ""; position = proc(position); position += 10; int pref = (data[position++] << 8) | (data[position++] & 0xFF); name = ""; position = proc(position); mxRecord = new MXRecord(); mxRecord.preference = pref; mxRecord.exchange = name; mxRecords.Add(mxRecord); } return(mxRecords); }