-
Notifications
You must be signed in to change notification settings - Fork 41
/
sysinfo.h
82 lines (55 loc) · 1.35 KB
/
sysinfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* sysinfo.h
*
* Created on: 30.04.2014
* Author: mad
*/
#ifndef SYSINFO_H_
#define SYSINFO_H_
#ifdef WIN32
#include <windows.h>
#else
#include <sys/utsname.h>
#endif
namespace sysinfo {
static std::string GetClientName() {
std::string name;
#ifdef WIN32
TCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD size = sizeof(computerName) / sizeof(computerName[0]);
GetComputerName(computerName, &size);
name = std::string(computerName, size);
#else
static struct utsname u;
if(uname(&u) < 0)
name = "unknown";
name = std::string(u.nodename);
#endif
return name;
}
static void getCpuid(unsigned int* p, unsigned int ax)
{
__asm __volatile
( "movl %%ebx, %%esi\n\t"
"cpuid\n\t"
"xchgl %%ebx, %%esi"
: "=a" (p[0]), "=S" (p[1]),
"=c" (p[2]), "=d" (p[3])
: "0" (ax)
);
}
static unsigned GetClientID() {
unsigned id = 0;
#ifdef WIN32
DWORD serialNum = 0;
GetVolumeInformation("c:\\", NULL, 0, &serialNum, NULL, NULL, NULL, 0);
id = serialNum;
#else
unsigned int cpuinfo[4] = { 0, 0, 0, 0 };
getCpuid(cpuinfo, 0);
id = cpuinfo[0] * cpuinfo[1] * cpuinfo[2] * cpuinfo[3];
#endif
return id;
}
}; // namespace sysinfo
#endif /* SYSINFO_H_ */