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
Resolver provides cancellable synchronous and asynchronous DNS resolution, for hostnames (
lookup_by_address ,
lookup_by_name and their async variants) and SRV (service) records
(lookup_service ).
NetworkAddress and NetworkService
provide wrappers around Resolver functionality that also implement
SocketConnectable , making it easy to connect to a remote host/service.
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
Content:
Static methods:
Creation methods:
Methods:
public virtual string lookup_by_address (InetAddress address, Cancellable ? cancellable = null ) throws Error
Synchronously reverse-resolves address
to determine its
associated hostname.
public virtual async string lookup_by_address_async (InetAddress address, Cancellable ? cancellable = null ) throws Error
Begins asynchronously reverse-resolving address
to
determine its associated hostname, and eventually calls callback
, which must call
lookup_by_address_async.end to get the final result.
public virtual List <InetAddress > lookup_by_name (string hostname, Cancellable ? cancellable = null ) throws Error
Synchronously resolves hostname
to determine its
associated IP address(es).
public virtual async List <InetAddress > lookup_by_name_async (string hostname, Cancellable ? cancellable = null ) throws Error
Begins asynchronously resolving hostname
to determine its
associated IP address(es), and eventually calls callback
, which must call
lookup_by_name_async.end to get the result.
public virtual List <InetAddress > lookup_by_name_with_flags (string hostname, ResolverNameLookupFlags flags, Cancellable ? cancellable = null ) throws Error
This differs from
lookup_by_name in that you can modify the lookup behavior with
flags
.
public virtual async List <InetAddress > lookup_by_name_with_flags_async (string hostname, ResolverNameLookupFlags flags, Cancellable ? cancellable = null ) throws Error
Begins asynchronously resolving hostname
to determine its
associated IP address(es), and eventually calls callback
, which must call
lookup_by_name_with_flags_async.end to get the result.
public virtual List <Variant > lookup_records (string rrname, ResolverRecordType record_type, Cancellable ? cancellable = null ) throws Error
Synchronously performs a DNS record lookup for the given rrname
and returns a list of records as Variant tuples.
public virtual async List <Variant > lookup_records_async (string rrname, ResolverRecordType record_type, Cancellable ? cancellable = null ) throws Error
Begins asynchronously performing a DNS lookup for the given
rrname
, and eventually calls callback
, which must call lookup_records_async.end
to get the final result.
public List <SrvTarget > lookup_service (string service, string protocol, string domain, Cancellable ? cancellable = null ) throws Error
Synchronously performs a DNS SRV lookup for the given service
and protocol
in the given domain
and returns an array of
SrvTarget .
public async List <SrvTarget > lookup_service_async (string service, string protocol, string domain, Cancellable ? cancellable = null ) throws Error
Begins asynchronously performing a DNS SRV lookup for the given
service
and protocol
in the given domain
, and eventually calls callback
, which must
call lookup_service_async.end to get the final result.
public virtual List <SrvTarget > lookup_service_fn (string rrname, Cancellable ? cancellable = null ) throws Error
public virtual async List <SrvTarget > lookup_service_fn_async (string rrname, Cancellable ? cancellable = null ) throws Error
public void set_default ()
Sets this to be the application's
default resolver (reffing this , and unreffing the previous default resolver, if any).
Signals:
Inherited Members:
All known members inherited from class GLib.Object
@get
@new
@ref
@set
add_toggle_ref
add_weak_pointer
bind_property
connect
constructed
disconnect
dispose
dup_data
dup_qdata
force_floating
freeze_notify
get_class
get_data
get_property
get_qdata
get_type
getv
interface_find_property
interface_install_property
interface_list_properties
is_floating
new_valist
new_with_properties
newv
notify
notify_property
ref_count
ref_sink
remove_toggle_ref
remove_weak_pointer
replace_data
replace_qdata
set_data
set_data_full
set_property
set_qdata
set_qdata_full
set_valist
setv
steal_data
steal_qdata
thaw_notify
unref
watch_closure
weak_ref
weak_unref