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 InetAddress.newFromString).

On success, Resolver.lookupByName will return a non-empty GList of gio.InetAddress, sorted in order of preference and guaranteed to not contain duplicates. That is, if using the result to connect to hostname, you should attempt to connect to the first address first, then the second if the first fails, etc. If you are using the result to listen on a socket, it is appropriate to add each result using e.g. Socket.listenerAddAddress.

If the DNS resolution fails, error (if non-NULL) will be set to a value from GResolverError and NULL will be returned.

If cancellable is non-NULL, it can be used to cancel the operation, in which case error (if non-NULL) will be set to G_IO_ERROR_CANCELLED.

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

class Resolver


hostname string

the hostname to look up

cancellable Cancellable

a gio.Cancellable, or NULL

Return Value

Type: ListG

a non-empty GList of gio.InetAddress, or NULL on error. You must unref each of the addresses and free the list when you are done with it. (You can use Resolver.freeAddresses to do this.)


GException on failure.