(file) Return to System.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/System.cpp between version 1.43 and 1.44

version 1.43, 2006/10/31 19:47:32 version 1.44, 2006/11/10 18:14:58
Line 29 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (mbrasher@bmc.com)  
 //  
 // Modified By: Rudy Schuet (rudy.schuet@compaq.com) 11/12/01  
 //                  added nsk platform support  
 //              Ramnath Ravindran (Ramnath.Ravindran@compaq.com) 03/21/2002  
 //                  replaced instances of "| ios::binary" with  
 //                  PEGASUS_OR_IOS_BINARY  
 //              Robert Kieninger, IBM (kieningr@de.ibm.com) for Bug#667  
 //              Dave Sudlik, IBM (dsudlik@us.ibm.com) for Bug#1462  
 //              Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)  
 //              David Dillard, Symantec Corp. (david_dillard@symantec.com)  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
 #endif #endif
  
   
 #include <fstream> #include <fstream>
 #include <cctype>  // for tolower() #include <cctype>  // for tolower()
 #include <cstring> #include <cstring>
Line 277 
Line 264 
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 // This code used to check if the first character of "hostname" was alphabetic // This code used to check if the first character of "hostname" was alphabetic
 // to indicate hostname instead of IP address. But RFC 1123, section 2.1, relaxed  // to indicate hostname instead of IP address. But RFC 1123, section 2.1,
 // this requirement to alphabetic character *or* digit. So bug 1462 changed the  // relaxed this requirement to alphabetic character *or* digit. So bug 1462
 // flow here to call inet_addr first to check for a valid IP address in dotted  // changed the flow here to call inet_addr first to check for a valid IP
 // decimal notation. If it's not a valid IP address, then try to validate  // address in dotted decimal notation. If it's not a valid IP address, then
 // it as a hostname.  // try to validate it as a hostname.
 // RFC 1123 states: The host SHOULD check the string syntactically for a // RFC 1123 states: The host SHOULD check the string syntactically for a
 // dotted-decimal number before looking it up in the Domain Name System. // dotted-decimal number before looking it up in the Domain Name System.
 // Hence the call to inet_addr() first. // Hence the call to inet_addr() first.
Line 333 
Line 320 
             gethostname( hostName, PEGASUS_MAXHOSTNAMELEN );             gethostname( hostName, PEGASUS_MAXHOSTNAMELEN );
             hostName[sizeof(hostName)-1] = 0;             hostName[sizeof(hostName)-1] = 0;
             hostEntry = gethostbyname(hostName);             hostEntry = gethostbyname(hostName);
         } else          }
           else
         {         {
             hostEntry = gethostbyname((char *)hostname);             hostEntry = gethostbyname((char *)hostname);
         }         }
Line 358 
Line 346 
     else    // else hostname *is* a dotted-decimal IP address     else    // else hostname *is* a dotted-decimal IP address
         {         {
                 // resolve hostaddr to a real host entry                 // resolve hostaddr to a real host entry
                 // casting to (const char *) as (char *) will work as (void *) too, those it fits all platforms          // casting to (const char *) as (char *) will work as (void *) too,
           // those it fits all platforms
 #ifndef PEGASUS_OS_OS400 #ifndef PEGASUS_OS_OS400
         hostEntry = gethostbyaddr((const char *) &tmp_addr, sizeof(tmp_addr), AF_INET);          hostEntry =
               gethostbyaddr((const char *) &tmp_addr, sizeof(tmp_addr), AF_INET);
 #else #else
                 hostEntry = gethostbyaddr((char *) &tmp_addr, sizeof(tmp_addr), AF_INET);          hostEntry =
               gethostbyaddr((char *) &tmp_addr, sizeof(tmp_addr), AF_INET);
 #endif #endif
                 if (hostEntry == 0)                 if (hostEntry == 0)
                 {                 {
                         // error, couldn't resolve the ip                         // error, couldn't resolve the ip
                         return 0xFFFFFFFF;                         return 0xFFFFFFFF;
                 } else          }
           else
                 {                 {
   
                         unsigned char ip_part1,ip_part2,ip_part3,ip_part4;                         unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
  
                         ip_part1 = hostEntry->h_addr[0];                         ip_part1 = hostEntry->h_addr[0];
Line 447 
Line 438 
     return true;     return true;
 } }
  
 Boolean System::resolveHostNameAtDNS(const char* hostname, Uint32 * resolvedNameIP)  Boolean System::resolveHostNameAtDNS(
       const char* hostname,
       Uint32* resolvedNameIP)
 { {
     // ask the DNS for hostname resolution to IP address     // ask the DNS for hostname resolution to IP address
     // this can mean a time delay for as long as the DNS     // this can mean a time delay for as long as the DNS
Line 484 
Line 477 
     {     {
         // error, couldn't resolve the hostname to an ip address         // error, couldn't resolve the hostname to an ip address
         return false;         return false;
     } else      }
       else
     {     {
         unsigned char ip_part1,ip_part2,ip_part3,ip_part4;         unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
         ip_part1 = hostEntry->h_addr[0];         ip_part1 = hostEntry->h_addr[0];
Line 512 
Line 506 
                 {                 {
                         // error, couldn't resolve the ip                         // error, couldn't resolve the ip
                         return false;                         return false;
                 } else      }
       else
                 {                 {
                         unsigned char ip_part1,ip_part2,ip_part3,ip_part4;                         unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
                         ip_part1 = entry->h_addr[0];                         ip_part1 = entry->h_addr[0];
Line 570 
Line 565 
         {         {
         // localhost ?         // localhost ?
         if (String::equalNoCase(hostName,String("localhost"))) return true;         if (String::equalNoCase(hostName,String("localhost"))) return true;
         char* localHostName = strdup( (const char *) System::getHostName ().getCString() );          char* localHostName =
               strdup((const char*) System::getHostName().getCString());
         // given hostname equals what system returns as local hostname ?         // given hostname equals what system returns as local hostname ?
         if (String::equalNoCase(hostName,localHostName)) return true;         if (String::equalNoCase(hostName,localHostName)) return true;
         Uint32 hostIP;         Uint32 hostIP;
Line 582 
Line 578 
         // need to check if the local hosts name is possibly         // need to check if the local hosts name is possibly
         // registered at the DNS with the IP address equal resolvedNameIP         // registered at the DNS with the IP address equal resolvedNameIP
         Uint32 localHostIP;         Uint32 localHostIP;
         if (!System::resolveHostNameAtDNS(localHostName, &localHostIP)) return false;          if (!System::resolveHostNameAtDNS(localHostName, &localHostIP))
               return false;
         if (localHostIP == hostIP) return true;         if (localHostIP == hostIP) return true;
     } else      }
       else
     {   // hostname is an IP address     {   // hostname is an IP address
         // 127.0.0.1 is always the loopback         // 127.0.0.1 is always the loopback
         // inet_addr returns network byte order         // inet_addr returns network byte order
Line 594 
Line 592 
         // out of luck so far, lets ask the DNS what our IP is         // out of luck so far, lets ask the DNS what our IP is
         // and check against what we got         // and check against what we got
         Uint32 localHostIP;         Uint32 localHostIP;
         if (!System::resolveHostNameAtDNS((const char *) System::getHostName().getCString(), &localHostIP)) return false;          if (!System::resolveHostNameAtDNS(
                   (const char*) System::getHostName().getCString(), &localHostIP))
               return false;
         if (localHostIP == tmp_addr) return true;         if (localHostIP == tmp_addr) return true;
         // not yet, sometimes resolving the IP address we got against the DNS         // not yet, sometimes resolving the IP address we got against the DNS
         // can solve the problem         // can solve the problem
                 // casting to (const char *) as (char *) will work as (void *) too, those it fits all platforms          // casting to (const char *) as (char *) will work as (void *) too,
           // those it fits all platforms
         Uint32 hostIP;         Uint32 hostIP;
         if (!System::resolveIPAtDNS(tmp_addr, &hostIP)) return false;         if (!System::resolveIPAtDNS(tmp_addr, &hostIP)) return false;
         if (hostIP == localHostIP) return true;         if (hostIP == localHostIP) return true;


Legend:
Removed from v.1.43  
changed lines
  Added in v.1.44

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2