1 | #include "libtrace_int.h" |
---|
2 | #include "libtrace.h" |
---|
3 | #include "format_erf.h" |
---|
4 | #include "format_pcapng.h" |
---|
5 | |
---|
6 | #include <stdio.h> |
---|
7 | #include <stdlib.h> |
---|
8 | #include <string.h> |
---|
9 | |
---|
10 | /* Internal Meta functions */ |
---|
11 | static int trace_meta_check_input(libtrace_packet_t *packet, char *input_func) { |
---|
12 | if (packet == NULL) { |
---|
13 | fprintf(stderr, "NULL packet passed into %s\n", input_func); |
---|
14 | return -1; |
---|
15 | } |
---|
16 | if (packet->trace == NULL) { |
---|
17 | fprintf(stderr, "Packet contains NULL trace in %s\n", input_func); |
---|
18 | return -1; |
---|
19 | } |
---|
20 | return 1; |
---|
21 | } |
---|
22 | |
---|
23 | static libtrace_meta_t *trace_get_meta_option(libtrace_packet_t *packet, uint32_t section, |
---|
24 | uint32_t option) { |
---|
25 | |
---|
26 | libtrace_meta_t *r = NULL; |
---|
27 | libtrace_meta_t *f = NULL; |
---|
28 | int i; |
---|
29 | |
---|
30 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
31 | r = packet->trace->format->get_meta_section(packet, |
---|
32 | section); |
---|
33 | } |
---|
34 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
35 | r = packet->trace->format->get_meta_section(packet, |
---|
36 | section); |
---|
37 | } |
---|
38 | |
---|
39 | if (r == NULL) { return NULL; } |
---|
40 | |
---|
41 | /* Allocate memory for the result */ |
---|
42 | f = malloc(sizeof(libtrace_meta_t)); |
---|
43 | if (f == NULL) { |
---|
44 | trace_set_err(packet->trace, TRACE_ERR_OUT_OF_MEMORY, |
---|
45 | "Unable to allocate memory in trace_get_meta_option()"); |
---|
46 | trace_destroy_meta(r); |
---|
47 | return NULL; |
---|
48 | } |
---|
49 | f->num = 0; |
---|
50 | |
---|
51 | /* See if a result was found within the section */ |
---|
52 | for (i=0; i<r->num; i++) { |
---|
53 | if (r->section == section && r->items[i].option == option) { |
---|
54 | /* Create a meta structure with the single item wanted */ |
---|
55 | //f = malloc(sizeof(libtrace_meta_t)); |
---|
56 | if (f->num == 0) { |
---|
57 | f->items = malloc(sizeof(libtrace_meta_item_t)); |
---|
58 | } else { |
---|
59 | f->items = realloc(f->items, (f->num+1)* |
---|
60 | sizeof(libtrace_meta_item_t)); |
---|
61 | } |
---|
62 | /* Ensure memory was allocated */ |
---|
63 | if (f->items == NULL) { |
---|
64 | trace_set_err(packet->trace, TRACE_ERR_OUT_OF_MEMORY, |
---|
65 | "Unable to allocate memory in trace_get_meta_option()"); |
---|
66 | trace_destroy_meta(r); |
---|
67 | trace_destroy_meta(f); |
---|
68 | return NULL; |
---|
69 | } |
---|
70 | |
---|
71 | /* Copy the data over */ |
---|
72 | f->items[f->num].option = r->items[i].option; |
---|
73 | f->items[f->num].option_name = r->items[i].option_name; |
---|
74 | f->items[f->num].len = r->items[i].len; |
---|
75 | f->items[f->num].datatype = r->items[i].datatype; |
---|
76 | f->items[f->num].data = r->items[i].data; |
---|
77 | |
---|
78 | /* delink from original structure */ |
---|
79 | r->items[i].data = NULL; |
---|
80 | |
---|
81 | f->num += 1; |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | /* Destroy the old structure */ |
---|
86 | trace_destroy_meta(r); |
---|
87 | |
---|
88 | if (f->num > 0) { |
---|
89 | return f; |
---|
90 | } else { |
---|
91 | trace_destroy_meta(f); |
---|
92 | return NULL; |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | /* API FUNCTIONS */ |
---|
98 | |
---|
99 | int trace_destroy_meta(libtrace_meta_t *result) { |
---|
100 | int i; |
---|
101 | if (!result) { return -1; } |
---|
102 | |
---|
103 | for (i=0;i<result->num;i++) { |
---|
104 | if(result->items[i].data != NULL) { |
---|
105 | free(result->items[i].data); |
---|
106 | } |
---|
107 | } |
---|
108 | if (result->items) { |
---|
109 | free(result->items); |
---|
110 | } |
---|
111 | if (result) { |
---|
112 | free(result); |
---|
113 | } |
---|
114 | |
---|
115 | return 1; |
---|
116 | } |
---|
117 | |
---|
118 | libtrace_meta_t *trace_get_interface_name_meta(libtrace_packet_t *packet) { |
---|
119 | if (trace_meta_check_input(packet, "trace_get_interface_name()")<0) { |
---|
120 | return NULL; |
---|
121 | } |
---|
122 | |
---|
123 | libtrace_meta_t *r = NULL; |
---|
124 | |
---|
125 | /* get the result */ |
---|
126 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
127 | r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_NAME); |
---|
128 | } |
---|
129 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
130 | r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_NAME); |
---|
131 | } |
---|
132 | |
---|
133 | return r; |
---|
134 | } |
---|
135 | |
---|
136 | char *trace_get_interface_name(libtrace_packet_t *packet, char *space, int spacelen, |
---|
137 | int index) { |
---|
138 | |
---|
139 | libtrace_meta_t *r = trace_get_interface_name_meta(packet); |
---|
140 | if (r == NULL) { return NULL; } |
---|
141 | /* If there is not a result for the index return */ |
---|
142 | if (r->num <= index) { |
---|
143 | trace_destroy_meta(r); |
---|
144 | return NULL; |
---|
145 | } |
---|
146 | /* Ensure the supplied memory allocation is enough, if not only fill |
---|
147 | * what we can. */ |
---|
148 | if (spacelen > r->items[index].len) { |
---|
149 | memcpy(space, r->items[index].data, r->items[index].len); |
---|
150 | space[r->items[index].len] = '\0'; |
---|
151 | } else { |
---|
152 | memcpy(space, r->items[index].data, spacelen); |
---|
153 | space[spacelen] = '\0'; |
---|
154 | } |
---|
155 | trace_destroy_meta(r); |
---|
156 | return space; |
---|
157 | } |
---|
158 | |
---|
159 | libtrace_meta_t *trace_get_interface_mac_meta(libtrace_packet_t *packet) { |
---|
160 | if (trace_meta_check_input(packet, "trace_get_interface_mac()")<0) { |
---|
161 | return NULL; |
---|
162 | } |
---|
163 | |
---|
164 | libtrace_meta_t *r = NULL; |
---|
165 | |
---|
166 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
167 | r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_MAC); |
---|
168 | } |
---|
169 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
170 | r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_MAC); |
---|
171 | } |
---|
172 | |
---|
173 | return r; |
---|
174 | } |
---|
175 | |
---|
176 | char *trace_get_interface_mac(libtrace_packet_t *packet, char *space, int spacelen, |
---|
177 | int index) { |
---|
178 | |
---|
179 | libtrace_meta_t *r = trace_get_interface_mac_meta(packet); |
---|
180 | if (r == NULL) { return NULL; } |
---|
181 | if (index >= r->num) { |
---|
182 | trace_destroy_meta(r); |
---|
183 | return NULL; |
---|
184 | } |
---|
185 | if (r->items[index].len > spacelen) { |
---|
186 | memcpy(space, r->items[index].data, spacelen); |
---|
187 | space[spacelen] = '\0'; |
---|
188 | } else { |
---|
189 | memcpy(space, r->items[index].data, r->items[index].len); |
---|
190 | space[r->items[index].len] = '\0'; |
---|
191 | } |
---|
192 | trace_destroy_meta(r); |
---|
193 | return space; |
---|
194 | } |
---|
195 | |
---|
196 | libtrace_meta_t *trace_get_interface_speed_meta(libtrace_packet_t *packet) { |
---|
197 | if (trace_meta_check_input(packet, "trace_get_interface_speed()")<0) { |
---|
198 | return NULL; |
---|
199 | } |
---|
200 | |
---|
201 | libtrace_meta_t *r = NULL; |
---|
202 | |
---|
203 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
204 | r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_SPEED); |
---|
205 | } |
---|
206 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
207 | r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_SPEED); |
---|
208 | } |
---|
209 | |
---|
210 | return r; |
---|
211 | } |
---|
212 | |
---|
213 | uint64_t trace_get_interface_speed(libtrace_packet_t *packet, int index) { |
---|
214 | libtrace_meta_t *r = trace_get_interface_speed_meta(packet); |
---|
215 | if (r == NULL) { return 0; } |
---|
216 | /* If the index wanted does not exist return 0 */ |
---|
217 | if (index >= r->num) { |
---|
218 | trace_destroy_meta(r); |
---|
219 | return 0; |
---|
220 | } |
---|
221 | /* Need to check this more ERF reports this in network order */ |
---|
222 | uint64_t data = *(uint64_t *)r->items[index].data; |
---|
223 | trace_destroy_meta(r); |
---|
224 | return data; |
---|
225 | } |
---|
226 | |
---|
227 | libtrace_meta_t *trace_get_interface_ipv4_meta(libtrace_packet_t *packet) { |
---|
228 | if (trace_meta_check_input(packet, "trace_get_interface_ip4()")<0) { |
---|
229 | return NULL; |
---|
230 | } |
---|
231 | |
---|
232 | libtrace_meta_t *r = NULL; |
---|
233 | |
---|
234 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
235 | r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_IPV4); |
---|
236 | } |
---|
237 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
238 | r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_IP4); |
---|
239 | } |
---|
240 | |
---|
241 | return r; |
---|
242 | } |
---|
243 | |
---|
244 | uint32_t trace_get_interface_ipv4(libtrace_packet_t *packet, int index) { |
---|
245 | libtrace_meta_t *r = trace_get_interface_ipv4_meta(packet); |
---|
246 | if (r == NULL) { return 0; } |
---|
247 | if (index >= r->num) { |
---|
248 | trace_destroy_meta(r); |
---|
249 | return 0; |
---|
250 | } |
---|
251 | uint32_t data = *(uint32_t *)r->items[index].data; |
---|
252 | trace_destroy_meta(r); |
---|
253 | return data; |
---|
254 | } |
---|
255 | |
---|
256 | /* UNTESTED */ |
---|
257 | char *trace_get_interface_ipv4_string(libtrace_packet_t *packet, char *space, int spacelen, |
---|
258 | int index) { |
---|
259 | |
---|
260 | if (spacelen < INET_ADDRSTRLEN) { |
---|
261 | return NULL; |
---|
262 | } |
---|
263 | |
---|
264 | uint32_t addr = trace_get_interface_ipv4(packet, index); |
---|
265 | if (addr == 0) { |
---|
266 | return NULL; |
---|
267 | } |
---|
268 | |
---|
269 | /* get the string representation, store in space */ |
---|
270 | inet_ntop(AF_INET, &addr, space, INET_ADDRSTRLEN); |
---|
271 | |
---|
272 | return space; |
---|
273 | } |
---|
274 | |
---|
275 | libtrace_meta_t *trace_get_interface_ipv6_meta(libtrace_packet_t *packet) { |
---|
276 | if (trace_meta_check_input(packet, "trace_get_interface_ip6()")<0) { |
---|
277 | return NULL; |
---|
278 | } |
---|
279 | |
---|
280 | libtrace_meta_t *r = NULL; |
---|
281 | |
---|
282 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
283 | r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_IPV4); |
---|
284 | } |
---|
285 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
286 | r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_IP4); |
---|
287 | } |
---|
288 | |
---|
289 | return r; |
---|
290 | } |
---|
291 | |
---|
292 | void *trace_get_interface_ipv6(libtrace_packet_t *packet, void *space, int spacelen, |
---|
293 | int index) { |
---|
294 | |
---|
295 | libtrace_meta_t *r = trace_get_interface_ipv6_meta(packet); |
---|
296 | if (r == NULL) { return NULL; } |
---|
297 | if (r->num <= index) { |
---|
298 | trace_destroy_meta(r); |
---|
299 | return NULL; |
---|
300 | } |
---|
301 | if (r->items[index].len > spacelen) { |
---|
302 | memcpy(space, r->items[index].data, spacelen); |
---|
303 | } else { |
---|
304 | memcpy(space, r->items[index].data, r->items[index].len); |
---|
305 | } |
---|
306 | trace_destroy_meta(r); |
---|
307 | return space; |
---|
308 | } |
---|
309 | |
---|
310 | /* UNTESTED */ |
---|
311 | char *trace_get_interface_ipv6_string(libtrace_packet_t *packet, char *space, int spacelen, |
---|
312 | int index) { |
---|
313 | |
---|
314 | /* Ensure we have enough space */ |
---|
315 | if (spacelen < INET6_ADDRSTRLEN) { |
---|
316 | return NULL; |
---|
317 | } |
---|
318 | |
---|
319 | struct sockaddr_in6 sa; |
---|
320 | |
---|
321 | void *r = trace_get_interface_ipv6(packet, &(sa.sin6_addr), 16, index); |
---|
322 | if (r == NULL) { |
---|
323 | return NULL; |
---|
324 | } |
---|
325 | |
---|
326 | /* get the string representation, store in space */ |
---|
327 | inet_ntop(AF_INET6, &(sa.sin6_addr), space, INET6_ADDRSTRLEN); |
---|
328 | |
---|
329 | return space; |
---|
330 | } |
---|
331 | |
---|
332 | libtrace_meta_t *trace_get_interface_description_meta(libtrace_packet_t *packet) { |
---|
333 | if (trace_meta_check_input(packet, "trace_get_interface_description()")<0) { |
---|
334 | return NULL; |
---|
335 | } |
---|
336 | |
---|
337 | libtrace_meta_t *r = NULL; |
---|
338 | |
---|
339 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
340 | r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_DESCR); |
---|
341 | } |
---|
342 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
343 | r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_DESCR); |
---|
344 | } |
---|
345 | |
---|
346 | return r; |
---|
347 | } |
---|
348 | |
---|
349 | char *trace_get_interface_description(libtrace_packet_t *packet, char *space, int spacelen, |
---|
350 | int index) { |
---|
351 | |
---|
352 | libtrace_meta_t *r = trace_get_interface_description_meta(packet); |
---|
353 | if (r == NULL) { return NULL; } |
---|
354 | if (r->num <= index) { |
---|
355 | trace_destroy_meta(r); |
---|
356 | return NULL; |
---|
357 | } |
---|
358 | if (r->items[index].len > spacelen) { |
---|
359 | memcpy(space, r->items[index].data, spacelen); |
---|
360 | space[spacelen] = '\0'; |
---|
361 | } else { |
---|
362 | memcpy(space, r->items[index].data, r->items[index].len); |
---|
363 | space[r->items[index].len] = '\0'; |
---|
364 | } |
---|
365 | trace_destroy_meta(r); |
---|
366 | return space; |
---|
367 | } |
---|
368 | |
---|
369 | libtrace_meta_t *trace_get_host_os_meta(libtrace_packet_t *packet) { |
---|
370 | if (trace_meta_check_input(packet, "trace_get_host_os()")<0) { |
---|
371 | return NULL; |
---|
372 | } |
---|
373 | |
---|
374 | libtrace_meta_t *r = NULL; |
---|
375 | |
---|
376 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
377 | r = trace_get_meta_option(packet, ERF_PROV_SECTION_HOST, ERF_PROV_OS); |
---|
378 | } |
---|
379 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
380 | r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_OS); |
---|
381 | } |
---|
382 | |
---|
383 | return r; |
---|
384 | } |
---|
385 | |
---|
386 | char *trace_get_host_os(libtrace_packet_t *packet, char *space, int spacelen) { |
---|
387 | libtrace_meta_t *r = trace_get_host_os_meta(packet); |
---|
388 | if (r == NULL) { return NULL; } |
---|
389 | if (r->items[0].len > spacelen) { |
---|
390 | memcpy(space, r->items[0].data, spacelen); |
---|
391 | space[spacelen] = '\0'; |
---|
392 | } else { |
---|
393 | memcpy(space, r->items[0].data, r->items[0].len); |
---|
394 | space[r->items[0].len] = '\0'; |
---|
395 | } |
---|
396 | trace_destroy_meta(r); |
---|
397 | return space; |
---|
398 | } |
---|
399 | |
---|
400 | libtrace_meta_t *trace_get_interface_fcslen_meta(libtrace_packet_t *packet) { |
---|
401 | if (trace_meta_check_input(packet, "trace_get_interface_frame_check_sequence_length()")<0) { |
---|
402 | return NULL; |
---|
403 | } |
---|
404 | |
---|
405 | libtrace_meta_t *r = NULL; |
---|
406 | |
---|
407 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
408 | r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_FCS_LEN); |
---|
409 | } |
---|
410 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
411 | r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_FCSLEN); |
---|
412 | } |
---|
413 | |
---|
414 | return r; |
---|
415 | } |
---|
416 | |
---|
417 | uint32_t trace_get_interface_fcslen(libtrace_packet_t *packet, int index) { |
---|
418 | libtrace_meta_t *r = trace_get_interface_fcslen_meta(packet); |
---|
419 | if (r == NULL) { return 0; } |
---|
420 | if (r->num <= index) { |
---|
421 | trace_destroy_meta(r); |
---|
422 | return 0; |
---|
423 | } |
---|
424 | uint32_t data = *(uint32_t *)r->items[index].data; |
---|
425 | trace_destroy_meta(r); |
---|
426 | return data; |
---|
427 | } |
---|
428 | |
---|
429 | libtrace_meta_t *trace_get_interface_comment_meta(libtrace_packet_t *packet) { |
---|
430 | if (trace_meta_check_input(packet, "trace_get_interface_comment()")<0) { |
---|
431 | return NULL; |
---|
432 | } |
---|
433 | |
---|
434 | libtrace_meta_t *r = NULL; |
---|
435 | |
---|
436 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
437 | r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_COMMENT); |
---|
438 | } |
---|
439 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
440 | r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_OPTION_COMMENT); |
---|
441 | } |
---|
442 | |
---|
443 | return r; |
---|
444 | } |
---|
445 | |
---|
446 | char *trace_get_interface_comment(libtrace_packet_t *packet, char *space, int spacelen, |
---|
447 | int index) { |
---|
448 | |
---|
449 | libtrace_meta_t *r = trace_get_interface_comment_meta(packet); |
---|
450 | if (r == NULL) { return NULL; } |
---|
451 | if (index > r->num) { |
---|
452 | trace_destroy_meta(r); |
---|
453 | return NULL; |
---|
454 | } |
---|
455 | if (r->items[index].len > spacelen) { |
---|
456 | memcpy(space, r->items[index].data, spacelen); |
---|
457 | space[spacelen] = '\0'; |
---|
458 | } else { |
---|
459 | memcpy(space, r->items[index].data, r->items[index].len); |
---|
460 | space[r->items[index].len] = '\0'; |
---|
461 | } |
---|
462 | trace_destroy_meta(r); |
---|
463 | return space; |
---|
464 | } |
---|
465 | |
---|
466 | libtrace_meta_t *trace_get_capture_application_meta(libtrace_packet_t *packet) { |
---|
467 | if (trace_meta_check_input(packet, "trace_get_interface_comment()")<0) { |
---|
468 | return NULL; |
---|
469 | } |
---|
470 | |
---|
471 | libtrace_meta_t *r = NULL; |
---|
472 | |
---|
473 | if (packet->trace->format->type == TRACE_FORMAT_ERF) { |
---|
474 | r = trace_get_meta_option(packet, ERF_PROV_SECTION_CAPTURE, ERF_PROV_APP_NAME); |
---|
475 | } |
---|
476 | if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) { |
---|
477 | r = trace_get_meta_option(packet, PCAPNG_SECTION_TYPE, PCAPNG_META_SHB_USERAPPL); |
---|
478 | } |
---|
479 | |
---|
480 | return r; |
---|
481 | } |
---|
482 | |
---|
483 | char *trace_get_capture_application(libtrace_packet_t *packet, char *space, int spacelen) { |
---|
484 | libtrace_meta_t *r = trace_get_capture_application_meta(packet); |
---|
485 | if (r == NULL) { return NULL; } |
---|
486 | if (r->items[0].len > spacelen) { |
---|
487 | memcpy(space, r->items[0].data, spacelen); |
---|
488 | space[spacelen] = '\0'; |
---|
489 | } else { |
---|
490 | memcpy(space, r->items[0].data, r->items[0].len); |
---|
491 | space[r->items[0].len] = '\0'; |
---|
492 | } |
---|
493 | trace_destroy_meta(r); |
---|
494 | return space; |
---|
495 | } |
---|
496 | |
---|
497 | libtrace_meta_t *trace_get_section_option(libtrace_packet_t *packet, uint32_t section_code, |
---|
498 | uint16_t option_code) { |
---|
499 | |
---|
500 | if (trace_meta_check_input(packet, "trace_get_custom_meta()")<0) { |
---|
501 | return NULL; |
---|
502 | } |
---|
503 | |
---|
504 | return trace_get_meta_option(packet, section_code, option_code); |
---|
505 | } |
---|
506 | |
---|
507 | libtrace_meta_t *trace_get_section(libtrace_packet_t *packet, uint32_t section_code) { |
---|
508 | if (trace_meta_check_input(packet, "trace_get_section()")<0) { |
---|
509 | return NULL; |
---|
510 | } |
---|
511 | |
---|
512 | return packet->trace->format->get_meta_section(packet, section_code); |
---|
513 | } |
---|
514 | |
---|
515 | char *trace_get_erf_dag_card_model(libtrace_packet_t *packet, char *space, int spacelen) { |
---|
516 | libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE, |
---|
517 | ERF_PROV_MODEL); |
---|
518 | |
---|
519 | if (r == NULL) { return NULL; } |
---|
520 | if (r->items[0].len > spacelen) { |
---|
521 | memcpy(space, r->items[0].data, spacelen); |
---|
522 | space[spacelen] = '\0'; |
---|
523 | } else { |
---|
524 | memcpy(space, r->items[0].data, r->items[0].len); |
---|
525 | space[r->items[0].len] = '\0'; |
---|
526 | } |
---|
527 | trace_destroy_meta(r); |
---|
528 | return space; |
---|
529 | } |
---|
530 | |
---|
531 | char *trace_get_erf_dag_version(libtrace_packet_t *packet, char *space, int spacelen) { |
---|
532 | libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE, |
---|
533 | ERF_PROV_DAG_VERSION); |
---|
534 | |
---|
535 | if (r == NULL) { return NULL; } |
---|
536 | |
---|
537 | if (r->items[0].len > spacelen) { |
---|
538 | memcpy(space, r->items[0].data, spacelen); |
---|
539 | space[spacelen] = '\0'; |
---|
540 | } else { |
---|
541 | memcpy(space, r->items[0].data, r->items[0].len); |
---|
542 | space[r->items[0].len] = '\0'; |
---|
543 | } |
---|
544 | trace_destroy_meta(r); |
---|
545 | return space; |
---|
546 | } |
---|
547 | |
---|
548 | char *trace_get_erf_dag_fw_version(libtrace_packet_t *packet, char *space, int spacelen) { |
---|
549 | libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE, |
---|
550 | ERF_PROV_FW_VERSION); |
---|
551 | |
---|
552 | if (r == NULL) { return NULL; } |
---|
553 | |
---|
554 | if (r->items[0].len > spacelen) { |
---|
555 | memcpy(space, r->items[0].data, spacelen); |
---|
556 | space[spacelen] = '\0'; |
---|
557 | } else { |
---|
558 | memcpy(space, r->items[0].data, r->items[0].len); |
---|
559 | space[r->items[0].len] = '\0'; |
---|
560 | } |
---|
561 | trace_destroy_meta(r); |
---|
562 | return space; |
---|
563 | } |
---|
564 | |
---|