1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
25 #include <Standard_NullObject.hxx>
26 #include <Standard_ConstructionError.hxx>
27 #include <OSD_Host.ixx>
28 #include <OSD_WhoAmI.hxx>
30 const OSD_WhoAmI Iam = OSD_WHost;
34 #ifdef HAVE_SYS_UTSNAME_H
35 # include <sys/utsname.h> // For 'uname'
39 # include <netdb.h> // This is for 'gethostbyname'
44 #ifdef HAVE_SYS_IOCTL_H
45 # include <sys/ioctl.h>
48 #if defined(__osf__) || defined(DECOSF1)
49 #include <sys/types.h>
50 #include <sys/sysinfo.h> // For 'getsysinfo'
51 #include <sys/socket.h> // To get ethernet address
52 #include <sys/ioctl.h>
55 int gethostname(char* address, int len);
60 # include <sysent.h> // for 'gethostname'
63 #ifdef HAVE_SYS_SOCKET_H
64 # include <sys/socket.h>
67 #ifdef HAVE_SYS_UNISTD_H
68 # include <sys/unistd.h>
75 #ifdef HAVE_SYS_SYSTEMINFO_H
76 # include <sys/systeminfo.h>
79 extern "C" {int sysinfo(int, char *, long);}
82 // =========================================================================
84 OSD_Host::OSD_Host(){}
86 // =========================================================================
88 TCollection_AsciiString OSD_Host::SystemVersion(){
90 TCollection_AsciiString result;
91 #ifdef HAVE_SYS_SYSTEMINFO_H
96 result = info.sysname;
98 result += info.release;
99 #ifdef HAVE_SYS_SYSTEMINFO_H
101 sysinfo(SI_ARCHITECTURE,buf,99);
104 sysinfo(SI_HW_PROVIDER,buf,99);
110 // =========================================================================
112 OSD_SysType OSD_Host::SystemId()const{
117 if (!strcmp(info.sysname,"SunOS")) return (OSD_UnixBSD);
118 if (!strcmp(info.sysname,"ULTRIX")) return (OSD_UnixBSD);
119 if (!strcmp(info.sysname,"FreeBSD")) return (OSD_UnixBSD);
120 if (!strncmp(info.sysname,"Linux",5)) return (OSD_LinuxREDHAT);
121 if (!strncmp(info.sysname,"IRIX", 4)) return (OSD_UnixSystemV);
122 if (!strncmp(info.sysname,"OSF", 3)) return (OSD_OSF);
123 if (!strcmp(info.sysname,"AIX")) return (OSD_Aix);
124 if (!strcmp(info.sysname,"UNIX_System_V")) return (OSD_UnixSystemV);
125 if (!strcmp(info.sysname,"VMS_POSIX")) return (OSD_VMS);
126 if (!strcmp(info.sysname,"Darwin")) return (OSD_MacOs);
127 return (OSD_Unknown);
130 // =========================================================================
132 TCollection_AsciiString OSD_Host::HostName(){
133 TCollection_AsciiString result;
137 status = gethostname(value, 64);
138 if (status == -1) myError.SetValue(errno, Iam, "Host Name");
145 // =========================================================================
148 Standard_Integer OSD_Host::AvailableMemory(){
149 Standard_Integer result;
151 #if defined(__osf__) || defined(DECOSF1)
153 //// result = getsysinfo(GSI_PHYSMEM,buffer, 16,0,NULL);
163 // =========================================================================
165 TCollection_AsciiString OSD_Host::InternetAddress(){
166 struct hostent internet_address;
169 TCollection_AsciiString result,host;
172 memcpy(&internet_address,
173 gethostbyname(host.ToCString()),
174 sizeof(struct hostent));
176 // Gets each bytes into integers
177 a = (unsigned char)internet_address.h_addr_list[0][0];
178 b = (unsigned char)internet_address.h_addr_list[0][1];
179 c = (unsigned char)internet_address.h_addr_list[0][2];
180 d = (unsigned char)internet_address.h_addr_list[0][3];
181 sprintf(buffer,"%d.%d.%d.%d",a,b,c,d);
186 // =========================================================================
187 OSD_OEMType OSD_Host::MachineType(){
192 if (!strcmp(info.sysname,"SunOS")) return (OSD_SUN);
193 if (!strcmp(info.sysname,"ULTRIX")) return (OSD_DEC);
194 if (!strncmp(info.sysname,"IRIX",4)) return (OSD_SGI);
195 if (!strcmp(info.sysname,"HP-UX")) return (OSD_HP);
196 if (!strcmp(info.sysname,"UNIX_System_V")) return (OSD_NEC);
197 if (!strcmp(info.sysname,"VMS_POSIX")) return (OSD_VAX);
198 if (!strncmp(info.sysname,"OSF",3)) return (OSD_DEC);
199 if (!strncmp(info.sysname,"Linux",5)) return (OSD_LIN);
200 if (!strcmp(info.sysname,"FreeBSD")) return (OSD_LIN);
201 if (!strncmp(info.sysname,"AIX",3)) return (OSD_AIX);
202 if (!strcmp(info.sysname,"Darwin")) return (OSD_MAC);
203 return (OSD_Unavailable);
207 void OSD_Host::Reset(){
211 Standard_Boolean OSD_Host::Failed()const{
212 return( myError.Failed());
215 void OSD_Host::Perror() {
220 Standard_Integer OSD_Host::Error()const{
221 return( myError.Error());
226 //------------------------------------------------------------------------
227 //------------------- WNT Sources of OSD_Host ---------------------------
228 //------------------------------------------------------------------------
233 #include <OSD_Host.hxx>
235 #pragma comment( lib, "WSOCK32.LIB" )
237 void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
239 static BOOL fInit = FALSE;
240 static TCollection_AsciiString hostName;
241 static TCollection_AsciiString version;
242 static TCollection_AsciiString interAddr;
243 static Standard_Integer memSize;
245 OSD_Host :: OSD_Host () {
248 Standard_Character szHostName[ MAX_COMPUTERNAME_LENGTH + 1 ];
254 OSVERSIONINFO osVerInfo;
258 nSize = MAX_COMPUTERNAME_LENGTH + 1;
259 osVerInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
261 ZeroMemory ( szHostName, sizeof ( hostName ) );
263 if ( !GetVersionEx ( &osVerInfo ) ) {
265 _osd_wnt_set_error ( myError, OSD_WHost );
267 } else if ( !GetComputerName ( szHostName, &nSize ) ) {
269 _osd_wnt_set_error ( myError, OSD_WHost );
273 ms.dwLength = sizeof ( MEMORYSTATUS );
274 GlobalMemoryStatus ( &ms );
280 memSize = (Standard_Integer) ms.dwAvailPageFile;
282 if ( WSAStartup ( MAKEWORD( 1, 1 ), &wd ) ) {
284 _osd_wnt_set_error ( myError, OSD_WHost );
286 } else if ( ( phe = gethostbyname ( szHostName ) ) == NULL ) {
288 _osd_wnt_set_error ( myError, OSD_WHost );
292 CopyMemory ( &inAddr, *phe -> h_addr_list, sizeof ( IN_ADDR ) );
293 hostAddr = inet_ntoa ( inAddr );
301 hostName = szHostName;
302 interAddr = Standard_CString ( hostAddr );
304 osVerInfo.szCSDVersion, TEXT( "Windows NT Version %d.%d" ),
305 osVerInfo.dwMajorVersion, osVerInfo.dwMinorVersion
307 version = osVerInfo.szCSDVersion;
321 TCollection_AsciiString OSD_Host :: SystemVersion () {
325 } // end OSD_Host :: SystemVersion
327 OSD_SysType OSD_Host :: SystemId () const {
329 return OSD_WindowsNT;
331 } // end OSD_Host :: SystemId
333 TCollection_AsciiString OSD_Host :: HostName () {
337 } // end OSD_Host :: HostName
339 Standard_Integer OSD_Host :: AvailableMemory () {
343 } // end OSD_Host :: AvailableMemory
345 TCollection_AsciiString OSD_Host :: InternetAddress () {
349 } // end OSD_Host :: InternetAddress
351 OSD_OEMType OSD_Host :: MachineType () {
355 } // end OSD_Host :: MachineTYpe
357 Standard_Boolean OSD_Host :: Failed () const {
359 return myError.Failed ();
361 } // end OSD_Host :: Failed
363 void OSD_Host :: Reset () {
367 } // end OSD_Host :: Reset
369 void OSD_Host :: Perror () {
373 } // end OSD_Host :: Perror
375 Standard_Integer OSD_Host :: Error () const {
377 return myError.Error ();
379 } //end OSD_Host :: Error