Aresolve provides asynchronous DNS host resolution.
Aresolve resolves and automatically re-resolves DNS information for requests made via the aresolve_handler’s watch_* methods. Whenever resolution information about the watched name changes, the aresolve_handler’s on_aresolve_host() function is called.
For example, an application may wish to track the IP address of a particular infrastructure hostname (e.g., a syslog receiver we’ll call “loghost”). In this example, an IP address object is created to track the current address of the loghost:
#include <assert.h> #include <eos/agent.h> #include <eos/aresolve.h> #include <eos/ip.h> #include <eos/sdk.h> class Aresolver : public eos::aresolve_handler, public eos::agent_handler { public: explicit Aresolver(eos::sdk & sdk) : eos::aresolve_handler(sdk.get_aresolve_mgr()), eos::agent_handler(sdk.get_agent_mgr()) { } void on_initialized() { // Register our interest in the IP address of "loghost" watch_host("loghost", true); } virtual void on_aresolve_host(eos::aresolve_record_host const & record) { // Called on initial host resolution or updates in host address if (record.valid()) { // We should only ever see results for "loghost". assert(record.qname() == "loghost"); // Get the IP address; we'll assume there's only one in this case. if (record.addr_v4().size() > 0) { // IPv4 address = record.addr_v4().front(); } else if (record.addr_v6().size() > 0) { // IPv6 address = record.addr_v6().front(); } // Do something with the new address, like send a syslog message. } else { // There was a host resolution error. Inspect record.last_error(), // which is an EAI_* error from netdb.h. } } private: eos::ip_addr_t address; };
The Aresolve handler.
This handler receives callback notifications about objects that are being resolved via watch_* calls.
Public Functions
Starts or stops watching IPv4 and IPv6 addresses for the provided host name.
When host resolution completes or an error occurs, on_aresolve_host() is called. After host resolution completes initially, watched hosts will be refreshed automatically. When changes in the result happen, your handler’s on_aresolve_host(), method is called. In this way, you need only watch hostnames you’re interested in and implement the on_aresolve_host() method to deal with the changes in results.
The hostname to watch
If true, start watching the hostname, else stop watching.
Callback called by Aresolve when host resolution completes.
Called by Aresolve when DNS resolution of a host previously watched by watch_host() completes.
Will be called upon successful updates or otherwise, when either the valid or last update time member attributes change. May be called more than once for a given hostname, if DNS had a temporary failure.
A record containing new or updated information about a watched host.
Public Functions
Aresolve implementation configuration settings.
The short time defines the minimum period between DNS resolutions. (default: 1s)
Returns the long timer, or seconds between repeated DNS queries.
You will receive at most one notification per DNS query (watched host) every aresolve_long_time() number of seconds. (default: 300s)
Sets the Aresolve short timer to the value provided.
Sets the Aresolve long timer to the value provided.
Protected Functions
Private Members
Friends
Warning
doxygenfile: Found multiple matches for file “eos/types/aresolve.h