source: examples/skeleton/output.c @ d420777

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since d420777 was f724640, checked in by Shane Alcock <salcock@…>, 10 years ago
  • Fix warnings in the skeleton code
  • Property mode set to 100644
File size: 2.1 KB
Line 
1/* An example program that demonstrates libtrace's output functionalities.
2 *
3 * This libtrace skeleton has the bare minimum required to write a useful
4 * libtrace output program, including error handling.
5 *
6 */
7#include "libtrace.h"
8#include <stdio.h>
9#include <assert.h>
10
11static void per_packet(libtrace_packet_t *packet)
12{
13        assert(packet);
14        /* Your code goes here */
15}
16
17int main(int argc, char *argv[])
18{
19        libtrace_t *trace;
20        libtrace_out_t *output;
21        libtrace_packet_t *packet;
22        int compress_level = 6;
23       
24        if (argc<3) {
25                fprintf(stderr,"usage: %s <input uri> <outputuri>\n",argv[0]);
26                return 1;
27        }
28
29        trace = trace_create(argv[1]);
30
31        if (trace_is_err(trace)) {
32                trace_perror(trace,"Opening input trace");
33                return 1;
34        }
35
36        if (trace_start(trace)) {
37                trace_perror(trace,"Starting input trace");
38                trace_destroy(trace);
39                return 1;
40        }
41
42        /* Creating output trace */
43        output = trace_create_output(argv[2]);
44       
45        if (trace_is_err_output(output)) {
46                trace_perror_output(output, "Opening output trace");
47                return 1;
48        }
49
50        /* Setting compression level */
51        if (trace_config_output(output, TRACE_OPTION_OUTPUT_COMPRESS, 
52                                &compress_level) == -1) {
53                trace_perror_output(output, "Setting compression level");
54                trace_destroy(trace);
55                trace_destroy_output(output);
56                return 1;
57        }
58       
59        if (trace_start_output(output)) {
60                trace_perror_output(output, "Starting output trace");
61                trace_destroy_output(output);
62                trace_destroy(trace);
63                return 1;
64        }
65               
66        packet = trace_create_packet();
67
68        while (trace_read_packet(trace,packet)>0) {
69                /* Perhaps we want to do something to the packet first */
70                per_packet(packet);
71
72                /* Write out the packet */
73                if (trace_write_packet(output, packet) < 0) {
74                        trace_perror_output(output, "Writing packet");
75                        trace_destroy(trace);
76                        trace_destroy_output(output);
77                        trace_destroy_packet(packet);
78                        return 1;
79                }
80               
81        }
82       
83
84        if (trace_is_err(trace)) {
85                trace_perror(trace,"Reading packets");
86                trace_destroy(trace);
87                trace_destroy_output(output);
88                trace_destroy_packet(packet);
89                return 1;
90        }
91
92        trace_destroy(trace);
93        trace_destroy_output(output);
94        trace_destroy_packet(packet);
95       
96        return 0;
97}
Note: See TracBrowser for help on using the repository browser.