1 | #define sysctl _std_sysctl
|
---|
2 | #include <string.h>
|
---|
3 | #include <sys/types.h>
|
---|
4 | #include <sys/sysctl.h>
|
---|
5 | #include <sys/time.h>
|
---|
6 | #include <stdio.h>
|
---|
7 | #include <errno.h>
|
---|
8 |
|
---|
9 | int main()
|
---|
10 | {
|
---|
11 |
|
---|
12 | {
|
---|
13 | int mib[] = {CTL_KERN, KERN_BOOTTIME};
|
---|
14 | struct timeval j;
|
---|
15 | size_t cbOut = sizeof(j);
|
---|
16 | int rc = sysctl(mib, 2, &j, &cbOut, NULL, 0);
|
---|
17 | printf("KERN_BOOTTIME: rc=%d errno=%d cbOut=%d - %d.%.6ld\n", rc, errno, cbOut, j.tv_sec, j.tv_usec);
|
---|
18 | }
|
---|
19 |
|
---|
20 | #define GETSTRING(a, b) \
|
---|
21 | { \
|
---|
22 | int mib[] = {a, b}; \
|
---|
23 | char sz[256] = {0}; \
|
---|
24 | size_t cbOut = sizeof(sz); \
|
---|
25 | int rc = sysctl(mib, 2, sz, &cbOut, NULL, 0); \
|
---|
26 | printf(#b ": rc=%d errno=%d cbOut=%d - %s\n", rc, errno, cbOut, sz); \
|
---|
27 | }
|
---|
28 |
|
---|
29 | #define GETINT(a, b) \
|
---|
30 | { \
|
---|
31 | int mib[] = {a, b}; \
|
---|
32 | int j; \
|
---|
33 | size_t cbOut = sizeof(j); \
|
---|
34 | int rc = sysctl(mib, 2, &j, &cbOut, NULL, 0); \
|
---|
35 | printf(#b ": rc=%d errno=%d cbOut=%d - %d (%#x)\n", rc, errno, cbOut, j, j); \
|
---|
36 | }
|
---|
37 |
|
---|
38 | GETSTRING(CTL_KERN, KERN_BOOTFILE)
|
---|
39 | GETSTRING(CTL_HW, HW_MACHINE_ARCH)
|
---|
40 | GETSTRING(CTL_HW, HW_MACHINE)
|
---|
41 | GETSTRING(CTL_HW, HW_MODEL)
|
---|
42 | GETINT(CTL_HW, HW_NCPU)
|
---|
43 |
|
---|
44 |
|
---|
45 | return 0;
|
---|
46 | }
|
---|