-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetbsd_gettime50.c
55 lines (46 loc) · 1.54 KB
/
netbsd_gettime50.c
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/timex.h>
#include <sys/syscall.h>
#define GETTIME50 448
// relevant data structures
/* struct timespec { */
/* time_t tv_sec; /\* seconds *\/ */
/* long tv_nsec; /\* and nanoseconds *\/ */
/* }; */
/* struct ntptimeval { */
/* struct timespec time; /\* current time (ns) (ro) *\/ */
/* long maxerror; /\* maximum error (us) (ro) *\/ */
/* long esterror; /\* estimated error (us) (ro) *\/ */
/* long tai; /\* TAI offset *\/ */
/* int time_state; /\* time status *\/ */
/* }; */
// -> due to alignment the compiler reserves four more bytes at the end of this struct
int main(int argc, char *argv[])
{
struct ntptimeval *buf = malloc(sizeof(struct ntptimeval));
if (buf == NULL) {
printf("Could allocate memory.");
exit(1);
}
memset(buf, 0x00, sizeof(struct ntptimeval));
printf("size of struct ntptimeval is %lu bytes.\n", sizeof(struct ntptimeval));
// syscall prototype:
// int ntp_gettime(struct ntptimeval *ntvp)
syscall(GETTIME50, buf);
// view with "hexdump gettime50_dump.bin"
FILE *ptr;
ptr = fopen("gettime50_dump.bin","wb");
if (ptr == NULL){
printf("Error while opening file.\n");
exit(1);
}
fwrite(buf, sizeof(struct ntptimeval), 1, ptr);
fclose(ptr);
free(buf);
return 0;
}