nsISupports
Last changed in Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)Implemented by: @mozilla.org/network/dns-service;1
. To access the service, use:
var dnsService = Components.classes["@mozilla.org/network/dns-service;1"] .createInstance(Components.interfaces.nsIDNSService);
Note: Starting in Gecko 7.0, the "happy eyeballs" strategy is used to reduce lengthy timeouts when attempting backup connections during attempts to connect from clients that have broken IPv6 connectivity. This is done by disabling IPv6 on backup connections.
nsICancelable asyncResolve(in AUTF8String aHostName, in unsigned long aFlags, in nsIDNSListener aListener, in nsIEventTarget aListenerTarget); |
void init(); Obsolete since Gecko 1.8 |
nsIDNSRecord resolve(in AUTF8String aHostName, in unsigned long aFlags); |
void shutdown(); Obsolete since Gecko 1.8 |
Attribute | Type | Description |
myHostName |
AUTF8String |
Read only. |
Various flags that may be ORed together to form the aFlags
parameter passed to asyncResolve()
and resolve()
.
Constant | Value | Description |
RESOLVE_BYPASS_CACHE |
(1 << 0) |
This flag suppresses the internal DNS lookup cache. |
RESOLVE_CANONICAL_NAME |
(1 << 1) |
The canonical name of the specified host will be queried. |
RESOLVE_PRIORITY_MEDIUM |
(1 << 2) |
The query is given medium priority. If used with low, medium takes precedence. |
RESOLVE_PRIORITY_LOW |
(1 << 3) |
The query is given lower priority. If used with medium, medium takes precedence. |
RESOLVE_SPECULATE |
(1 << 4) |
Indicates request is speculative. Speculative requests return errors if prefetching is disabled by configuration. |
RESOLVE_DISABLE_IPV6 |
(1 << 5) |
If this flag is set, only IPv4 addresses will be returned by asyncResolve() and resolve() . |
Begins off an asynchronous host lookup. A specified nsIDNSListener
is invoked when the resolution process is completed.
nsICancelable asyncResolve( in AUTF8String aHostName, in unsigned long aFlags, in nsIDNSListener aListener, in nsIEventTarget aListenerTarget );
aHostName
aFlags
aListener
aListenerTarget
null
). If not null
, this parameter specifies the nsIEventTarget
of the thread on which the listener's onLookupComplete should be called. If this parameter is null
, then onLookupComplete will be called on an unspecified thread (possibly recursively).An object that can be used to cancel the host lookup.
Called to initialize the DNS service.
void init();
None.
Called to synchronously resolve a host name. Warning this method may block the calling thread for a long period of time. It is extremely unwise to call this function on the User Interface thread of an application.
nsIDNSRecord resolve( in AUTF8String aHostName, in unsigned long aFlags );
aHostName
aFlags
DNS record corresponding to the given host name.
NS_ERROR_UNKNOWN_HOST
Called to shutdown the DNS service. Any pending asynchronous requests will be canceled, and the local cache of DNS records will be cleared.
void shutdown();
None.
let DnsService = Components.classes["@mozilla.org/network/dns-service;1"] .createInstance(Components.interfaces.nsIDNSService); let Thread = Components.classes["@mozilla.org/thread-manager;1"] .getService(Components.interfaces.nsIThreadManager).currentThread; let host = "www.mozilla.org"; let Listener = { onLookupComplete: function(request, record, status) { if (!Components.isSuccessCode(status)) { // Handle error here return; } let address = record.getNextAddrAsString(); console.log(host + " = " + address); } }; DnsService.asyncResolve(host, 0, Listener, Thread);