//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); }
//for unpacking the byte array public static 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; }