use of org.xbill.DNS.Message in project opennms by OpenNMS.
the class DNSServer method buildErrorMessage.
byte[] buildErrorMessage(final Header header, final int rcode, final Record question) {
final Message response = new Message();
response.setHeader(header);
for (int i = 0; i < 4; i++) response.removeAllRecords(i);
if (rcode == Rcode.SERVFAIL)
response.addRecord(question, Section.QUESTION);
header.setRcode(rcode);
return response.toWire();
}
use of org.xbill.DNS.Message in project nhin-d by DirectProject.
the class DNSResponder method processError.
/**
* Processes a DNS error condition and creates an appropriate DNS response.
* @param request The original DNS request.
* @param error The error condition that occured.
* @return A response to the DNS request.
*/
protected Message processError(Message request, DNSError<?> error) {
Message errorResponse = null;
try {
Header respHeader = new Header(request.toWire());
Message response = new Message();
response.setHeader(respHeader);
for (int i = 0; i < 4; i++) response.removeAllRecords(i);
response.addRecord(request.getQuestion(), Section.QUESTION);
response.getHeader().setFlag(Flags.QR);
if (request.getHeader().getFlag(Flags.RD))
response.getHeader().setFlag(Flags.RD);
respHeader.setRcode(Integer.parseInt(error.getError().toString()));
return response;
} catch (IOException e) {
}
return errorResponse;
}
use of org.xbill.DNS.Message in project nhin-d by DirectProject.
the class DNSCertificateStore_lookupDNSTest method getPKIXAnswer.
protected Answer<Message> getPKIXAnswer(final byte[] certData) {
final Answer<Message> retVal = new Answer<Message>() {
public Message answer(InvocationOnMock invocation) throws Throwable {
final Message request = (Message) invocation.getArguments()[0];
final Message response = new Message(request.getHeader().getID());
response.getHeader().setFlag(Flags.QR);
if (request.getHeader().getFlag(Flags.RD))
response.getHeader().setFlag(Flags.RD);
response.addRecord(request.getQuestion(), Section.QUESTION);
if (certData != null) {
final CERTRecord rec = new CERTRecord(request.getQuestion().getName(), DClass.IN, 86400L, CERTRecord.PKIX, 0, 5, /*public key alg, RFC 4034*/
certData);
response.addRecord(rec, Section.ANSWER);
} else {
response.getHeader().setRcode(Rcode.NXDOMAIN);
}
// we are authoritative only
response.getHeader().setFlag(Flags.AA);
return response;
}
};
return retVal;
}
use of org.xbill.DNS.Message in project nhin-d by DirectProject.
the class DNSCertificateStore_lookupDNSTest method getIPKIXAnswer.
protected Answer<Message> getIPKIXAnswer(final String url) {
final Answer<Message> retVal = new Answer<Message>() {
public Message answer(InvocationOnMock invocation) throws Throwable {
final Message request = (Message) invocation.getArguments()[0];
final Message response = new Message(request.getHeader().getID());
response.getHeader().setFlag(Flags.QR);
if (request.getHeader().getFlag(Flags.RD))
response.getHeader().setFlag(Flags.RD);
response.addRecord(request.getQuestion(), Section.QUESTION);
final CERTRecord rec = new CERTRecord(request.getQuestion().getName(), DClass.IN, 86400L, CERTRecord.URI, 0, 5, /*public key alg, RFC 4034*/
url.getBytes());
response.addRecord(rec, Section.ANSWER);
// we are authoritative only
response.getHeader().setFlag(Flags.AA);
return response;
}
};
return retVal;
}
use of org.xbill.DNS.Message in project hadoop-pcap by RIPE-NCC.
the class DnsPcapReader method processPacketPayload.
@Override
protected void processPacketPayload(Packet packet, byte[] payload) {
String protocol = (String) packet.get(Packet.PROTOCOL);
if (!PcapReader.PROTOCOL_UDP.equals(protocol) && !PcapReader.PROTOCOL_TCP.equals(protocol))
return;
DnsPacket dnsPacket = (DnsPacket) packet;
if (DNS_PORT == (Integer) packet.get(Packet.SRC_PORT) || DNS_PORT == (Integer) packet.get(Packet.DST_PORT)) {
if (PROTOCOL_TCP.equals(protocol) && // TODO Support DNS responses with multiple messages (as used for XFRs)
payload.length > 2)
// First two bytes denote the size of the DNS message, ignore them
payload = Arrays.copyOfRange(payload, 2, payload.length);
try {
Message msg = new Message(payload);
Header header = msg.getHeader();
dnsPacket.put(DnsPacket.QUERYID, header.getID());
dnsPacket.put(DnsPacket.FLAGS, header.printFlags());
dnsPacket.put(DnsPacket.QR, header.getFlag(Flags.QR));
dnsPacket.put(DnsPacket.OPCODE, Opcode.string(header.getOpcode()));
dnsPacket.put(DnsPacket.RCODE, Rcode.string(header.getRcode()));
dnsPacket.put(DnsPacket.QUESTION, convertRecordToString(msg.getQuestion()));
dnsPacket.put(DnsPacket.QNAME, convertRecordOwnerToString(msg.getQuestion()));
dnsPacket.put(DnsPacket.QTYPE, convertRecordTypeToInt(msg.getQuestion()));
dnsPacket.put(DnsPacket.ANSWER, convertRecordsToStrings(msg.getSectionArray(Section.ANSWER)));
dnsPacket.put(DnsPacket.AUTHORITY, convertRecordsToStrings(msg.getSectionArray(Section.AUTHORITY)));
dnsPacket.put(DnsPacket.ADDITIONAL, convertRecordsToStrings(msg.getSectionArray(Section.ADDITIONAL)));
} catch (Exception e) {
// If we cannot decode a DNS packet we ignore it
}
}
}
Aggregations