Resolver


Object Hierarchy:

GLib.Resolver GLib.Resolver GLib.Resolver GLib.Object GLib.Object GLib.Object->GLib.Resolver

Description:

[ CCode ( type_id = "g_resolver_get_type ()" ) ]
public abstract class Resolver : Object

The object that handles DNS resolution.

Use [func@Gio.Resolver.get_default] to get the default resolver.

`GResolver` provides cancellable synchronous and asynchronous DNS resolution, for hostnames ([method@Gio.Resolver.lookup_by_address], [ method@Gio.Resolver.lookup_by_name] and their async variants) and SRV (service) records ([method@Gio.Resolver.lookup_service]).

[class@Gio.NetworkAddress] and [class@Gio.NetworkService] provide wrappers around `GResolver` functionality that also implement [ iface@Gio.SocketConnectable], making it easy to connect to a remote host/service.

The default resolver (see [func@Gio.Resolver.get_default]) has a timeout of 30s set on it since GLib 2.78. Earlier versions of GLib did not support resolver timeouts.

This is an abstract type; subclasses of it implement different resolvers for different platforms and situations.

Example: Resolver, lookup by name, sync:

public static int main () {
// Resolve hostname to IP address
try {
Resolver resolver = Resolver.get_default ();
List<InetAddress> addresses = resolver.lookup_by_name ("www.google.com", null);

// Example output:
// ``173.194.35.179``
// ``173.194.35.178``
// ``173.194.35.177``
// ``173.194.35.176``
// ``173.194.35.180``
// ``2a00:1450:4016:801::1013``
foreach (InetAddress address in addresses) {
print ("%s\n", address.to_string ());
}
} catch (Error e) {
print ("Error: %s\n", e.message);
}

return 0;
}

valac --pkg gio-2.0 GLib.Resolver.lookup_by_name.vala

Example: Resolver, lookup by name, async:

public static int main () {
MainLoop loop = new MainLoop ();

Resolver resolver = Resolver.get_default ();
resolver.lookup_by_name_async.begin ("www.google.com", null, (obj, res) => {
try {
// Example output:
// ``173.194.35.179``
// ``173.194.35.178``
// ``173.194.35.177``
// ``173.194.35.176``
// ``173.194.35.180``
// ``2a00:1450:4016:801::1013``
List<InetAddress> addresses = resolver.lookup_by_name_async.end (res);
foreach (InetAddress address in addresses) {
print ("%s\n", address.to_string ());
}
} catch (Error e) {
print ("Error: %s\n", e.message);
}

loop.quit ();
});

// Block until loop.quit is called:
loop.run ();
return 0;
}

valac --pkg gio-2.0 GLib.Resolver.lookup_by_name_async.vala

All known sub-classes:

Namespace: GLib
Package: gio-2.0

Content:

Properties:

Static methods:

Creation methods:

Methods:

Signals:

Inherited Members: