Async::DnsLookup Class Reference

A class for performing asynchronous DNS lookups. More...

#include <AsyncDnsLookup.h>

List of all members.

Public Member Functions

Public Attributes


Detailed Description

A class for performing asynchronous DNS lookups.

Author:
Tobias Blomberg
Date:
2003-04-12

Use this class to make DNS lookups. Right now it only supports looking up hostnames to find out what IP-addresses it maps to. An example usage can be seen below.

#include <iostream>
#include <AsyncCppApplication.h>
#include <AsyncDnsLookup.h>

using namespace std;
using namespace Async;

class MyClass : public SigC::Object
{
  public:
    MyClass(void)
    {
      cout << "Starting query of www.ibm.com...\n";
      dns_lookup = new DnsLookup("www.ibm.com");
      dns_lookup->resultsReady.connect(slot(*this, &MyClass::onResultsReady));
    }
    
    ~MyClass(void)
    {
      delete dns_lookup;
    }
    
    void onResultsReady(DnsLookup& dns)
    {
      cout << "Results received:\n";
      vector<IpAddress> addresses = dns.addresses();
      vector<IpAddress>::iterator it;
      for (it = addresses.begin(); it != addresses.end(); ++it)
      {
        cout << *it << endl;
      }
      
      delete dns_lookup;
      dns_lookup = 0;
      
      Application::app().quit();
    }
    
  private:
    DnsLookup *dns_lookup;
  
};

int main(int argc, char **argv)
{
  CppApplication app;
  MyClass dns;
  app.exec();
}
Examples:

AsyncDnsLookup_demo.cpp.

Definition at line 120 of file AsyncDnsLookup.h.


Constructor & Destructor Documentation

Async::DnsLookup::DnsLookup ( const std::string &  label  ) 

Constructor.

Parameters:
label The label (hostname) to lookup
Async::DnsLookup::~DnsLookup ( void   ) 

Destructor.


Member Function Documentation

std::vector<IpAddress> Async::DnsLookup::addresses ( void   ) 

Return the addresses for the host in the query.

Returns:
Return a stl vector which contains all the addresses associated with the hostname in the query.
Precondition:
The result is not available before the resultsReay signal has been emitted

Use this function to retrieve all the IP-addresses associated with the hostname in the query. If the list is empty, the query has failed.

Examples:
AsyncDnsLookup_demo.cpp.
const std::string& Async::DnsLookup::label ( void   )  const [inline]

Return the associated label.

Returns:
Returns the label associated with this DNS lookup

Definition at line 138 of file AsyncDnsLookup.h.


Member Data Documentation

A signal to indicate that the query has been completed.

Parameters:
dns A reference to the DNS object associated with the query

Definition at line 156 of file AsyncDnsLookup.h.


The documentation for this class was generated from the following file:
Generated by  doxygen 1.6.2-20100208