vpr::sim::DNS Class Reference

Do lookups on addresses, giving results for each unique query. More...

#include <vpr/md/SIM/DNS.h>

Inheritance diagram for vpr::sim::DNS:

Inheritance graph
[legend]
Collaboration diagram for vpr::sim::DNS:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 DNS ()
vpr::Uint32 lookupAddress (const std::string &addr)
 Given an Internet name or dotted-decimal address, this returns the IP address in network byte order.

Protected Attributes

std::map< std::string, vpr::Uint32mDnsAddressLookup
 Use this to look up an address from a name.
vpr::Uint32 mUniqueGenerator

Detailed Description

Do lookups on addresses, giving results for each unique query.

Definition at line 64 of file DNS.h.


Constructor & Destructor Documentation

vpr::sim::DNS::DNS (  )  [inline]

Definition at line 67 of file DNS.h.

00067             : mUniqueGenerator(0)
00068       {
00069          mDnsAddressLookup["localhost"] = 0x7F000001;
00070       }


Member Function Documentation

vpr::Uint32 vpr::sim::DNS::lookupAddress ( const std::string &  addr  ) 

Given an Internet name or dotted-decimal address, this returns the IP address in network byte order.

Definition at line 57 of file DNS.cpp.

References mDnsAddressLookup, mUniqueGenerator, and vpr::SystemPosix::Ntohl().

00058 {
00059    vpr::Uint32 found_addr;
00060 
00061    // if name is found in lookup, return the address
00062    if ( mDnsAddressLookup.count(addr_str) > 0 )
00063    {
00064       found_addr = mDnsAddressLookup[addr_str];
00065    }
00066    // if not found, then make an entry for the new address.
00067    else
00068    {
00069       union
00070       {
00071          vpr::Uint8 bytes[4];
00072          vpr::Uint32 value;
00073       } addr;
00074       int retval;
00075 
00076       vpr::Uint32 temp1, temp2, temp3, temp4;
00077       retval = sscanf(addr_str.c_str(), "%3u.%3u.%3u.%3u", &temp1, &temp2,
00078                       &temp3, &temp4);
00079       addr.bytes[0] = (vpr::Uint8) temp1;
00080       addr.bytes[1] = (vpr::Uint8) temp2;
00081       addr.bytes[2] = (vpr::Uint8) temp3;
00082       addr.bytes[3] = (vpr::Uint8) temp4;
00083 
00084       if ( retval == 4 )
00085       {
00086          found_addr = vpr::System::Ntohl(addr.value);
00087       }
00088       else
00089       {
00090          found_addr = mUniqueGenerator++;
00091       }
00092 
00093       mDnsAddressLookup[addr_str] = found_addr;
00094    }
00095 
00096    return found_addr;
00097 }


Member Data Documentation

std::map< std::string, vpr::Uint32 > vpr::sim::DNS::mDnsAddressLookup [protected]

Use this to look up an address from a name.

Definition at line 81 of file DNS.h.

Referenced by lookupAddress().

vpr::Uint32 vpr::sim::DNS::mUniqueGenerator [protected]

Definition at line 83 of file DNS.h.

Referenced by lookupAddress().


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:56:11 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1