Package org.minidns.hla
Class ResolverApi
java.lang.Object
org.minidns.hla.ResolverApi
- Direct Known Subclasses:
DnssecResolverApi
The high-level MiniDNS resolving API. It is designed to be easy to use.
A simple exammple how to resolve the IPv4 address of a given domain:
ResolverResult<A> result = DnssecResolverApi.INSTANCE.resolve("verteiltesysteme.net", A.class);
if (!result.wasSuccessful()) {
RESPONSE_CODE responseCode = result.getResponseCode();
// Perform error handling.
…
return;
}
if (!result.isAuthenticData()) {
// Response was not secured with DNSSEC.
…
return;
}
Set<A> answers = result.getAnswers();
for (A a : answers) {
InetAddress inetAddress = a.getInetAddress();
// Do someting with the InetAddress, e.g. connect to.
…
}
MiniDNS also supports SRV resource records as first class citizens:
SrvResolverResult result = DnssecResolverApi.INSTANCE.resolveSrv(SrvType.xmpp_client, "example.org")
if (!result.wasSuccessful()) {
RESPONSE_CODE responseCode = result.getResponseCode();
// Perform error handling.
…
return;
}
if (!result.isAuthenticData()) {
// Response was not secured with DNSSEC.
…
return;
}
List<ResolvedSrvRecord> srvRecords = result.getSortedSrvResolvedAddresses();
// Loop over the domain names pointed by the SRV RR. MiniDNS will return the list
// correctly sorted by the priority and weight of the related SRV RR.
for (ResolvedSrvRecord srvRecord : srvRecord) {
// Loop over the Internet Address RRs resolved for the SRV RR. The order of
// the list depends on the prefered IP version setting of MiniDNS.
for (InternetAddressRR inetAddressRR : srvRecord.addresses) {
InetAddress inetAddress = inetAddressRR.getInetAddress();
int port = srvAddresses.port;
// Try to connect to inetAddress at port.
…
}
}
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal AbstractDnsClient
final <D extends Data>
ResolverResult<D> <D extends Data>
ResolverResult<D> final <D extends Data>
ResolverResult<D> resolveSrv
(String name) resolveSrv
(DnsLabel service, DnsLabel proto, DnsName name) resolveSrv
(DnsName srvDnsName) Resolve theSRV
resource record for the given name.resolveSrv
(DnsName name, SrvServiceProto srvServiceProto) Resolve theSRV
resource record for the given service name, service and protcol.resolveSrv
(SrvService service, SrvProto proto, String name) resolveSrv
(SrvService service, SrvProto proto, DnsName name) resolveSrv
(SrvType type, String serviceName) resolveSrv
(SrvType type, DnsName serviceName) reverseLookup
(CharSequence inetAddressCs) reverseLookup
(Inet4Address inet4Address) reverseLookup
(Inet6Address inet6Address) reverseLookup
(InetAddress inetAddress)
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
ResolverApi
-
-
Method Details
-
resolve
public final <D extends Data> ResolverResult<D> resolve(String name, Class<D> type) throws IOException - Throws:
IOException
-
resolve
public final <D extends Data> ResolverResult<D> resolve(DnsName name, Class<D> type) throws IOException - Throws:
IOException
-
resolve
- Throws:
IOException
-
resolveSrv
- Throws:
IOException
-
resolveSrv
- Throws:
IOException
-
resolveSrv
public SrvResolverResult resolveSrv(SrvService service, SrvProto proto, String name) throws IOException - Throws:
IOException
-
resolveSrv
public SrvResolverResult resolveSrv(SrvService service, SrvProto proto, DnsName name) throws IOException - Throws:
IOException
-
resolveSrv
public SrvResolverResult resolveSrv(DnsLabel service, DnsLabel proto, DnsName name) throws IOException - Throws:
IOException
-
resolveSrv
- Throws:
IOException
-
reverseLookup
- Throws:
IOException
-
reverseLookup
- Throws:
IOException
-
reverseLookup
- Throws:
IOException
-
reverseLookup
- Throws:
IOException
-
resolveSrv
Resolve theSRV
resource record for the given name. After ensuring that the resolution was successful withResolverResult.wasSuccessful()
, and, if DNSSEC was used, that the results could be verified withResolverResult.isAuthenticData()
, simply useSrvResolverResult.getSortedSrvResolvedAddresses()
to retrieve the resolved IP addresses.The name of SRV records is "_[service]._[protocol].[serviceDomain]", for example "_xmpp-client._tcp.example.org".
- Parameters:
srvDnsName
- the name to resolve.- Returns:
- a
SrvResolverResult
instance which can be used to retrieve the IP addresses. - Throws:
IOException
- if an IO exception occurs.
-
resolveSrv
public SrvResolverResult resolveSrv(DnsName name, SrvServiceProto srvServiceProto) throws IOException Resolve theSRV
resource record for the given service name, service and protcol. After ensuring that the resolution was successful withResolverResult.wasSuccessful()
, and, if DNSSEC was used, that the results could be verified withResolverResult.isAuthenticData()
, simply useSrvResolverResult.getSortedSrvResolvedAddresses()
to retrieve the resolved IP addresses.- Parameters:
name
- the DNS name of the service.srvServiceProto
- the service and protocol to lookup.- Returns:
- a
SrvResolverResult
instance which can be used to retrieve the IP addresses. - Throws:
IOException
- if an I/O error occurs.
-
getClient
-