4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change
on this file since 853603a was
853603a,
checked in by Perry Lorier <perry@…>, 15 years ago
|
Migrate tools to the new API
|
-
Property mode set to
100644
|
File size:
1.8 KB
|
Line | |
---|
1 | #include <libtrace.h> |
---|
2 | #include <err.h> |
---|
3 | #include <time.h> |
---|
4 | #include "libpacketdump.h" |
---|
5 | #include <stdio.h> |
---|
6 | #include <stdlib.h> |
---|
7 | #include <getopt.h> |
---|
8 | |
---|
9 | void usage(char *argv0) |
---|
10 | { |
---|
11 | fprintf(stderr,"Usage:\n" |
---|
12 | "%s flags inputfile\n" |
---|
13 | "-f --filter=expr BPF filter specification, quoted\n" |
---|
14 | "-c --count=num terminate after num packets\n" |
---|
15 | ,argv0); |
---|
16 | exit(0); |
---|
17 | } |
---|
18 | |
---|
19 | int main(int argc,char **argv) |
---|
20 | { |
---|
21 | struct libtrace_t *trace = NULL; |
---|
22 | struct libtrace_packet_t *packet = trace_create_packet(); |
---|
23 | struct libtrace_filter_t *filter=NULL; |
---|
24 | uint64_t count=0; |
---|
25 | uint64_t numpackets=0; |
---|
26 | |
---|
27 | |
---|
28 | if (argc<2) |
---|
29 | usage(argv[0]); |
---|
30 | |
---|
31 | while(1) { |
---|
32 | int option_index; |
---|
33 | struct option long_options[] = { |
---|
34 | { "filter", 1, 0, 'f' }, |
---|
35 | { "count", 1, 0, 'c' }, |
---|
36 | { NULL, 0, 0, 0 }, |
---|
37 | }; |
---|
38 | |
---|
39 | int c=getopt_long(argc,argv,"f:c:", |
---|
40 | long_options, &option_index); |
---|
41 | if (c == -1) |
---|
42 | break; |
---|
43 | switch(c) { |
---|
44 | case 'f': |
---|
45 | if (filter!=NULL) { |
---|
46 | fprintf(stderr,"You can only have one filter (quote it with " ")\n"); |
---|
47 | usage(argv[0]); |
---|
48 | } |
---|
49 | filter=trace_create_filter(optarg); |
---|
50 | break; |
---|
51 | case 'c': count=atol(optarg); break; |
---|
52 | default: |
---|
53 | printf("unknown option: %c\n",c); |
---|
54 | usage(argv[0]); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | while(optind <argc) { |
---|
61 | trace = trace_create(argv[optind]); |
---|
62 | optind ++; |
---|
63 | numpackets = 0; |
---|
64 | if (trace_is_err(trace)) { |
---|
65 | trace_perror(trace,"trace_create"); |
---|
66 | trace_destroy(trace); |
---|
67 | continue; |
---|
68 | } |
---|
69 | |
---|
70 | trace_start(trace); |
---|
71 | if (trace_is_err(trace)) { |
---|
72 | trace_perror(trace,"trace_start"); |
---|
73 | trace_destroy(trace); |
---|
74 | continue; |
---|
75 | } |
---|
76 | while(trace_read_packet(trace,packet)> 0 ){ |
---|
77 | if (filter && !trace_apply_filter(filter,packet)) |
---|
78 | continue; |
---|
79 | |
---|
80 | trace_dump_packet(packet); |
---|
81 | |
---|
82 | if(count) { |
---|
83 | numpackets++; |
---|
84 | if (numpackets == count) |
---|
85 | break; |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | printf("\n"); |
---|
90 | trace_destroy(trace); |
---|
91 | } |
---|
92 | return 0; |
---|
93 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.