XMPP::NameResolver Class Reference

Performs a DNS lookup. More...

#include <netnames.h>

List of all members.

Public Types

enum  Mode { Single, LongLived }
enum  Error {
  ErrorGeneric, ErrorNoName, ErrorTimeout, ErrorNoLocal,
  ErrorNoLongLived
}

Signals

void resultsReady (const QList< XMPP::NameRecord > &results)
void error (XMPP::NameResolver::Error e)

Public Member Functions

 NameResolver (QObject *parent=0)
 ~NameResolver ()
void start (const QByteArray &name, NameRecord::Type type=NameRecord::A, Mode mode=Single)
void stop ()


Detailed Description

Performs a DNS lookup.

NameResolver performs an asynchronous DNS lookup for a given domain name and record type. Call start() to begin. The resultsReady() signal is emitted on success, otherwise error() is emitted. To cancel a lookup, call stop().

For example, here is how to obtain the IPv4 addresses of a domain name:

NameResolver *resolver;

void do_lookup()
{
        resolver = new NameResolver;
        connect(resolver, SIGNAL(resultsReady(const QList<XMPP::NameRecord> &)),
                SLOT(dns_resultsReady(const QList<XMPP::NameRecord> &)));
        connect(resolver, SIGNAL(error(XMPP::NameResolver::Error)),
                SLOT(dns_error(XMPP::NameResolver::Error)));

        // look up affinix.com
        resolver->start("affinix.com");
}

void dns_resultsReady(const QList<XMPP::NameRecord> &results)
{
        // print IP addresses
        foreach(NameRecord i, results)
                printf("%s\n", qPrintable(i.address().toString()));
}

void dns_error(XMPP::NameResolver::Error error)
{
        // handle error
        ...
}

Yes, a domain name can have multiple IP addresses. Many applications ignore this fact, and use only one of the answers. A proper network application should try connecting to each IP address until one succeeds.

To lookup other types, pass the desired type to start(). For example, suppose you want to look up the MX record of a domain name:

// look up the MX record for affinix.com
resolver->start("affinix.com", NameRecord::Mx);

It is also possible to perform long-lived queries. This is generally useful for DNS Service Discovery. Long-lived queries are continuous, and resultsReady() may be emitted multiple times. Unlike a normal lookup, which stops once the results are returned, a long-lived query will keep going until stop() is called.

For example, suppose you want to scan the local network for SSH services. According to the DNS-SD protocol, this is done by querying for the name "_ssh._tcp.local." of type PTR.

// monitor for SSH services on the local network
resolver->start("_ssh._tcp.local.", NameRecord::Ptr, NameResolver::LongLived);

Don't be alarmed by the trailing dot (".") character in this last example. It is not well known, but all valid DNS domain names end with a dot. However, NameResolver, like most DNS programming interfaces, allows the dot to be left out. What this means is that if a trailing dot is missing in the input to start(), NameResolver will internally append one before performing the query.

See also:
NameRecord


Member Enumeration Documentation

enum XMPP::NameResolver::Error
 

Resolve error.

Enumerator:
ErrorGeneric  General failure during lookup, no further details.
ErrorNoName  Name does not exist.
ErrorTimeout  The operation timed out.
ErrorNoLocal  The query is to the local network, but no mechanism for Multicast DNS is available.
ErrorNoLongLived  The query requires long-lived capability, but no mechanism for doing so is available.

enum XMPP::NameResolver::Mode
 

Resolve mode.

Enumerator:
Single  A normal DNS query with a single result set.
LongLived  An endless query, with multiple result sets allowed.


Constructor & Destructor Documentation

XMPP::NameResolver::NameResolver QObject *  parent = 0  ) 
 

Constructs a new resolver object with the given parent.

XMPP::NameResolver::~NameResolver  ) 
 

Destroys the resolver object.

The lookup is, of course, stopped.


Member Function Documentation

void XMPP::NameResolver::error XMPP::NameResolver::Error  e  )  [signal]
 

Notification of error.

This signal is emitted if an error has occurred while performing a lookup. The reason for error can be found in e. Regardless of the mode used, the lookup is stopped when an error occurs.

void XMPP::NameResolver::resultsReady const QList< XMPP::NameRecord > &  results  )  [signal]
 

Notification of result records.

This signal is emitted when results of the lookup operation have arrived. The results parameter is a list of NameRecords. All records will be of the type queried for with start(), unless the NameRecord::Any type was specified, in which case the records may be of any type

When using the NameResolver::Single mode, the lookup is stopped once results are ready. However, with the NameResolver::LongLived mode, the lookup stays active, and in that case this signal may be emitted multiple times.

void XMPP::NameResolver::start const QByteArray &  name,
NameRecord::Type  type = NameRecord::A,
Mode  mode = Single
 

Starts a lookup.

A lookup for name of type is started. For normal queries, mode should be NameResolver::Single (this is the default). For long-lived queries, use NameResolver::LongLived.

See also:
stop

void XMPP::NameResolver::stop  ) 
 

Stops a lookup.

Use this function if you want to stop the current lookup, such that the resolver object may be reused again later. If you don't plan to reuse the object, then destroying the object is enough.

See also:
start


The documentation for this class was generated from the following file:
Generated on Sun Mar 18 17:58:51 2007 for IrisNet by  doxygen 1.4.6