Class Resolver.

Inherits Garbage

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

Reimplements Garbage::Garbage().

static EStringList Resolver::errors()

Returns a list of one-line error messages concerning all resolution errors since startup.

void Resolver::query( uint type, EStringList * results )

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.

EString Resolver::readString( uint & i )

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.

static EStringList Resolver::resolve( const EString & name )

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

static Resolver * Resolver::resolver()

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.