checkResponseCode(hdr);
ResourceRecords rrs = new ResourceRecords(msg, msg.length,
hdr, true);
if (rrs.getFirstAnsType() != ResourceRecord.TYPE_SOA)
{
throw new CommunicationException(
"DNS error: zone xfer doesn't begin with SOA");
}
if (rrs.answer.size() == 1
|| rrs.getLastAnsType() != ResourceRecord.TYPE_SOA)
{
// The response is split into multiple DNS messages.
do
{
msg = continueTcpQuery(tcp);
if (msg == null)
{
throw new CommunicationException(
"DNS error: incomplete zone transfer");
}
hdr = new Header(msg, msg.length);
checkResponseCode(hdr);
rrs.add(msg, msg.length, hdr);
} while (rrs.getLastAnsType() != ResourceRecord.TYPE_SOA);
}
// Delete the duplicate SOA record.
rrs.answer.removeElementAt(rrs.answer.size() - 1);
return rrs;
}
finally
{
tcp.close();
}
}
catch (IOException e)
{
caughtException = e;
}
catch (NameNotFoundException e)
{
throw e;
}
catch (NamingException e)
{
caughtException = e;
}
}
if (caughtException instanceof NamingException)
{
throw (NamingException) caughtException;
}
NamingException ne = new CommunicationException(
"DNS error during zone transfer");
ne.setRootCause(caughtException);
throw ne;
}