0025181: Incrementation of OCCT version up to 6.8.0.dev
[occt.git] / src / OSD / OSD_Host.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15#ifdef HAVE_CONFIG_H
16# include <config.h>
17#endif
18
19#ifndef WNT
20
21#include <Standard_NullObject.hxx>
22#include <Standard_ConstructionError.hxx>
23#include <OSD_Host.ixx>
24#include <OSD_WhoAmI.hxx>
25
26const OSD_WhoAmI Iam = OSD_WHost;
27
28#include <errno.h>
29
30#ifdef HAVE_SYS_UTSNAME_H
31# include <sys/utsname.h> // For 'uname'
32#endif
33
34#ifdef HAVE_NETDB_H
35# include <netdb.h> // This is for 'gethostbyname'
36#endif
37
38#include <stdio.h>
39
40#ifdef HAVE_SYS_IOCTL_H
41# include <sys/ioctl.h>
42#endif
43
44#if defined(__osf__) || defined(DECOSF1)
45#include <sys/types.h>
46#include <sys/sysinfo.h> // For 'getsysinfo'
47#include <sys/socket.h> // To get ethernet address
48#include <sys/ioctl.h>
49#include <net/if.h>
50extern "C" {
51 int gethostname(char* address, int len);
52}
53#endif
54
55#ifdef HAVE_SYSENT_H
56# include <sysent.h> // for 'gethostname'
57#endif
58
59#ifdef HAVE_SYS_SOCKET_H
60# include <sys/socket.h>
61#endif
62
63#ifdef HAVE_SYS_UNISTD_H
64# include <sys/unistd.h>
65#endif
66
67#ifdef HAVE_UNISTD_H
68# include <unistd.h>
69#endif
70
71#ifdef HAVE_SYS_SYSTEMINFO_H
72# include <sys/systeminfo.h>
73#endif
74
75extern "C" {int sysinfo(int, char *, long);}
76
77
78// =========================================================================
79
80OSD_Host::OSD_Host(){}
81
82// =========================================================================
83
84TCollection_AsciiString OSD_Host::SystemVersion(){
85struct utsname info;
86TCollection_AsciiString result;
87#ifdef HAVE_SYS_SYSTEMINFO_H
88char buf[100];
89#endif
90
91 uname (&info);
92 result = info.sysname;
93 result += " ";
94 result += info.release;
95#ifdef HAVE_SYS_SYSTEMINFO_H
96 result += " ";
97 sysinfo(SI_ARCHITECTURE,buf,99);
98 result += buf;
99 result += " ";
100 sysinfo(SI_HW_PROVIDER,buf,99);
101 result += buf;
102#endif
103 return(result);
104}
105
106// =========================================================================
107
108OSD_SysType OSD_Host::SystemId()const{
109struct utsname info;
110
111 uname (&info);
112
113 if (!strcmp(info.sysname,"SunOS")) return (OSD_UnixBSD);
114 if (!strcmp(info.sysname,"ULTRIX")) return (OSD_UnixBSD);
115 if (!strcmp(info.sysname,"FreeBSD")) return (OSD_UnixBSD);
116 if (!strncmp(info.sysname,"Linux",5)) return (OSD_LinuxREDHAT);
117 if (!strncmp(info.sysname,"IRIX", 4)) return (OSD_UnixSystemV);
118 if (!strncmp(info.sysname,"OSF", 3)) return (OSD_OSF);
119 if (!strcmp(info.sysname,"AIX")) return (OSD_Aix);
120 if (!strcmp(info.sysname,"UNIX_System_V")) return (OSD_UnixSystemV);
121 if (!strcmp(info.sysname,"VMS_POSIX")) return (OSD_VMS);
122 if (!strcmp(info.sysname,"Darwin")) return (OSD_MacOs);
123 return (OSD_Unknown);
124}
125
126// =========================================================================
127
128TCollection_AsciiString OSD_Host::HostName(){
129TCollection_AsciiString result;
130char value[65];
131int status;
132
133status = gethostname(value, 64);
134if (status == -1) myError.SetValue(errno, Iam, "Host Name");
135
136 result = value;
137 return(result);
138}
139
140
141// =========================================================================
142
143
144Standard_Integer OSD_Host::AvailableMemory(){
145 Standard_Integer result;
146
147#if defined(__osf__) || defined(DECOSF1)
148 char buffer[16];
149 //// result = getsysinfo(GSI_PHYSMEM,buffer, 16,0,NULL);
150 if (result != -1)
151 result *= 1024;
152#else
153 result = 0;
154 //@@ A faire
155#endif
156 return (result);
157}
158
159// =========================================================================
160
161TCollection_AsciiString OSD_Host::InternetAddress(){
162 struct hostent internet_address;
163 int a,b,c,d;
164 char buffer[16];
165 TCollection_AsciiString result,host;
166
167 host = HostName();
168 memcpy(&internet_address,
169 gethostbyname(host.ToCString()),
170 sizeof(struct hostent));
171
172 // Gets each bytes into integers
173 a = (unsigned char)internet_address.h_addr_list[0][0];
174 b = (unsigned char)internet_address.h_addr_list[0][1];
175 c = (unsigned char)internet_address.h_addr_list[0][2];
176 d = (unsigned char)internet_address.h_addr_list[0][3];
177 sprintf(buffer,"%d.%d.%d.%d",a,b,c,d);
178 result = buffer;
179 return(result);
180}
181
7fd59977 182// =========================================================================
183OSD_OEMType OSD_Host::MachineType(){
184struct utsname info;
185
186 uname (&info);
187
188 if (!strcmp(info.sysname,"SunOS")) return (OSD_SUN);
189 if (!strcmp(info.sysname,"ULTRIX")) return (OSD_DEC);
190 if (!strncmp(info.sysname,"IRIX",4)) return (OSD_SGI);
191 if (!strcmp(info.sysname,"HP-UX")) return (OSD_HP);
192 if (!strcmp(info.sysname,"UNIX_System_V")) return (OSD_NEC);
193 if (!strcmp(info.sysname,"VMS_POSIX")) return (OSD_VAX);
194 if (!strncmp(info.sysname,"OSF",3)) return (OSD_DEC);
195 if (!strncmp(info.sysname,"Linux",5)) return (OSD_LIN);
196 if (!strcmp(info.sysname,"FreeBSD")) return (OSD_LIN);
197 if (!strncmp(info.sysname,"AIX",3)) return (OSD_AIX);
198 if (!strcmp(info.sysname,"Darwin")) return (OSD_MAC);
199 return (OSD_Unavailable);
200
201}
202
203void OSD_Host::Reset(){
204 myError.Reset();
205}
206
207Standard_Boolean OSD_Host::Failed()const{
208 return( myError.Failed());
209}
210
211void OSD_Host::Perror() {
212 myError.Perror();
213}
214
215
216Standard_Integer OSD_Host::Error()const{
217 return( myError.Error());
218}
219
220#else
221
222//------------------------------------------------------------------------
223//------------------- WNT Sources of OSD_Host ---------------------------
224//------------------------------------------------------------------------
225
226#define STRICT
227#include <windows.h>
228
229#include <OSD_Host.hxx>
230
231#pragma comment( lib, "WSOCK32.LIB" )
232
233void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
234
235static BOOL fInit = FALSE;
236static TCollection_AsciiString hostName;
237static TCollection_AsciiString version;
238static TCollection_AsciiString interAddr;
7fd59977 239static Standard_Integer memSize;
240
241OSD_Host :: OSD_Host () {
242
243 DWORD nSize;
244 Standard_Character szHostName[ MAX_COMPUTERNAME_LENGTH + 1 ];
302f96fb 245 char* hostAddr = 0;
7fd59977 246 MEMORYSTATUS ms;
247 WSADATA wd;
248 PHOSTENT phe;
249 IN_ADDR inAddr;
250 OSVERSIONINFO osVerInfo;
251
252 if ( !fInit ) {
253
254 nSize = MAX_COMPUTERNAME_LENGTH + 1;
255 osVerInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
256
302f96fb 257 ZeroMemory (&ms, sizeof(ms));
8ec3edb0 258 ZeroMemory ( szHostName, sizeof ( Standard_Character ) * (MAX_COMPUTERNAME_LENGTH + 1) );
7fd59977 259
260 if ( !GetVersionEx ( &osVerInfo ) ) {
261
262 _osd_wnt_set_error ( myError, OSD_WHost );
263
264 } else if ( !GetComputerName ( szHostName, &nSize ) ) {
265
266 _osd_wnt_set_error ( myError, OSD_WHost );
267
268 } else {
269
270 ms.dwLength = sizeof ( MEMORYSTATUS );
271 GlobalMemoryStatus ( &ms );
272
273 } // end else
274
275 if ( !Failed () ) {
276
60be1f9b 277 memSize = (Standard_Integer) ms.dwAvailPageFile;
7fd59977 278
279 if ( WSAStartup ( MAKEWORD( 1, 1 ), &wd ) ) {
280
281 _osd_wnt_set_error ( myError, OSD_WHost );
282
283 } else if ( ( phe = gethostbyname ( szHostName ) ) == NULL ) {
284
285 _osd_wnt_set_error ( myError, OSD_WHost );
286
287 } else {
288
289 CopyMemory ( &inAddr, *phe -> h_addr_list, sizeof ( IN_ADDR ) );
290 hostAddr = inet_ntoa ( inAddr );
291
292 } // end else
293
294 } // end if
295
296 if ( !Failed () ) {
297
298 hostName = szHostName;
299 interAddr = Standard_CString ( hostAddr );
300 wsprintf (
301 osVerInfo.szCSDVersion, TEXT( "Windows NT Version %d.%d" ),
302 osVerInfo.dwMajorVersion, osVerInfo.dwMinorVersion
303 );
304 version = osVerInfo.szCSDVersion;
305
306 fInit = TRUE;
307
308 } // end if
309
310 } // end if
311
312 if ( fInit )
313
314 myName = hostName;
315
316} // end constructor
317
318TCollection_AsciiString OSD_Host :: SystemVersion () {
319
320 return version;
321
322} // end OSD_Host :: SystemVersion
323
324OSD_SysType OSD_Host :: SystemId () const {
325
326 return OSD_WindowsNT;
327
328} // end OSD_Host :: SystemId
329
330TCollection_AsciiString OSD_Host :: HostName () {
331
332 return hostName;
333
334} // end OSD_Host :: HostName
335
336Standard_Integer OSD_Host :: AvailableMemory () {
337
338 return memSize;
339
340} // end OSD_Host :: AvailableMemory
341
342TCollection_AsciiString OSD_Host :: InternetAddress () {
343
344 return interAddr;
345
346} // end OSD_Host :: InternetAddress
347
7fd59977 348OSD_OEMType OSD_Host :: MachineType () {
349
350 return OSD_PC;
351
352} // end OSD_Host :: MachineTYpe
353
354Standard_Boolean OSD_Host :: Failed () const {
355
356 return myError.Failed ();
357
358} // end OSD_Host :: Failed
359
360void OSD_Host :: Reset () {
361
362 myError.Reset ();
363
364} // end OSD_Host :: Reset
365
366void OSD_Host :: Perror () {
367
368 myError.Perror ();
369
370} // end OSD_Host :: Perror
371
372Standard_Integer OSD_Host :: Error () const {
373
374 return myError.Error ();
375
376} //end OSD_Host :: Error
377
378#endif
379
380
381
382
383