The Resolver class performs DNS lookups and caches the results until the process exits. It does not consider the TTLs on the DNS results.
The only public functions are resolve(), which does a cache lookup and failing that, a DNS lookup, and errors(), which returns a list of all errors seen so far. A server can ensure that it calls resolve() at startup time for all required names, and if errors() remains empty, all is well and remains well until the end of the process.
We need a class called Revolver.
Constructs an empty Resolver. This constructor is private; in general, Resolver is used via the static function resolve().
Returns a list of one-line error messages concerning all resolution errors since startup.
This private function issues a DNS query of type and appends the results to results. Truncated packets are silently accepted (the partial RR is ignored). type is passed through to ::res_query() unchanged.
Reads and returns a single string from the stored DNS reply at offset i, modifying i. If errors occur, an error is logged. If the parser runs off the end of the reply, readString() returns an empty string, but logs no error.
Resolves name and returns a list of results, or returns a cached list of results if resolve() has been called for name already.
name is assumed to be case-insensitive.
Any errors are added to an internal list and can be retrieved with errors().
This private helper ensures that there is a resolver, and returns a pointer to it.
This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.