4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change
on this file since 3840760 was
3840760,
checked in by Daniel Lawson <dlawson@…>, 17 years ago
|
updated the examples/ and tools/ directories to correctly use trace_packet_create() now.
fixed a typo in format_wag (shouldn't use pcap_get_framing_length for wag!)
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[fd9d44c] | 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; |
---|
[3840760] | 22 | struct libtrace_packet_t *packet = trace_packet_create(); |
---|
[fd9d44c] | 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_bpf_setfilter(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 | numpackets = 0; |
---|
| 63 | if (!trace) { |
---|
| 64 | errx(1,"Failed to open trace"); |
---|
| 65 | } |
---|
| 66 | |
---|
[3840760] | 67 | while(trace_read_packet(trace,packet)> 0 ){ |
---|
| 68 | if (filter && !trace_bpf_filter(filter,packet)) |
---|
[fd9d44c] | 69 | continue; |
---|
| 70 | |
---|
[3840760] | 71 | trace_dump_packet(packet); |
---|
[fd9d44c] | 72 | if(count) { |
---|
| 73 | numpackets++; |
---|
| 74 | if (numpackets == count) |
---|
| 75 | break; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
[0c9681f] | 79 | printf("\n"); |
---|
[fd9d44c] | 80 | trace_destroy(trace); |
---|
| 81 | optind ++; |
---|
| 82 | } |
---|
| 83 | return 0; |
---|
| 84 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.