source: examples/skeleton/output.c @ d025ff7

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since d025ff7 was 0f42351, checked in by Perry Lorier <perry@…>, 15 years ago

Lots more warnings squashed

  • Property mode set to 100644
File size: 2.0 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
10static void per_packet(libtrace_packet_t *packet)
11{
12        /* Your code goes here */
13}
14
15int main(int argc, char *argv[])
16{
17        libtrace_t *trace;
18        libtrace_out_t *output;
19        libtrace_packet_t *packet;
20        int compress_level = 6;
21       
22        if (argc<3) {
23                fprintf(stderr,"usage: %s <input uri> <outputuri>\n",argv[0]);
24                return 1;
25        }
26
27        trace = trace_create(argv[1]);
28
29        if (trace_is_err(trace)) {
30                trace_perror(trace,"Opening input trace");
31                return 1;
32        }
33
34        if (trace_start(trace)) {
35                trace_perror(trace,"Starting input trace");
36                trace_destroy(trace);
37                return 1;
38        }
39
40        /* Creating output trace */
41        output = trace_create_output(argv[2]);
42       
43        if (trace_is_err_output(output)) {
44                trace_perror_output(output, "Opening output trace");
45                return 1;
46        }
47
48        /* Setting compression level */
49        if (trace_config_output(output, TRACE_OPTION_OUTPUT_COMPRESS, 
50                                &compress_level) == -1) {
51                trace_perror_output(output, "Setting compression level");
52                trace_destroy(trace);
53                trace_destroy_output(output);
54                return 1;
55        }
56       
57        if (trace_start_output(output)) {
58                trace_perror_output(output, "Starting output trace");
59                trace_destroy_output(output);
60                trace_destroy(trace);
61                return 1;
62        }
63               
64        packet = trace_create_packet();
65
66        while (trace_read_packet(trace,packet)>0) {
67                /* Perhaps we want to do something to the packet first */
68                per_packet(packet);
69
70                /* Write out the packet */
71                if (trace_write_packet(output, packet) < 0) {
72                        trace_perror_output(output, "Writing packet");
73                        trace_destroy(trace);
74                        trace_destroy_output(output);
75                        trace_destroy_packet(packet);
76                        return 1;
77                }
78               
79        }
80       
81
82        if (trace_is_err(trace)) {
83                trace_perror(trace,"Reading packets");
84                trace_destroy(trace);
85                trace_destroy_output(output);
86                trace_destroy_packet(packet);
87                return 1;
88        }
89
90        trace_destroy(trace);
91        trace_destroy_output(output);
92        trace_destroy_packet(packet);
93       
94        return 0;
95}
Note: See TracBrowser for help on using the repository browser.