File: trivial.c

package info (click to toggle)
libtrace3 3.0.7-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,676 kB
  • ctags: 3,140
  • sloc: ansic: 20,551; sh: 10,125; cpp: 1,384; makefile: 415; yacc: 96; lex: 50
file content (63 lines) | stat: -rw-r--r-- 1,178 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Trivial libtrace skeleton program
 *
 * This libtrace skeleton has the bare minimum required to write a useful
 * libtrace program, including error handling.
 *
 * If you are going to base your program on anything, you should look at the
 * complete.c and use that.
 *
 */
#include "libtrace.h"
#include <stdio.h>
#include <assert.h>

static void per_packet(libtrace_packet_t *packet)
{
	/* You really should consider using complete.c instead */
	assert(packet);
	
	/* Your code goes here */

}

int main(int argc, char *argv[])
{
	libtrace_t *trace;
	libtrace_packet_t *packet;

	if (argc<2) {
		fprintf(stderr,"usage: %s libtraceuri\n",argv[0]);
		return 1;
	}

	trace = trace_create(argv[1]);

	if (trace_is_err(trace)) {
		trace_perror(trace,"Opening trace file");
		return 1;
	}

	if (trace_start(trace)) {
		trace_perror(trace,"Starting trace");
		trace_destroy(trace);
		return 1;
	}

	packet = trace_create_packet();

	while (trace_read_packet(trace,packet)>0) {
		per_packet(packet);
	}

	trace_destroy_packet(packet);

	if (trace_is_err(trace)) {
		trace_perror(trace,"Reading packets");
		trace_destroy(trace);
		return 1;
	}

	trace_destroy(trace);

	return 0;
}