source: lib/format_pktmeta.c @ a86d10e

develop
Last change on this file since a86d10e was a86d10e, checked in by Jacob Van Walraven <jcv9@…>, 21 months ago

byte ordering is handling by the format

  • Property mode set to 100644
File size: 22.7 KB
Line 
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 */
11static 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/* API functions to retrieve interface related packet data */
24
25/* Destroy libtrace_meta_t structure
26 *
27 * @params libtrace_meta_t structure
28 * returns 1 on success, -1 on failure
29 */
30int trace_destroy_meta(libtrace_meta_t *result) {
31        int i;
32        if (!result) { return -1; }
33
34        for (i=0;i<result->num;i++) {
35                if(result->items[i].data != NULL) {
36                        free(result->items[i].data);
37                }
38        }
39        if (result->items) {
40                free(result->items);
41        }
42        if (result) {
43                free(result);
44        }
45
46        return 1;
47}
48
49libtrace_meta_t *trace_get_meta_option(libtrace_packet_t *packet, uint32_t section,
50        uint32_t option) {
51
52        libtrace_meta_t *r = NULL;
53        libtrace_meta_t *f;
54        int i;
55
56        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
57                r = packet->trace->format->get_meta_section(packet,
58                        section);
59        }
60        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
61                r = packet->trace->format->get_meta_section(packet,
62                        section);
63        }
64
65        if (r == NULL) { return NULL; }
66
67        /* See if a result was found within the section */
68        for (i=0; i<r->num; i++) {
69                if (r->section == section && r->items[i].option == option) {
70                        /* Create a meta structure with the single item wanted */
71                        f = malloc(sizeof(libtrace_meta_t));
72                        f->num = 1;
73                        f->items = malloc(sizeof(libtrace_meta_item_t));
74
75                        f->items->option = r->items[i].option;
76                        f->items->option_name = r->items[i].option_name;
77                        f->items->len = r->items[i].len;
78                        f->items->datatype = r->items[i].datatype;
79                        f->items->data = r->items[i].data;
80
81                        /* delink from original structure */
82                        r->items[i].data = NULL;
83
84                        trace_destroy_meta(r);
85                        return f;
86                }
87        }
88
89        trace_destroy_meta(r);
90        return NULL;
91}
92
93/* Get the interface name/s for a meta packet.
94 * Must be destroyed with trace_destroy_meta().
95 *
96 * @params libtrace_packet_t meta packet.
97 * @returns Pointer to libtrace_meta_t structure containing all found interface names
98 * or NULL.
99 */
100libtrace_meta_t *trace_get_interface_name_meta(libtrace_packet_t *packet) {
101        if (trace_meta_check_input(packet, "trace_get_interface_name()")<0) {
102                return NULL;
103        }
104
105        libtrace_meta_t *r = NULL;
106
107        /* get the result */
108        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
109                r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_NAME);
110        }
111        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
112                r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_NAME);
113        }
114
115        return r;
116}
117/* Get the interface name for a meta packet.
118 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
119 * specify the interface index.
120 *
121 * @params libtrace_packet_t meta packet to extract the interface name from.
122 * @params A pointer to a character buffer to store the interface name in.
123 * @params The size of the buffer passed in.
124 * @params The interface index within the meta packet.
125 * @returns Pointer to the character buffer containing the interface name or NULL.
126 */
127char *trace_get_interface_name(libtrace_packet_t *packet, char *space, int spacelen,
128        int index) {
129
130        libtrace_meta_t *r = trace_get_interface_name_meta(packet);
131        if (r == NULL) { return NULL; }
132        /* If there is not a result for the index return */
133        if (r->num <= index) { return NULL; }
134        /* Ensure the supplied memory allocation is enough, if not only fill
135         * what we can */
136        if (spacelen > r->items[index].len) {
137                memcpy(space, r->items[index].data, r->items[index].len);
138        } else {
139                memcpy(space, r->items[index].data, spacelen);
140        }
141        trace_destroy_meta(r);
142        return space;
143}
144
145/* Get the interface MAC address/s for a meta packet.
146 * Must be destroyed with trace_destroy_meta().
147 *
148 * @params libtrace_packet_t meta packet.
149 * @returns Pointer to libtrace_meta_t structure containing all found interface mac
150 * addresses or NULL.
151 */
152libtrace_meta_t *trace_get_interface_mac_meta(libtrace_packet_t *packet) {
153        if (trace_meta_check_input(packet, "trace_get_interface_mac()")<0) {
154                return NULL;
155        }
156
157        libtrace_meta_t *r = NULL;
158
159        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
160                r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_MAC);
161        }
162        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
163                r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_MAC);
164        }
165
166        return r;
167}
168/* Get the interface MAC address for a meta packet.
169 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
170 * specify the interface index.
171 *
172 * @params libtrace_packet_t meta packet to extract the MAC address from.
173 * @params A pointer to a character buffer to store the MAC address in.
174 * @params The size of the buffer passed in.
175 * @params The interface index within the meta packet.
176 * @returns Pointer to the character buffer containing the MAC address or NULL.
177 */
178char *trace_get_interface_mac(libtrace_packet_t *packet, char *space, int spacelen,
179        int index) {
180
181        libtrace_meta_t *r = trace_get_interface_mac_meta(packet);
182        if (r == NULL) { return NULL; }
183        if (index >= r->num) { return NULL; }
184        if (r->items[index].len > spacelen) {
185                memcpy(space, r->items[index].data, spacelen);
186        } else {
187                memcpy(space, r->items[index].data, r->items[index].len);
188        }
189        trace_destroy_meta(r);
190        return space;
191}
192
193/* Get the interface speed/s from a meta packet.
194 * Must be destroyed with trace_destroy_meta().
195 *
196 * @params libtrace_packet_t packet.
197 * @returns Pointer to libtrace_meta_t structure containing all found interface
198 * speeds or NULL.
199 */
200libtrace_meta_t *trace_get_interface_speed_meta(libtrace_packet_t *packet) {
201        if (trace_meta_check_input(packet, "trace_get_interface_speed()")<0) {
202                return NULL;
203        }
204
205        libtrace_meta_t *r = NULL;
206
207        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
208                r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_SPEED);
209        }
210        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
211                r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_SPEED);
212        }
213
214        return r;
215}
216/* Get the interface speed for a meta packet.
217 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
218 * specify the interface index.
219 *
220 * @params libtrace_packet_t meta packet to extract the interface speed from.
221 * @params The interface index within the meta packet.
222 * @returns uint64_t interface speed or NULL.
223 */
224uint64_t trace_get_interface_speed(libtrace_packet_t *packet, int index) {
225        libtrace_meta_t *r = trace_get_interface_speed_meta(packet);
226        if (r == NULL) { return 0; }
227        /* If the index wanted does not exist return 0 */
228        if (index >= r->num) { return 0; }
229        /* Need to check this more ERF reports this in network order */
230        uint64_t data = *(uint64_t *)r->items[index].data;
231        trace_destroy_meta(r);
232        return data;
233}
234
235/* Get the interface ipv4 address/s for a meta packet.
236 * Must be destroyed with trace_destroy_meta().
237 *
238 * @params libtrace_packet_t meta packet.
239 * @returns Pointer to libtrace_meta_t structure containing all found ipv4 addresses
240 * or NULL
241 */
242libtrace_meta_t *trace_get_interface_ipv4_meta(libtrace_packet_t *packet) {
243        if (trace_meta_check_input(packet, "trace_get_interface_ip4()")<0) {
244                return NULL;
245        }
246
247        libtrace_meta_t *r = NULL;
248
249        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
250                r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_IPV4);
251        }
252        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
253                r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_IP4);
254        }
255
256        return r;
257}
258/* Get the interface ipv4 address for a meta packet.
259 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
260 * specify the interface index.
261 *
262 * @params libtrace_packet_t meta packet to extract the ipv4 address from.
263 * @params The interface index within the meta packet.
264 * @returns uint32_t ipv4 address or 0.
265 */
266uint32_t trace_get_interface_ipv4(libtrace_packet_t *packet, int index) {
267        libtrace_meta_t *r = trace_get_interface_ipv4_meta(packet);
268        if (r == NULL) { return 0; }
269        if (index >= r->num) { return 0; }
270        uint32_t data = *(uint32_t *)r->items[index].data;
271        trace_destroy_meta(r);
272        return data;
273}
274/* Get the interface ipv4 address string for a meta packet.
275 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
276 * specify the interface index.
277 *
278 * @params libtrace_packet_t meta packet to extract the ipv4 address from.
279 * @params A pointer to a character buffer to store the ipv4 address string in.
280 * @params The size of the buffer passed in.
281 * @params The interface index within the meta packet.
282 * @returns Pointer to the character buffer containing the ipv4 address string or NULL.
283 */
284/* UNTESTED */
285char *trace_get_interface_ipv4_string(libtrace_packet_t *packet, char *space, int spacelen,
286        int index) {
287
288        uint32_t addr = htonl(trace_get_interface_ipv4(packet, index));
289        if (addr == 0) { return NULL; }
290
291        char *addrstr = inet_ntoa(*(struct in_addr *)&addr);
292        memcpy(space, addrstr, spacelen);
293        return space;
294}
295
296/* Get the interface ipv6 address/s for a meta packet.
297 * Must be destroyed with trace_destroy_meta().
298 *
299 * @params libtrace_packet_t meta packet.
300 * @returns Pointer to libtrace_meta_t structure containing all found ipv6 addresses
301 * or NULL.
302 */
303libtrace_meta_t *trace_get_interface_ipv6_meta(libtrace_packet_t *packet) {
304        if (trace_meta_check_input(packet, "trace_get_interface_ip6()")<0) {
305                return NULL;
306        }
307
308        libtrace_meta_t *r = NULL;
309
310        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
311                r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_IPV4);
312        }
313        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
314                r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_IP4);
315        }
316
317        return r;
318}
319/* Get the interface ipv6 address for a meta packet.
320 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
321 * specify the interface index.
322 *
323 * @params libtrace_packet_t meta packet to extract the ipv6 address from.
324 * @params A pointer to a character buffer to store the ipv6 address in.
325 * @params The size of the buffer passed in.
326 * @params The interface index within the meta packet.
327 * @returns Pointer to the buffer containing the ipv6 address or NULL.
328 */
329void *trace_get_interface_ipv6(libtrace_packet_t *packet, void *space, int spacelen,
330        int index) {
331
332        libtrace_meta_t *r = trace_get_interface_ipv6_meta(packet);
333        if (r == NULL) { return NULL; }
334        if (r->num <= index) { return NULL; }
335        if (r->items[index].len > spacelen) {
336                memcpy(space, r->items[index].data, spacelen);
337        } else {
338                memcpy(space, r->items[index].data, r->items[index].len);
339        }
340        trace_destroy_meta(r);
341        return space;
342}
343/* Get the interface ipv6 address string for a meta packet.
344 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
345 * specify the interface index.
346 *
347 * @params libtrace_packet_t meta packet to extract the ipv6 address from.
348 * @params A pointer to a character buffer to store the ipv6 address in.
349 * @params The size of the buffer passed in.
350 * @params The interface index within the meta packet.
351 * @returns Pointer to the character buffer containing the ipv6 address string or NULL.
352 */
353/* UNTESTED */
354char *trace_get_interface_ipv6_string(libtrace_packet_t *packet, char *space, int spacelen,
355        int index) {
356
357        if (spacelen < INET6_ADDRSTRLEN) {
358                return NULL;
359        }
360
361        void *addr = calloc(1, 16);
362        void *r = trace_get_interface_ipv6(packet, addr, 16, index);
363
364        if (r == NULL) {
365                return NULL;
366        }
367
368        inet_ntop(AF_INET6, addr, space, INET6_ADDRSTRLEN);
369        free(addr);
370
371        return space;
372}
373
374
375/* Get the interface description/s for a meta packet.
376 * Must be destroyed with trace_destroy_meta().
377 *
378 * @params libtrace_packet_t meta packet.
379 * @returns Pointer to libtrace_meta_t structure containing all found interface
380 * descriptions or NULL.
381 */
382libtrace_meta_t *trace_get_interface_description_meta(libtrace_packet_t *packet) {
383        if (trace_meta_check_input(packet, "trace_get_interface_description()")<0) {
384                return NULL;
385        }
386
387        libtrace_meta_t *r = NULL;
388
389        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
390                r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_DESCR);
391        }
392        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
393                r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_DESCR);
394        }
395
396        return r;
397}
398/* Get the interface description for a meta packet.
399 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
400 * specify the interface index.
401 *
402 * @params libtrace_packet_t meta packet to extract the interface description from.
403 * @params A pointer to a character buffer to store the interface description in.
404 * @params The size of the buffer passed in.
405 * @params The interface index within the meta packet.
406 * @returns Pointer to the character buffer containing the interface description or NULL.
407 */
408char *trace_get_interface_description(libtrace_packet_t *packet, char *space, int spacelen,
409        int index) {
410
411        libtrace_meta_t *r = trace_get_interface_description_meta(packet);
412        if (r == NULL) { return NULL; }
413        if (r->num <= index) { return NULL; }
414        if (r->items[index].len > spacelen) {
415                memcpy(space, r->items[index].data, spacelen);
416        } else {
417                memcpy(space, r->items[index].data, r->items[index].len);
418        }
419        trace_destroy_meta(r);
420        return space;
421}
422
423
424/* Get the host OS for a meta packet.
425 * Must be destroyed with trace_destroy_meta().
426 *
427 * @params libtrace_packet_t meta packet.
428 * @returns Pointer to libtrace_meta_t structure containing the host OS or NULL.
429 */
430libtrace_meta_t *trace_get_host_os_meta(libtrace_packet_t *packet) {
431        if (trace_meta_check_input(packet, "trace_get_host_os()")<0) {
432                return NULL;
433        }
434
435        libtrace_meta_t *r = NULL;
436
437        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
438                r = trace_get_meta_option(packet, ERF_PROV_SECTION_HOST, ERF_PROV_OS);
439        }
440        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
441                r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_OS);
442        }
443
444        return r;
445}
446/* Get the host OS for a meta packet.
447 *
448 * @params libtrace_packet_t meta packet to extract the host OS from.
449 * @params A pointer to a character buffer to store the host OS in.
450 * @params The size of the buffer passed in.
451 * @returns Pointer to the character buffer containing the host OS or NULL.
452 */
453char *trace_get_host_os(libtrace_packet_t *packet, char *space, int spacelen) {
454        libtrace_meta_t *r = trace_get_host_os_meta(packet);
455        if (r == NULL) { return NULL; }
456        if (r->items[0].len > spacelen) {
457                memcpy(space, r->items[0].data, spacelen);
458        } else {
459                memcpy(space, r->items[0].data, r->items[0].len);
460        }
461        trace_destroy_meta(r);
462        return space;
463}
464
465/* Get the interface frame check sequence length for a meta packet.
466 * Must be destroyed with trace_destroy_meta().
467 *
468 * @params libtrace_packet_t meta packet.
469 * @returns Pointer to libtrace_meta_t structure containing all found frame check
470 * sequence lengths or NULL.
471 */
472libtrace_meta_t *trace_get_interface_fcslen_meta(libtrace_packet_t *packet) {
473        if (trace_meta_check_input(packet, "trace_get_interface_frame_check_sequence_length()")<0) {
474                return NULL;
475        }
476
477        libtrace_meta_t *r = NULL;
478
479        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
480                r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_FCS_LEN);
481        }
482        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
483                r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_FCSLEN);
484        }
485
486        return r;
487}
488/* Get the interface frame check sequence length for a meta packet.
489 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
490 * specify the interface index.
491 *
492 * @params libtrace_packet_t meta packet to extract the interface fcslen from.
493 * @params The interface index within the meta packet.
494 * @returns uint32_t frame check sequence length or 0.
495 */
496uint32_t trace_get_interface_fcslen(libtrace_packet_t *packet, int index) {
497        libtrace_meta_t *r = trace_get_interface_fcslen_meta(packet);
498        if (r == NULL) { return 0; }
499        if (r->num <= index) { return 0; }
500        uint32_t data = *(uint32_t *)r->items[index].data;
501        trace_destroy_meta(r);
502        return data;
503}
504
505/* Get any interface comments for a meta packet
506 * Must be destroyed with trace_destroy_meta()
507 *
508 * @params libtrace_packet_t packet
509 * @returns Pointer to libtrace_meta_t structure or NULL
510 */
511libtrace_meta_t *trace_get_interface_comment_meta(libtrace_packet_t *packet) {
512        if (trace_meta_check_input(packet, "trace_get_interface_comment()")<0) {
513                return NULL;
514        }
515
516        libtrace_meta_t *r = NULL;
517
518        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
519                r = trace_get_meta_option(packet, ERF_PROV_SECTION_INTERFACE, ERF_PROV_COMMENT);
520        }
521        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
522                r = trace_get_meta_option(packet, PCAPNG_INTERFACE_TYPE, PCAPNG_OPTION_COMMENT);
523        }
524
525        return r;
526}
527/* Get the interface comment for a meta packet.
528 * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
529 * specify the interface ID.
530 *
531 * @params libtrace_packet_t meta packet to extract the interface comment from.
532 * @params A pointer to a character buffer to store the interface description in.
533 * @params The size of the buffer passed in.
534 * @params The interface number within the meta packet.
535 * @returns Pointer to the character buffer containing the hardware description or NULL.
536 */
537char *trace_get_interface_comment(libtrace_packet_t *packet, char *space, int spacelen,
538        int index) {
539
540        libtrace_meta_t *r = trace_get_interface_comment_meta(packet);
541        if (r == NULL) { return NULL; }
542        if (index > r->num) { return NULL; }
543        if (r->items[index].len > spacelen) {
544                memcpy(space, r->items[index].data, spacelen);
545        } else {
546                memcpy(space, r->items[index].data, r->items[index].len);
547        }
548        trace_destroy_meta(r);
549        return space;
550}
551
552/* Get the capture application for a meta packet
553 * Must be destroyed with trace_destroy_meta()
554 *
555 * @params libtrace_packet_t packet
556 * @returns Pointer to libtrace_meta_t structure or NULL
557 */
558libtrace_meta_t *trace_get_capture_application_meta(libtrace_packet_t *packet) {
559        if (trace_meta_check_input(packet, "trace_get_interface_comment()")<0) {
560                return NULL;
561        }
562
563        libtrace_meta_t *r = NULL;
564
565        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
566                r = trace_get_meta_option(packet, ERF_PROV_SECTION_CAPTURE, ERF_PROV_APP_NAME);
567        }
568        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
569                r = trace_get_meta_option(packet, PCAPNG_SECTION_TYPE, PCAPNG_META_SHB_USERAPPL);
570        }
571
572        return r;
573}
574/* Get the capture application for a meta packet.
575 *
576 * @params libtrace_packet_t meta packet to extract the application name from.
577 * @params A pointer to a character buffer to store the application name in.
578 * @params The size of the buffer passed in.
579 * @returns Pointer to the character buffer containing the application name or NULL.
580 */
581char *trace_get_capture_application(libtrace_packet_t *packet, char *space, int spacelen) {
582        libtrace_meta_t *r = trace_get_capture_application_meta(packet);
583        if (r == NULL) { return NULL; }
584        if (r->items[0].len > spacelen) {
585                memcpy(space, r->items[0].data, spacelen);
586        } else {
587                memcpy(space, r->items[0].data, r->items[0].len);
588        }
589        trace_destroy_meta(r);
590        return space;
591}
592
593/* Get a meta section option from a meta packet
594 * Must be destroyed with trace_destroy_meta()
595 *
596 * @params libtrace_packet_t packet
597 * @params Section code
598 * @params Option code
599 * @returns Pointer to libtrace_meta_t structure or NULL
600 */
601libtrace_meta_t *trace_get_section_option(libtrace_packet_t *packet, uint32_t section_code,
602        uint16_t option_code) {
603
604        if (trace_meta_check_input(packet, "trace_get_custom_meta()")<0) {
605                return NULL;
606        }
607
608        return trace_get_meta_option(packet, section_code, option_code);
609}
610
611/* Get a section from a meta packet
612 * Must be destroyed with trace_destroy_meta()
613 *
614 * @params libtrace_packet_t packet
615 * @params Section code
616 * @returns Pointer to libtrace_meta_t structure or NULL
617 */
618libtrace_meta_t *trace_get_section(libtrace_packet_t *packet, uint32_t section_code) {
619        if (trace_meta_check_input(packet, "trace_get_section()")<0) {
620                return NULL;
621        }
622
623        return packet->trace->format->get_meta_section(packet, section_code);
624}
625
626/* ERF specific function */
627/* Get the DAG card model from a meta packet.
628 *
629 * @params libtrace_packet_t meta packet to extract the DAG model from.
630 * @params A pointer to a character buffer to store the DAG model in.
631 * @params The size of the buffer passed in.
632 * @returns Pointer to the character buffer containing the DAG model or NULL.
633 */
634char *trace_get_erf_dag_card_model(libtrace_packet_t *packet, char *space, int spacelen) {
635        libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE,
636                ERF_PROV_MODEL);
637
638        if (r == NULL) { return NULL; }
639        if (r->items[0].len > spacelen) {
640                memcpy(space, r->items[0].data, spacelen);
641        } else {
642                memcpy(space, r->items[0].data, r->items[0].len);
643        }
644        trace_destroy_meta(r);
645        return space;
646}
647/* Get the host DAG software version for a meta packet.
648 *
649 * @params libtrace_packet_t meta packet to extract the hosts DAG verion from.
650 * @params A pointer to a character buffer to store the DAG version in.
651 * @params The size of the buffer passed in.
652 * @returns Pointer to the character buffer containing the DAG version or NULL.
653 */
654char *trace_get_erf_dag_version(libtrace_packet_t *packet, char *space, int spacelen) {
655        libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE,
656                ERF_PROV_DAG_VERSION);
657
658        if (r == NULL) { return NULL; }
659
660        if (r->items[0].len > spacelen) {
661                memcpy(space, r->items[0].data, spacelen);
662        } else {
663                memcpy(space, r->items[0].data, r->items[0].len);
664        }
665        trace_destroy_meta(r);
666        return space;
667}
668/* Get the firmware version for a DAG module from a meta packet.
669 *
670 * @params libtrace_packet_t meta packet to extract the FW version from.
671 * @params A pointer to a character buffer to store the FW version in.
672 * @params The size of the buffer passed in.
673 * @returns Pointer to the character buffer containing the FW version or NULL.
674 */
675char *trace_get_erf_dag_fw_version(libtrace_packet_t *packet, char *space, int spacelen) {
676        libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE,
677                ERF_PROV_FW_VERSION);
678
679        if (r == NULL) { return NULL; }
680
681        if (r->items[0].len > spacelen) {
682                memcpy(space, r->items[0].data, spacelen);
683        } else {
684                memcpy(space, r->items[0].data, r->items[0].len);
685        }
686        trace_destroy_meta(r);
687        return space;
688}
689
Note: See TracBrowser for help on using the repository browser.