Create  Edit  FrontPage  Index  Search  Changes  History  RSS  Login

GLib::Resolver

class GLib::Resolver

GLib::Resolver provides cancellable synchronous and asynchronous DNS resolution, for hostnames (GLib::Resolver#lookup_by_address, GLib::Resolver#lookup_by_name and their async variants) and SRV (service) records (GLib::Resolver#lookup_service).

GLib::NetworkAddress and GLib::NetworkService provide wrappers around GLib::Resolver functionality that also implement GLib::SocketConnectable, making it easy to connect to a remote host/service.

Class Methods

GLib::Resolver.default
Gets the default GLib::Resolver.
GLib::Resolver.default=(resolver)
Same as GLib::Resolver#set_default.
  • Returns: resolver
GLib::Resolver.set_default(resolver)

Sets resolver to be the application's default resolver (reffing resolver, and unreffing the previous default resolver, if any). Future calls to GLib::Resolver#default will return this resolver.

This can be used if an application wants to perform any sort of DNS caching or “pinning”; it can implement its own GLib::Resolver that calls the original default resolver for DNS operations, and implements its own cache policies on top of that, and then set itself as the default resolver for all later code to use.

Instance Methods

lookup_by_address(address, cancellable = nil)

Synchronously reverse-resolves address to determine its associated hostname.

If the DNS resolution fails, a GLib::Resolver::Error will be raised.

If cancellable is non-nil, it can be used to cancel the operation, in which case a GLib::IO::CancelledError will be raised.

Since 2.22

  • address: The address to reverse-resolve
  • cancellable: A GLib::Cancellable, or nil
  • Returns: A hostname (either ASCII-only, or in ASCII-encoded form)
lookup_by_address_async(address, cancellable = nil){ |result| }

Begins asynchronously reverse-resolving address to determine its associated hostname, and eventually calls the passed block, which must call GLib::Resolver#lookup_by_address_finish to get the final result.

Since 2.22

lookup_by_address_finish(result)

Retrieves the result of a previous call to GLib::Resolver#lookup_by_address_async.

If the DNS resolution failed, a GLib::Resolver::Error will be raised. If the operation was cancelled, a GLib::IO::CancelledError will be raised.

Since 2.22

  • result: A GLib::AsyncResult
  • Returns: A hostname (either ASCII-only, or in ASCII-encoded form)
lookup_by_name(hostname, cancellable = nil)

Synchronously resolves hostname to determine its associated IP address(es). hostname may be an ASCII-only or UTF-8 hostname, or the textual form of an IP address (in which case this just becomes a wrapper around GLib::InetAddress.new_from_string.

On success, GLib::Resolver#lookup_by_name will return an Array of GLib::InetAddress objects, sorted in order of preference. (That is, you should attempt to connect to the first address first, then the second if the first fails, etc.)

If the DNS resolution fails, a GLib::Resolver::Error will be raised.

If cancellable is non-nil, it can be used to cancel the operation, in which case a GLib::IO::CancelledError will be raised.

If you are planning to connect to a socket on the resolved IP address, it may be easier to create a GLib::NetworkAddress and use its GLib::SocketConnectable interface.

Since 2.22

lookup_by_name_async(hostname, cancellable = nil){ |result| }

Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually calls the passed block, which must call GLib::Resolver#lookup_by_name_finish to get the result. See GLib::Resolver#lookup_by_name for more details.

Since 2.22

lookup_by_name_finish(result)

Retrieves the result of a call to GLib::Resolver#lookup_by_name_async.

If the DNS resolution failed, a GLib::Resolver::Error will be raised. If the operation was cancelled, a GLib::IO::CancelledError will be raised.

Since 2.22

lookup_service(service, protocol, domain, cancellable = nil)

Synchronously performs a DNS SRV lookup for the given service and protocol in the given domain and returns an array of GLib::SrvTarget. Domain may be an ASCII-only or UTF-8 hostname. Note also that the service and protocol arguments include the leading underscore that appears in the actual DNS entry.

On success, GLib::Resolver#lookup_service will return an Array of GLib::SrvTarget objects, sorted in order of preference. (That is, you should attempt to connect to the first target first, then the second if the first fails, etc.)

If the DNS resolution fails, a GLib::Resolver::Error will be raised.

If cancellable is non-nil, it can be used to cancel the operation, in which case a GLib::IO::CancelledError will be raised.

If you are planning to connect to the service, it is usually easier to create a GLib::NetworkService and use its GLib::SocketConnectable interface.

Since 2.22

  • service: The service type to look up (for example, “ldap”)
  • protocol: The networking protocol to use for service (for example, “tcp”)
  • domain: The DNS domain to look up the service in
  • cancellable: A GLib::Cancellable, or nil
  • Returns: An Array of GLib::SrvTarget objects
lookup_service_async(service, protocol, domain, cancellable = nil){ |result| }

Begins asynchronously performing a DNS SRV lookup for the given service and protocol in the given domain, and eventually calls the passed block, which must call GLib::Resolver#lookup_service_finish to get the final result. See GLib::Resolver#lookup_service for more details.

Since 2.22

  • service: The service type to look up (eg, "ldap")
  • protocol: The networking protocol to use for service (eg, "tcp")
  • domain: The DNS domain to look up the service in
  • cancellable: A GLib::Cancellable, or nil
  • result: A GLib::AsyncResult
  • Returns: self
lookup_service_finish(result)

Retrieves the result of a previous call to GLib::Resolver#lookup_service_async.

If the DNS resolution failed, a GLib::Resolver::Error will be raised. If the operation was cancelled, a GLib::IO::CancelledError will be raised.

Since 2.22