Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

DNS.cpp

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile: DNS.cpp,v $
00010  * Date modified: $Date: 2003/02/21 23:00:52 $
00011  * Version:       $Revision: 1.8 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #include <vpr/vprConfig.h>
00043 
00044 #include <stdio.h>
00045 
00046 #include <vpr/System.h>
00047 #include <vpr/Util/Debug.h>
00048 #include <vpr/md/SIM/DNS.h>
00049 
00050 
00051 namespace vpr
00052 {
00053 
00054 namespace sim
00055 {
00056 
00057 vpr::Uint32 DNS::lookupAddress (const std::string& addr_str)
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 }
00098 
00099 }
00100 
00101 }

Generated on Sun May 2 14:43:01 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002