source: examples/skeleton/trivial.c @ 48a20e3

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

Add some skeleton programs for people to use as a template

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/* Trivial libtrace skeleton program
2 *
3 * This libtrace skeleton has the bare minimum required to write a useful
4 * libtrace program, including error handling.
5 *
6 * If you are going to base your program on anything, you should look at the
7 * complete.c and use that.
8 *
9 */
10#include "libtrace.h"
11#include <stdio.h>
12
13void per_packet(libtrace_packet_t *packet)
14{
15        /* Your code goes here */
16}
17
18int main(int argc, char *argv[])
19{
20        libtrace_t *trace;
21        libtrace_packet_t *packet;
22
23        if (argc<2) {
24                fprintf(stderr,"usage: %s libtraceuri\n",argv[0]);
25                return 1;
26        }
27
28        trace = trace_create(argv[1]);
29
30        if (trace_is_err(trace)) {
31                trace_perror(trace,"Opening trace file");
32                return 1;
33        }
34
35        if (trace_start(trace)) {
36                trace_perror(trace,"Starting trace");
37                trace_destroy(trace);
38                return 1;
39        }
40
41        packet = trace_create_packet();
42
43        while (trace_read_packet(trace,packet)>0) {
44                per_packet(packet);
45        }
46
47        if (trace_is_err(trace)) {
48                trace_perror(trace,"Reading packets");
49                trace_destroy(trace);
50                return 1;
51        }
52
53        trace_destroy(trace);
54
55        return 0;
56}
Note: See TracBrowser for help on using the repository browser.