Stefan Schuermans commited on 2020-05-17 18:16:46
Showing 2 changed files, with 17 additions and 3 deletions.
... | ... |
@@ -1,13 +1,19 @@ |
1 | 1 |
#include "write.h" |
2 | 2 |
|
3 | 3 |
#include <fcntl.h> |
4 |
+#include <stdint.h> |
|
4 | 5 |
#include <stdlib.h> |
5 | 6 |
#include <string.h> |
6 | 7 |
#include <sys/file.h> |
7 | 8 |
#include <unistd.h> |
8 | 9 |
|
10 |
+struct lwptpl_event_header_s { |
|
11 |
+ uint8_t magic[4]; /**< l w p t */ |
|
12 |
+ uint8_t size[4]; /**< size of payload in network byte oder */ |
|
13 |
+} __attribute__((packed)); |
|
14 |
+ |
|
9 | 15 |
void lwptpl_write(void const *data, size_t size) { |
10 |
- if (! data || ! size) { |
|
16 |
+ if (! data || ! size || size > 0xFFFFFFFF) { |
|
11 | 17 |
return; |
12 | 18 |
} |
13 | 19 |
char const *filename = getenv("LWPTPL_OUTPUT"); |
... | ... |
@@ -22,6 +28,16 @@ void lwptpl_write(void const *data, size_t size) { |
22 | 28 |
close(fd); |
23 | 29 |
return; |
24 | 30 |
} |
31 |
+ struct lwptpl_event_header_s lwptpl_event_header = { |
|
32 |
+ .magic = { 'l', 'w', 'p', 't' }, |
|
33 |
+ .size = { |
|
34 |
+ (size >> 24) & 0xFF, |
|
35 |
+ (size >> 16) & 0xFF, |
|
36 |
+ (size >> 8) & 0xFF, |
|
37 |
+ size & 0xFF, |
|
38 |
+ } |
|
39 |
+ }; |
|
40 |
+ write(fd, &lwptpl_event_header, sizeof(lwptpl_event_header)); |
|
25 | 41 |
write(fd, data, size); |
26 | 42 |
flock(fd, LOCK_UN); |
27 | 43 |
close(fd); |