(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.20 and 1.21

version 1.20, 2004/06/21 18:44:39 version 1.21, 2004/08/25 11:15:54
Line 30 
Line 30 
 //                              Ramnath Ravindran (Ramnath.Ravindran@compaq.com) 03/21/2002 //                              Ramnath Ravindran (Ramnath.Ravindran@compaq.com) 03/21/2002
 //                                      replaced instances of "| ios::binary" with //                                      replaced instances of "| ios::binary" with
 //                                      PEGASUS_OR_IOS_BINARY //                                      PEGASUS_OR_IOS_BINARY
   //              Robert Kieninger, IBM (kieningr@de.ibm.com) for Bug#667
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 42 
Line 43 
 #include <cctype>  // for tolower() #include <cctype>  // for tolower()
 #include <cstring> #include <cstring>
 #include "System.h" #include "System.h"
   #include "Socket.h"
   
   #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
   # include <windows.h>
   #else
   # include <arpa/inet.h>
   #endif
  
 #include <Pegasus/Common/PegasusVersion.h> #include <Pegasus/Common/PegasusVersion.h>
  
Line 148 
Line 156 
   return dirname;   return dirname;
 } }
  
   
   // ------------------------------------------------------------------------
   // Convert a hostname into a a single host unique integer representation
   // ------------------------------------------------------------------------
   Uint32 System::_acquireIP(const char* hostname)
   {
           Uint32 ip = 0xFFFFFFFF;
           if (!hostname) return 0xFFFFFFFF;
   
   #ifdef PEGASUS_OS_OS400
           char ebcdicHost[PEGASUS_MAXHOSTNAMELEN];
           if (strlen(hostname) < PEGASUS_MAXHOSTNAMELEN)
                   strcpy(ebcdicHost, hostname);
           else
                   return 0xFFFFFFFF;
           AtoE(ebcdicHost);
   #endif
   
           struct hostent *entry;
   
           if (isalpha(hostname[0]))
           {
   #ifdef PEGASUS_PLATFORM_SOLARIS_SPARC_CC
   #define HOSTENT_BUFF_SIZE        8192
                   char      buf[HOSTENT_BUFF_SIZE];
                   int       h_errorp;
                   struct    hostent hp;
   
                   entry = gethostbyname_r((char *)hostname, &hp, buf,
                                                                   HOSTENT_BUFF_SIZE, &h_errorp);
   #elif defined(PEGASUS_OS_OS400)
                   entry = gethostbyname(ebcdicHost);
   #elif defined(PEGASUS_OS_ZOS)
                   char hostName[ PEGASUS_MAXHOSTNAMELEN ];
                   if (String::equalNoCase("localhost",String(hostname)))
                   {
                           gethostname( hostName, PEGASUS_MAXHOSTNAMELEN );
                           entry = gethostbyname(hostName);
                   } else
                   {
                           entry = gethostbyname((char *)hostname);
                   }
   #else
                   entry = gethostbyname((char *)hostname);
   #endif
                   if (!entry)
                   {
                           return 0xFFFFFFFF;
                   }
                   unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
   
                   ip_part1 = entry->h_addr[0];
                   ip_part2 = entry->h_addr[1];
                   ip_part3 = entry->h_addr[2];
                   ip_part4 = entry->h_addr[3];
                   ip = ip_part1;
                   ip = (ip << 8) + ip_part2;
                   ip = (ip << 8) + ip_part3;
                   ip = (ip << 8) + ip_part4;
           } else
           {
                   // given hostname starts with an numeric character
                   // get address in network byte order
   #ifdef PEGASUS_OS_OS400
                   Uint32 tmp_addr = inet_addr(ebcdicHost);
   #elif defined(PEGASUS_OS_ZOS)
                   Uint32 tmp_addr = inet_addr_ebcdic((char *)hostname);
   #else
                   Uint32 tmp_addr = inet_addr((char *) hostname);
   #endif
   
                   // 0xFFFFFFF is same as -1 in an unsigned int32
                   if (tmp_addr == 0xFFFFFFFF)
                   {
                           // error, given ip does not follow format requirements
                           return 0xFFFFFFFF;
                   }
                   // resolve hostaddr to a real host entry
                   // casting to (const char *) as (char *) will work as (void *) too, those it fits all platforms
                   entry = gethostbyaddr((const char *) &tmp_addr, sizeof(tmp_addr), AF_INET);
   
                   if (entry == 0)
                   {
                           // error, couldn't resolve the ip
                           return 0xFFFFFFFF;
                   } else
                   {
   
                           unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
   
                           ip_part1 = entry->h_addr[0];
                           ip_part2 = entry->h_addr[1];
                           ip_part3 = entry->h_addr[2];
                           ip_part4 = entry->h_addr[3];
                           ip = ip_part1;
                           ip = (ip << 8) + ip_part2;
                           ip = (ip << 8) + ip_part3;
                           ip = (ip << 8) + ip_part4;
                   }
           }
   
           return ip;
   }
   
 // System ID constants for Logger::put and Logger::trace // System ID constants for Logger::put and Logger::trace
 const String System::CIMLISTENER = "cimlistener"; // Listener systme ID const String System::CIMLISTENER = "cimlistener"; // Listener systme ID
  


Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2