
com.kendamasoft.dns.DnsConnection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dns-client Show documentation
Show all versions of dns-client Show documentation
Compact DNS client library intended primary for network utilities and testing applications
package com.kendamasoft.dns;
import java.io.IOException;
/**
* Connection to DNS server
*
* @see DnsConnectionUdp
* @see DnsConnectionTcp
*/
abstract class DnsConnection {
/**
* Default DNS server port
*/
public static final int DNS_PORT = 53;
static final int SOCKET_TIMEOUT_MS = 5000;
static final byte[] googleDnsAddress = {8, 8, 8, 8};
public DnsProtocol.Message doRequest(DnsProtocol.Message request) throws IOException {
Buffer buffer = new Buffer();
buffer.write(request);
send(buffer.getData());
byte data[] = receive();
buffer = new Buffer(data);
DnsProtocol.Message response = buffer.readMessage();
if(response.header.returnCode() != 0) {
throw new IOException("Got response message error code: " + String.format("0x%01X", response.header.returnCode()));
}
return response;
}
protected abstract void send(byte[] request) throws IOException;
protected abstract byte[] receive() throws IOException;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy