All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kendamasoft.dns.DnsConnection Maven / Gradle / Ivy

Go to download

Compact DNS client library intended primary for network utilities and testing applications

There is a newer version: 1.1.0
Show newest version
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