glibmm: Gio::Resolver Class Reference

glibmm 2.46.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Related Functions | List of all members
Gio::Resolver Class Reference
Portable Network I/O Functionality

Asynchronous and cancellable DNS resolver. More...

`#include <giomm/resolver.h>`

Inheritance diagram for Gio::Resolver:
[legend]

## Public Member Functions
| Resolver (Resolver&& src) noexcept
Resolver& | operator= (Resolver&& src) noexcept
virtual | ~Resolver () noexcept
GResolver* | gobj ()
| Provides access to the underlying C GObject. More...
const GResolver* | gobj () const
| Provides access to the underlying C GObject. More...
GResolver* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
Glib::ListHandle< Glib::RefPtr< InetAddress > > | lookup_by_name (const Glib::ustring& hostname, const Glib::RefPtr< Cancellable >& cancellable)
| Synchronously resolves hostname to determine its associated IP address(es). More...
Glib::ListHandle< Glib::RefPtr< InetAddress > > | lookup_by_name (const Glib::ustring& hostname)
| A lookup_by_name() convenience overload. More...
void | lookup_by_name_async (const Glib::ustring& hostname, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable)
| Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually calls slot, which must call lookup_by_name_finish() to get the result. More...
void | lookup_by_name_async (const Glib::ustring& hostname, const SlotAsyncReady& slot)
| Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually calls slot, which must call lookup_by_name_finish() to get the result. More...
Glib::ListHandle< Glib::RefPtr< InetAddress > > | lookup_by_name_finish (const Glib::RefPtr< AsyncResult >& result)
| Retrieves the result of a call to g_resolver_lookup_by_name_async(). More...
Glib::ustring | lookup_by_address (const Glib::RefPtr< InetAddress >& address, const Glib::RefPtr< Cancellable >& cancellable)
| Synchronously reverse-resolves address to determine its associated hostname. More...
Glib::ustring | lookup_by_address (const Glib::RefPtr< InetAddress >& address)
| A lookup_by_address() convenience overload. More...
void | lookup_by_address_async (const Glib::RefPtr< InetAddress >& address, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable)
| Begins asynchronously reverse-resolving an address to determine its associated hostname, and eventually calls callback, which must call lookup_by_address_finish() to get the final result. More...
void | lookup_by_address_async (const Glib::RefPtr< InetAddress >& address, const SlotAsyncReady& slot)
| Begins asynchronously reverse-resolving an address to determine its associated hostname, and eventually calls callback, which must call lookup_by_address_finish() to get the final result. More...
Glib::ustring | lookup_by_address_finish (const Glib::RefPtr< AsyncResult >& result)
| Retrieves the result of a previous call to g_resolver_lookup_by_address_async(). More...
ListHandle_SrvTarget | lookup_service (const Glib::ustring& service, const Glib::ustring& protocol, const Glib::ustring& domain, const Glib::RefPtr< Cancellable >& cancellable)
| Synchronously performs a DNS SRV lookup for the given service and protocol in the given domain and returns an array of SrvTarget. More...
ListHandle_SrvTarget | lookup_service (const Glib::ustring& service, const Glib::ustring& protocol, const Glib::ustring& domain)
| A lookup_service() convenience overload. More...
void | lookup_service_async (const Glib::ustring& service, const Glib::ustring& protocol, const Glib::ustring& domain, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable)
| 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_finish() to get the final result. More...
void | lookup_service_async (const Glib::ustring& service, const Glib::ustring& protocol, const Glib::ustring& domain, const SlotAsyncReady& slot)
| 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_finish() to get the final result. More...
ListHandle_SrvTarget | lookup_service_finish (const Glib::RefPtr< AsyncResult >& result)
| Retrieves the result of a previous call to g_resolver_lookup_service_async(). More...
std::vector< Glib::VariantContainerBase > | lookup_records (const Glib::ustring& rrname, ResolverRecordType record_type, const Glib::RefPtr< Cancellable >& cancellable)
| Synchronously performs a DNS record lookup for the given rrname and returns a list of records as Variant tuples. More...
std::vector< Glib::VariantContainerBase > | lookup_records (const Glib::ustring& rrname, ResolverRecordType record_type)
| A lookup_records() convenience overload. More...
void | lookup_records_async (const Glib::ustring& rrname, ResolverRecordType record_type, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable)
| Begins asynchronously performing a DNS lookup for the given rrname, and eventually calls slot, which must call lookup_records_finish() to get the final result. More...
void | lookup_records_async (const Glib::ustring& rrname, ResolverRecordType record_type, const SlotAsyncReady& slot)
| A non-cancellable version of lookup_records_async(). More...
std::vector< Glib::VariantContainerBase > | lookup_records_finish (const Glib::RefPtr< AsyncResult >& result)
| Retrieves the result of a previous call to g_resolver_lookup_records_async(). More...
Glib::SignalProxy0< void > | signal_reload ()
Public Member Functions inherited from Glib::Object
| Object (const Object&)=delete
Object& | operator= (const Object&)=delete
| Object (Object&& src) noexcept
Object& | operator= (Object&& src) noexcept
void* | get_data (const QueryQuark& key)
void | set_data (const Quark& key, void* data)
void | set_data (const Quark& key, void* data, DestroyNotify notify)
void | remove_data (const QueryQuark& quark)
void* | steal_data (const QueryQuark& quark)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase&)=delete
ObjectBase& | operator= (const ObjectBase&)=delete
void | set_property_value (const Glib::ustring& property_name, const Glib::ValueBase& value)
| You probably want to use a specific property_*() accessor method instead. More...
void | get_property_value (const Glib::ustring& property_name, Glib::ValueBase& value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | set_property (const Glib::ustring& property_name, const PropertyType& value)
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | get_property (const Glib::ustring& property_name, PropertyType& value) const
| You probably want to use a specific property_*() accessor method instead. More...
void | connect_property_changed (const Glib::ustring& property_name, const sigc::slot< void >& slot)
| You can use the signal_changed() signal of the property proxy instead, but this is necessary when using the reduced API. More...
sigc::connection | connect_property_changed_with_return (const Glib::ustring& property_name, const sigc::slot< void >& slot)
| You can use the signal_changed() signal of the property proxy instead, but this is necessary when using the reduced API. More...
void | freeze_notify ()
| Increases the freeze count on object. More...
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify(). More...
virtual void | reference () const
| Increment the reference count for this object. More...
virtual void | unreference () const
| Decrement the reference count for this object. More...
GObject* | gobj ()
| Provides access to the underlying C GObject. More...
const GObject* | gobj () const
| Provides access to the underlying C GObject. More...
GObject* | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access. More...
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src)
| ~trackable ()
void | add_destroy_notify_callback (void *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src)
void | remove_destroy_notify_callback (void *data) const

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...
static Glib::RefPtr< Resolver > | get_default ()
static void | set_default (const Glib::RefPtr< Resolver >& resolver)

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gio::Resolver > | wrap (GResolver* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...
Related Functions inherited from Glib::Object
Glib::RefPtr< Glib::Object > | wrap (GObject* object, bool take_copy=false)

## Additional Inherited Members
Public Types inherited from Glib::Object
typedef void(* | DestroyNotify) (gpointer data)
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams& construct_params)
| Object (GObject* castitem)
virtual | ~Object () noexcept
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
| ObjectBase (const char* custom_type_name)
| A derived constructor always overrides this choice. More...
| ObjectBase (const std::type_info& custom_type_info)
| This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
| ObjectBase (ObjectBase&& src) noexcept
ObjectBase& | operator= (ObjectBase&& src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject* castitem)
void | initialize_move (GObject* castitem, Glib::ObjectBase* previous_wrapper)

## Detailed Description

Asynchronous and cancellable DNS resolver.

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.

Since glibmm 2.24:

## Constructor & Destructor Documentation

Gio::Resolver::Resolver | ( | Resolver&& | src | ) |
| noexcept

virtual Gio::Resolver::~Resolver | ( |  | ) |
| virtualnoexcept

## Member Function Documentation

static Glib::RefPtr<Resolver> Gio::Resolver::get_default | ( |  | ) |
| static

static GType Gio::Resolver::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

GResolver* Gio::Resolver::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

const GResolver* Gio::Resolver::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

GResolver* Gio::Resolver::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

Glib::ustring Gio::Resolver::lookup_by_address | ( | const Glib::RefPtr< InetAddress >& | address,
|  | const Glib::RefPtr< Cancellable >& | cancellable
| ) |  |

Synchronously reverse-resolves address to determine its associated hostname.

If the DNS resolution fails, error (if non-`0`) will be set to a value from ResolverError.

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

Since glibmm 2.22:

Parameters

  address | The address to reverse-resolve.
  cancellable | A Cancellable, or `0`.

Returns
  A hostname (either ASCII-only, or in ASCII-encoded form), or `0` on error.

Glib::ustring Gio::Resolver::lookup_by_address | ( | const Glib::RefPtr< InetAddress >& | address | ) |

A lookup_by_address() convenience overload.

void Gio::Resolver::lookup_by_address_async | ( | const Glib::RefPtr< InetAddress >& | address,
|  | const SlotAsyncReady& | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable
| ) |  |

Begins asynchronously reverse-resolving an address to determine its associated hostname, and eventually calls callback, which must call lookup_by_address_finish() to get the final result.

Parameters

  address | The address to reverse-resolve.
  slot | A callback slot to call after the resolution completes.
  cancellable | A Cancellable object which can be used to cancel the operation.

void Gio::Resolver::lookup_by_address_async | ( | const Glib::RefPtr< InetAddress >& | address,
|  | const SlotAsyncReady& | slot
| ) |  |

Begins asynchronously reverse-resolving an address to determine its associated hostname, and eventually calls callback, which must call lookup_by_address_finish() to get the final result.

Parameters

  address | The address to reverse-resolve.
  slot | A callback slot to call after the resolution completes.

Glib::ustring Gio::Resolver::lookup_by_address_finish | ( | const Glib::RefPtr< AsyncResult >& | result | ) |

Retrieves the result of a previous call to g_resolver_lookup_by_address_async().

If the DNS resolution failed, error (if non-`0`) will be set to a value from ResolverError. If the operation was cancelled, error will be set to IO_ERROR_CANCELLED.

Since glibmm 2.22:

Parameters

  result | The result passed to your SlotAsyncReady.

Returns
  A hostname (either ASCII-only, or in ASCII-encoded form), or `0` on error.

Glib::ListHandle< Glib::RefPtr<InetAddress> > Gio::Resolver::lookup_by_name | ( | const Glib::ustring& | hostname,
|  | const Glib::RefPtr< Cancellable >& | cancellable
| ) |  |

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 g_inet_address_new_from_string()).

On success, g_resolver_lookup_by_name() will return a non-empty List of 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. g_socket_listener_add_address().

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

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

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

Since glibmm 2.22:

Parameters

  hostname | The hostname to look up.
  cancellable | A Cancellable, or `0`.

Returns
  A non-empty List of InetAddress, or `0` on error. You must unref each of the addresses and free the list when you are done with it. (You can use g_resolver_free_addresses() to do this.).

Glib::ListHandle< Glib::RefPtr<InetAddress> > Gio::Resolver::lookup_by_name | ( | const Glib::ustring& | hostname | ) |

A lookup_by_name() convenience overload.

void Gio::Resolver::lookup_by_name_async | ( | const Glib::ustring& | hostname,
|  | const SlotAsyncReady& | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable
| ) |  |

Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually calls slot, which must call lookup_by_name_finish() to get the result.

See lookup_by_name() for more details.

Parameters

  hostname | The hostname to look up.
  slot | A callback slot to call after the resolution completes.
  cancellable | A Cancellable object which can be used to cancel the operation.

void Gio::Resolver::lookup_by_name_async | ( | const Glib::ustring& | hostname,
|  | const SlotAsyncReady& | slot
| ) |  |

Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually calls slot, which must call lookup_by_name_finish() to get the result.

See lookup_by_name() for more details.

Parameters

  hostname | The hostname to look up.
  slot | A callback slot to call after the resolution completes.

Glib::ListHandle< Glib::RefPtr<InetAddress> > Gio::Resolver::lookup_by_name_finish | ( | const Glib::RefPtr< AsyncResult >& | result | ) |

Retrieves the result of a call to g_resolver_lookup_by_name_async().

If the DNS resolution failed, error (if non-`0`) will be set to a value from ResolverError. If the operation was cancelled, error will be set to IO_ERROR_CANCELLED.

Since glibmm 2.22:

Parameters

  result | The result passed to your SlotAsyncReady.

Returns
  A List of InetAddress, or `0` on error. See g_resolver_lookup_by_name() for more details.

std::vector<Glib::VariantContainerBase> Gio::Resolver::lookup_records | ( | const Glib::ustring& | rrname,
|  | ResolverRecordType | record_type,
|  | const Glib::RefPtr< Cancellable >& | cancellable
| ) |  |

Synchronously performs a DNS record lookup for the given rrname and returns a list of records as Variant tuples.

See ResolverRecordType for information on what the records contain for each record_type.

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

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

Since glibmm 2.34:

Parameters

  rrname | The DNS name to lookup the record for.
  record_type | The type of DNS record to lookup.
  cancellable | A Cancellable, or `0`.

Returns
  A non-empty List of Variant, or `0` on error. You must free each of the records and the list when you are done with it. (You can use Glib::list_free_full() with Glib::variant_unref() to do this.).

std::vector<Glib::VariantContainerBase> Gio::Resolver::lookup_records | ( | const Glib::ustring& | rrname,
|  | ResolverRecordType | record_type
| ) |  |

A lookup_records() convenience overload.

void Gio::Resolver::lookup_records_async | ( | const Glib::ustring& | rrname,
|  | ResolverRecordType | record_type,
|  | const SlotAsyncReady& | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable
| ) |  |

Begins asynchronously performing a DNS lookup for the given rrname, and eventually calls slot, which must call lookup_records_finish() to get the final result.

See lookup_records() for more details.

Parameters

  rrname | The DNS name to lookup the record for.
  record_type | The type of DNS record to lookup.
  cancellable | A Cancellable.
  slot | The slot to call after the resolution completes.

Since glibmm 2.36:

void Gio::Resolver::lookup_records_async | ( | const Glib::ustring& | rrname,
|  | ResolverRecordType | record_type,
|  | const SlotAsyncReady& | slot
| ) |  |

A non-cancellable version of lookup_records_async().

std::vector<Glib::VariantContainerBase> Gio::Resolver::lookup_records_finish | ( | const Glib::RefPtr< AsyncResult >& | result | ) |

Retrieves the result of a previous call to g_resolver_lookup_records_async().

Returns a non-empty list of records as Variant tuples. See ResolverRecordType for information on what the records contain.

If the DNS resolution failed, error (if non-`0`) will be set to a value from ResolverError. If the operation was cancelled, error will be set to IO_ERROR_CANCELLED.

Since glibmm 2.34:

Parameters

  result | The result passed to your SlotAsyncReady.

Returns
  A non-empty List of Variant, or `0` on error. You must free each of the records and the list when you are done with it. (You can use Glib::list_free_full() with Glib::variant_unref() to do this.).

ListHandle_SrvTarget Gio::Resolver::lookup_service | ( | const Glib::ustring& | service,
|  | const Glib::ustring& | protocol,
|  | const Glib::ustring& | domain,
|  | const Glib::RefPtr< Cancellable >& | cancellable
| ) |  |

Synchronously performs a DNS SRV lookup for the given service and protocol in the given domain and returns an array of SrvTarget.

domain may be an ASCII-only or UTF-8 hostname. Note also that the service and protocol arguments do not include the leading underscore that appears in the actual DNS entry.

On success, g_resolver_lookup_service() will return a non-empty List of SrvTarget, 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, error (if non-`0`) will be set to a value from ResolverError and `0` will be returned.

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

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

Since glibmm 2.22:

Parameters

  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 Cancellable, or `0`.

Returns
  A non-empty List of SrvTarget, or `0` on error. You must free each of the targets and the list when you are done with it. (You can use g_resolver_free_targets() to do this.).

ListHandle_SrvTarget Gio::Resolver::lookup_service | ( | const Glib::ustring& | service,
|  | const Glib::ustring& | protocol,
|  | const Glib::ustring& | domain
| ) |  |

A lookup_service() convenience overload.

void Gio::Resolver::lookup_service_async | ( | const Glib::ustring& | service,
|  | const Glib::ustring& | protocol,
|  | const Glib::ustring& | domain,
|  | const SlotAsyncReady& | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable
| ) |  |

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_finish() to get the final result.

See glookup_service() for more details.

Parameters

  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.
  slot | A callback slot to call after the resolution completes.
  cancellable | A Cancellable object which can be used to cancel the operation.

void Gio::Resolver::lookup_service_async | ( | const Glib::ustring& | service,
|  | const Glib::ustring& | protocol,
|  | const Glib::ustring& | domain,
|  | const SlotAsyncReady& | slot
| ) |  |

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_finish() to get the final result.

See glookup_service() for more details.

Parameters

  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.
  slot | A callback slot to call after the resolution completes.

ListHandle_SrvTarget Gio::Resolver::lookup_service_finish | ( | const Glib::RefPtr< AsyncResult >& | result | ) |

Retrieves the result of a previous call to g_resolver_lookup_service_async().

If the DNS resolution failed, error (if non-`0`) will be set to a value from ResolverError. If the operation was cancelled, error will be set to IO_ERROR_CANCELLED.

Since glibmm 2.22:

Parameters

  result | The result passed to your SlotAsyncReady.

Returns
  A non-empty List of SrvTarget, or `0` on error. See g_resolver_lookup_service() for more details.

Resolver& Gio::Resolver::operator= | ( | Resolver&& | src | ) |
| noexcept

static void Gio::Resolver::set_default | ( | const Glib::RefPtr< Resolver >& | resolver | ) |
| static

Glib::SignalProxy0< void > Gio::Resolver::signal_reload | ( |  | ) |

Slot Prototype:
  `void on_my_reload()`

Emitted when the resolver notices that the system resolver configuration has changed.

## Friends And Related Function Documentation

Glib::RefPtr< Gio::Resolver > wrap | ( | GResolver * | object,
|  | bool | take_copy = `false`
| ) |  |
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.