DnsResolver
public
final
class
DnsResolver
extends Object
java.lang.Object | |
↳ | android.net.DnsResolver |
Dns resolver class for asynchronous dns querying Note that if a client sends a query with more than 1 record in the question section but the remote dns server does not support this, it may not respond at all, leading to a timeout.
Summary
Nested classes | |
---|---|
interface |
DnsResolver.Callback<T>
Base interface for answer callbacks |
class |
DnsResolver.DnsException
Class to represent DNS error |
Constants | |
---|---|
int |
CLASS_IN
|
int |
ERROR_PARSE
Indicates that there was an error parsing the response the query. |
int |
ERROR_SYSTEM
Indicates that there was an error sending the query. |
int |
FLAG_EMPTY
|
int |
FLAG_NO_CACHE_LOOKUP
|
int |
FLAG_NO_CACHE_STORE
|
int |
FLAG_NO_RETRY
|
int |
TYPE_A
|
int |
TYPE_AAAA
|
Public methods | |
---|---|
static
DnsResolver
|
getInstance()
Get instance for DnsResolver |
void
|
query(Network network, String domain, int flags, Executor executor, CancellationSignal cancellationSignal, Callback<? super List<InetAddress>> callback)
Send a DNS query with the specified name on a network with both IPv4 and IPv6, get back a set of InetAddresses with rfc6724 sorting style asynchronously. |
void
|
query(Network network, String domain, int nsType, int flags, Executor executor, CancellationSignal cancellationSignal, Callback<? super List<InetAddress>> callback)
Send a DNS query with the specified name and query type, get back a set of InetAddresses with rfc6724 sorting style asynchronously. |
void
|
rawQuery(Network network, byte[] query, int flags, Executor executor, CancellationSignal cancellationSignal, Callback<? super byte[]> callback)
Send a raw DNS query. |
void
|
rawQuery(Network network, String domain, int nsClass, int nsType, int flags, Executor executor, CancellationSignal cancellationSignal, Callback<? super byte[]> callback)
Send a DNS query with the specified name, class and query type. |
Inherited methods | |
---|---|
Constants
ERROR_PARSE
public static final int ERROR_PARSE
Indicates that there was an error parsing the response the query.
The cause of this error is available via getCause() and is a ParseException
.
Constant Value: 0 (0x00000000)
ERROR_SYSTEM
public static final int ERROR_SYSTEM
Indicates that there was an error sending the query. The cause of this error is available via getCause() and is an ErrnoException.
Constant Value: 1 (0x00000001)
FLAG_NO_CACHE_LOOKUP
public static final int FLAG_NO_CACHE_LOOKUP
Constant Value: 4 (0x00000004)
FLAG_NO_CACHE_STORE
public static final int FLAG_NO_CACHE_STORE
Constant Value: 2 (0x00000002)
FLAG_NO_RETRY
public static final int FLAG_NO_RETRY
Constant Value: 1 (0x00000001)
Public methods
getInstance
public static DnsResolver getInstance ()
Get instance for DnsResolver
Returns | |
---|---|
DnsResolver |
This value cannot be null . |
query
public void query (Network network, String domain, int flags, Executor executor, CancellationSignal cancellationSignal, Callback<? super List<InetAddress>> callback)
Send a DNS query with the specified name on a network with both IPv4 and IPv6,
get back a set of InetAddresses with rfc6724 sorting style asynchronously.
This method will examine the connection ability on given network, and query IPv4
and IPv6 if connection is available.
If at least one query succeeded with valid answer, rcode will be 0
The answer will be provided asynchronously through the provided Callback
.
Parameters | |
---|---|
network |
Network : Network specifying which network to query on.
null for query on default network. |
domain |
String : domain name to query
This value cannot be null . |
flags |
int : flags as a combination of the FLAGS_* constants
Value is FLAG_EMPTY , FLAG_NO_RETRY , FLAG_NO_CACHE_STORE , or FLAG_NO_CACHE_LOOKUP |
executor |
Executor : The Executor that the callback should be executed on.
This value cannot be null .
Callback and listener events are dispatched through this
Executor , providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor() .
Otherwise, provide an Executor that dispatches to an appropriate thread. |
cancellationSignal |
CancellationSignal : used by the caller to signal if the query should be
cancelled. May be null . |
callback |
Callback : a Callback which will be called to notify the
caller of the result of dns query.
This value cannot be null . |
query
public void query (Network network, String domain, int nsType, int flags, Executor executor, CancellationSignal cancellationSignal, Callback<? super List<InetAddress>> callback)
Send a DNS query with the specified name and query type, get back a set of
InetAddresses with rfc6724 sorting style asynchronously.
The answer will be provided asynchronously through the provided Callback
.
Parameters | |
---|---|
network |
Network : Network specifying which network to query on.
null for query on default network. |
domain |
String : domain name to query
This value cannot be null . |
nsType |
int : dns resource record (RR) type as one of the TYPE_* constants
Value is TYPE_A , or TYPE_AAAA |
flags |
int : flags as a combination of the FLAGS_* constants
Value is FLAG_EMPTY , FLAG_NO_RETRY , FLAG_NO_CACHE_STORE , or FLAG_NO_CACHE_LOOKUP |
executor |
Executor : The Executor that the callback should be executed on.
This value cannot be null .
Callback and listener events are dispatched through this
Executor , providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor() .
Otherwise, provide an Executor that dispatches to an appropriate thread. |
cancellationSignal |
CancellationSignal : used by the caller to signal if the query should be
cancelled. May be null . |
callback |
Callback : a Callback which will be called to notify the caller
of the result of dns query.
This value cannot be null . |
rawQuery
public void rawQuery (Network network, byte[] query, int flags, Executor executor, CancellationSignal cancellationSignal, Callback<? super byte[]> callback)
Send a raw DNS query.
The answer will be provided asynchronously through the provided Callback
.
Parameters | |
---|---|
network |
Network : Network specifying which network to query on.
null for query on default network. |
query |
byte : blob message to query
This value cannot be null . |
flags |
int : flags as a combination of the FLAGS_* constants
Value is FLAG_EMPTY , FLAG_NO_RETRY , FLAG_NO_CACHE_STORE , or FLAG_NO_CACHE_LOOKUP |
executor |
Executor : The Executor that the callback should be executed on.
This value cannot be null .
Callback and listener events are dispatched through this
Executor , providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor() .
Otherwise, provide an Executor that dispatches to an appropriate thread. |
cancellationSignal |
CancellationSignal : used by the caller to signal if the query should be
cancelled. May be null . |
callback |
Callback : a Callback which will be called to notify the caller
of the result of dns query.
This value cannot be null . |
rawQuery
public void rawQuery (Network network, String domain, int nsClass, int nsType, int flags, Executor executor, CancellationSignal cancellationSignal, Callback<? super byte[]> callback)
Send a DNS query with the specified name, class and query type.
The answer will be provided asynchronously through the provided Callback
.
Parameters | |
---|---|
network |
Network : Network specifying which network to query on.
null for query on default network. |
domain |
String : domain name to query
This value cannot be null . |
nsClass |
int : dns class as one of the CLASS_* constants
Value is CLASS_IN |
nsType |
int : dns resource record (RR) type as one of the TYPE_* constants
Value is TYPE_A , or TYPE_AAAA |
flags |
int : flags as a combination of the FLAGS_* constants
Value is FLAG_EMPTY , FLAG_NO_RETRY , FLAG_NO_CACHE_STORE , or FLAG_NO_CACHE_LOOKUP |
executor |
Executor : The Executor that the callback should be executed on.
This value cannot be null .
Callback and listener events are dispatched through this
Executor , providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor() .
Otherwise, provide an Executor that dispatches to an appropriate thread. |
cancellationSignal |
CancellationSignal : used by the caller to signal if the query should be
cancelled. May be null . |
callback |
Callback : a Callback which will be called to notify the caller
of the result of dns query.
This value cannot be null . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-06-18 UTC.