1 | /* ERF META PACKET */ |
---|
2 | #include "libtrace.h" |
---|
3 | #include "libpacketdump.h" |
---|
4 | #include "format_erf.h" |
---|
5 | |
---|
6 | #include <arpa/inet.h> |
---|
7 | #include <inttypes.h> |
---|
8 | |
---|
9 | DLLEXPORT void decode(int link_type UNUSED, const char *packet UNUSED, unsigned len UNUSED) { |
---|
10 | } |
---|
11 | |
---|
12 | static void print_section(libtrace_meta_t *meta) { |
---|
13 | int i; |
---|
14 | for (i=0; i<meta->num; i++) { |
---|
15 | |
---|
16 | if (meta->items[i].datatype == TRACE_META_STRING) { |
---|
17 | printf(" %s: %s\n", |
---|
18 | meta->items[i].option_name, |
---|
19 | (char *)meta->items[i].data); |
---|
20 | } else if (meta->items[i].datatype == TRACE_META_UINT8) { |
---|
21 | printf(" %s: %" PRIu8 "\n", |
---|
22 | meta->items[i].option_name, |
---|
23 | *(uint8_t *)meta->items[i].data); |
---|
24 | } else if (meta->items[i].datatype == TRACE_META_UINT32) { |
---|
25 | printf(" %s: %" PRIu32 "\n", |
---|
26 | meta->items[i].option_name, |
---|
27 | *(uint32_t *)meta->items[i].data); |
---|
28 | } else if (meta->items[i].datatype == TRACE_META_UINT64) { |
---|
29 | printf(" %s: %" PRIu64 "\n", |
---|
30 | meta->items[i].option_name, |
---|
31 | *(uint64_t *)meta->items[i].data); |
---|
32 | } else if (meta->items[i].datatype == TRACE_META_IPV4) { |
---|
33 | struct in_addr ip; |
---|
34 | ip.s_addr = *(uint32_t *)meta->items[i].data; |
---|
35 | printf(" %s: %s\n", |
---|
36 | meta->items[i].option_name, |
---|
37 | inet_ntoa(ip)); |
---|
38 | } else if (meta->items[i].datatype == TRACE_META_IPV6) { |
---|
39 | printf(" %s: %s\n", |
---|
40 | meta->items[i].option_name, |
---|
41 | (char *)meta->items[i].data); |
---|
42 | } else if (meta->items[i].datatype == TRACE_META_MAC) { |
---|
43 | unsigned char *mac = meta->items[i].data; |
---|
44 | printf(" %s: %02x:%02x:%02x:%02x:%02x:%02x\n", |
---|
45 | meta->items[i].option_name, |
---|
46 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
---|
47 | } else { |
---|
48 | printf(" Unknown Option ID %" PRIu16 " (output RAW): ", meta->items[i].option); |
---|
49 | int k; |
---|
50 | unsigned char *curr = (unsigned char *)meta->items[i].data; |
---|
51 | for (k=0; k<meta->items[i].len; k++) { |
---|
52 | printf("%02x ", curr[k]); |
---|
53 | } |
---|
54 | printf("\n"); |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | DLLEXPORT void decode_meta(int link_type UNUSED, const char *packet UNUSED, unsigned len UNUSED, |
---|
60 | libtrace_packet_t *p) { |
---|
61 | |
---|
62 | printf(" ERF Provenance Packet\n"); |
---|
63 | |
---|
64 | /* Try to find each section from the meta packet */ |
---|
65 | libtrace_meta_t *sec_cap = trace_get_section(p, ERF_PROV_SECTION_CAPTURE); |
---|
66 | libtrace_meta_t *sec_host = trace_get_section(p, ERF_PROV_SECTION_HOST); |
---|
67 | libtrace_meta_t *sec_module = trace_get_section(p, ERF_PROV_SECTION_MODULE); |
---|
68 | libtrace_meta_t *sec_interface = trace_get_section(p, ERF_PROV_SECTION_INTERFACE); |
---|
69 | |
---|
70 | if (sec_cap != NULL) { |
---|
71 | printf(" Capture Section\n"); |
---|
72 | print_section(sec_cap); |
---|
73 | trace_destroy_meta(sec_cap); |
---|
74 | } |
---|
75 | |
---|
76 | if (sec_host != NULL) { |
---|
77 | printf(" Host Section\n"); |
---|
78 | print_section(sec_host); |
---|
79 | trace_destroy_meta(sec_host); |
---|
80 | } |
---|
81 | |
---|
82 | if (sec_module != NULL) { |
---|
83 | printf(" Module Section\n"); |
---|
84 | print_section(sec_module); |
---|
85 | trace_destroy_meta(sec_module); |
---|
86 | } |
---|
87 | |
---|
88 | if (sec_interface != NULL) { |
---|
89 | printf(" Interface Section\n"); |
---|
90 | print_section(sec_interface); |
---|
91 | trace_destroy_meta(sec_interface); |
---|
92 | } |
---|
93 | |
---|
94 | } |
---|