~ubuntu-branches/ubuntu/maverick/vmware-view-open-client/maverick

« back to all changes in this revision

Viewing changes to lib/open-vm-tools/misc/hostinfo_misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2010-06-04 17:45:04 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20100604174504-zjltuc0hdp4mv7de
Tags: 4.5.0-264434+dfsg-1
* Merging upstream version 4.5.0-264434+dfsg.
* Updating date and version header in manpage.
* Rediffing doc-pdf.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*********************************************************
2
 
 * Copyright (C) 1998 VMware, Inc. All rights reserved.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify it
5
 
 * under the terms of the GNU Lesser General Public License as published
6
 
 * by the Free Software Foundation version 2.1 and no later version.
7
 
 *
8
 
 * This program is released with an additional exemption that
9
 
 * compiling, linking, and/or using the OpenSSL libraries with this
10
 
 * program is allowed.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful, but
13
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
 
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
15
 
 * License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Lesser General Public License
18
 
 * along with this program; if not, write to the Free Software Foundation, Inc.,
19
 
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
20
 
 *
21
 
 *********************************************************/
22
 
 
23
 
#include <stdio.h>
24
 
#include <stdlib.h>
25
 
 
26
 
#if defined(_WIN32)
27
 
#include <windows.h>
28
 
#include <winbase.h>
29
 
#else
30
 
#include <string.h>
31
 
#include <errno.h>
32
 
#include <sys/time.h>
33
 
#include <sys/utsname.h>
34
 
#endif
35
 
 
36
 
#include "vmware.h"
37
 
#include "hostinfo.h"
38
 
#include "safetime.h"
39
 
#include "str.h"
40
 
 
41
 
static Bool hostinfoOSVersionInitialized;
42
 
 
43
 
#if defined(_WIN32)
44
 
static int hostinfoOSVersion[4];
45
 
static DWORD hostinfoOSPlatform;
46
 
#else
47
 
#if defined(__APPLE__)
48
 
#define SYS_NMLN _SYS_NAMELEN
49
 
#endif
50
 
static int hostinfoOSVersion[3];
51
 
static char hostinfoOSVersionString[SYS_NMLN];
52
 
#endif
53
 
 
54
 
 
55
 
#if defined(_WIN32)
56
 
/*
57
 
 *----------------------------------------------------------------------
58
 
 *
59
 
 * HostinfoOSVersionInit --
60
 
 *
61
 
 *      Compute the OS version information
62
 
 *
63
 
 * Results:
64
 
 *      None.
65
 
 *
66
 
 * Side effects:
67
 
 *      hostinfoOS* variables are filled in.
68
 
 *
69
 
 *----------------------------------------------------------------------
70
 
 */
71
 
 
72
 
void
73
 
HostinfoOSVersionInit(void)
74
 
{
75
 
   OSVERSIONINFO info;
76
 
   OSVERSIONINFOEX infoEx;
77
 
 
78
 
   if (hostinfoOSVersionInitialized) {
79
 
      return;
80
 
   }
81
 
 
82
 
   info.dwOSVersionInfoSize = sizeof (info);
83
 
   if (!GetVersionEx(&info)) {
84
 
      Warning("Unable to get OS version.\n");
85
 
      NOT_IMPLEMENTED();
86
 
   }
87
 
   ASSERT(ARRAYSIZE(hostinfoOSVersion) >= 4);
88
 
   hostinfoOSVersion[0] = info.dwMajorVersion;
89
 
   hostinfoOSVersion[1] = info.dwMinorVersion;
90
 
   hostinfoOSVersion[2] = info.dwBuildNumber & 0xffff;
91
 
   /*
92
 
    * Get the service pack number. We don't care much about NT4 hosts
93
 
    * so we can use OSVERSIONINFOEX without checking for Windows NT 4.0 SP6 
94
 
    * or later versions.
95
 
    */
96
 
   infoEx.dwOSVersionInfoSize = sizeof infoEx;
97
 
   if (GetVersionEx((OSVERSIONINFO*)&infoEx)) {
98
 
      hostinfoOSVersion[3] = infoEx.wServicePackMajor;
99
 
   }
100
 
   hostinfoOSPlatform = info.dwPlatformId;
101
 
 
102
 
   hostinfoOSVersionInitialized = TRUE;
103
 
}
104
 
 
105
 
 
106
 
/*
107
 
 *----------------------------------------------------------------------
108
 
 *
109
 
 * Hostinfo_OSIsWinNT --
110
 
 *
111
 
 *      This is Windows NT or descendant.
112
 
 *
113
 
 * Results:
114
 
 *      TRUE if Windows NT or descendant.
115
 
 *
116
 
 * Side effects:
117
 
 *      None.
118
 
 *
119
 
 *----------------------------------------------------------------------
120
 
 */
121
 
 
122
 
Bool
123
 
Hostinfo_OSIsWinNT(void)
124
 
{
125
 
   HostinfoOSVersionInit();
126
 
   return hostinfoOSPlatform == VER_PLATFORM_WIN32_NT;
127
 
}
128
 
#else
129
 
 
130
 
 
131
 
/*
132
 
 *----------------------------------------------------------------------
133
 
 *
134
 
 * HostinfoOSVersionInit --
135
 
 *
136
 
 *      Compute the OS version information
137
 
 *
138
 
 * Results:
139
 
 *      None.
140
 
 *
141
 
 * Side effects:
142
 
 *      hostinfoOS* variables are filled in.
143
 
 *
144
 
 *----------------------------------------------------------------------
145
 
 */
146
 
 
147
 
static void
148
 
HostinfoOSVersionInit(void)
149
 
{
150
 
   struct utsname u;
151
 
   char extra[SYS_NMLN] = "";
152
 
 
153
 
   if (hostinfoOSVersionInitialized) {
154
 
      return;
155
 
   }
156
 
 
157
 
   if (uname(&u) < 0) {
158
 
      Warning("%s unable to get host OS version (uname): %s\n",
159
 
              __FUNCTION__, strerror(errno));
160
 
      NOT_IMPLEMENTED();
161
 
   }
162
 
 
163
 
   Str_Strcpy(hostinfoOSVersionString, u.release, SYS_NMLN);
164
 
 
165
 
   ASSERT(ARRAYSIZE(hostinfoOSVersion) >= 3);
166
 
   if (sscanf(u.release, "%d.%d.%d%s",
167
 
              &hostinfoOSVersion[0], &hostinfoOSVersion[1],
168
 
              &hostinfoOSVersion[2], extra) < 1) {
169
 
      Warning("%s unable to parse host OS version string: %s\n",
170
 
              __FUNCTION__, u.release);
171
 
      NOT_IMPLEMENTED();
172
 
   }
173
 
 
174
 
   hostinfoOSVersionInitialized = TRUE;
175
 
}
176
 
 
177
 
 
178
 
/*
179
 
 *----------------------------------------------------------------------
180
 
 *
181
 
 * Hostinfo_OSVersionString --
182
 
 *
183
 
 *      Returns the host version information as returned in the
184
 
 *      release field of uname(2)
185
 
 *
186
 
 * Results:
187
 
 *      const char * - pointer to static buffer containing the release
188
 
 *
189
 
 * Side effects:
190
 
 *      None
191
 
 *
192
 
 *----------------------------------------------------------------------
193
 
 */
194
 
 
195
 
const char *
196
 
Hostinfo_OSVersionString(void)
197
 
{
198
 
   HostinfoOSVersionInit();
199
 
   return hostinfoOSVersionString;
200
 
}
201
 
#endif
202
 
 
203
 
 
204
 
/*
205
 
 *----------------------------------------------------------------------
206
 
 *
207
 
 * Hostinfo_OSVersion --
208
 
 *
209
 
 *      Host OS release info.
210
 
 *
211
 
 * Results:
212
 
 *      The i-th component of a dotted release string.
213
 
 *      0 if i is greater than the number of components we support.
214
 
 *
215
 
 * Side effects:
216
 
 *      None.
217
 
 *
218
 
 *----------------------------------------------------------------------
219
 
 */
220
 
 
221
 
int
222
 
Hostinfo_OSVersion(int i)
223
 
{
224
 
   HostinfoOSVersionInit();
225
 
   return i < ARRAYSIZE(hostinfoOSVersion) ? hostinfoOSVersion[i] : 0;
226
 
}
227
 
 
228
 
 
229
 
/*
230
 
 *----------------------------------------------------------------------
231
 
 *
232
 
 * Hostinfo_GetTimeOfDay --
233
 
 *
234
 
 *      Return the current time of day according to the host.  We want
235
 
 *      UTC time (seconds since Jan 1, 1970).
236
 
 *
237
 
 * Results:
238
 
 *      Time of day in microseconds.
239
 
 *
240
 
 * Side effects:
241
 
 *      None.
242
 
 *
243
 
 *----------------------------------------------------------------------
244
 
 */
245
 
 
246
 
void 
247
 
Hostinfo_GetTimeOfDay(VmTimeType *time)
248
 
{
249
 
#if defined(_WIN32)
250
 
   struct _timeb t;
251
 
 
252
 
   _ftime(&t);
253
 
 
254
 
   *time = (t.time * 1000000) + t.millitm * 1000;
255
 
#else  // assume POSIX
256
 
   struct timeval tv;
257
 
 
258
 
   gettimeofday(&tv, NULL);
259
 
 
260
 
   *time = ((int64)tv.tv_sec * 1000000) + tv.tv_usec;
261
 
#endif
262
 
}