Changeset cb8c1b9 for examples/tracedump/tracedump-libtrace.cc
- Timestamp:
- 02/22/05 16:08:14 (17 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- 68667ee
- Parents:
- fb1de29
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/tracedump/tracedump-libtrace.cc
r3fe7937 rcb8c1b9 4 4 #include "tracedump.h" 5 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 } 6 18 7 19 int main(int argc,char **argv) 8 20 { 9 struct libtrace_t *trace = trace_create(argv[1]);21 struct libtrace_t *trace = NULL; 10 22 struct libtrace_packet_t packet; 11 23 struct libtrace_filter_t *filter=NULL; 24 uint64_t count=0; 25 uint64_t numpackets=0; 12 26 13 if (!trace) { 14 errx(1,"Failed to open trace"); 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 } 15 56 } 57 58 16 59 17 if (argc>2) 18 filter=trace_bpf_setfilter(argv[2]); 60 while(optind <argc) { 61 trace = trace_create(argv[optind]); 62 numpackets = 0; 63 if (!trace) { 64 errx(1,"Failed to open trace"); 65 } 19 66 20 while(trace_read_packet(trace,&packet)> 0 ){21 time_t sec = (time_t)trace_get_seconds(&packet);22 char *link=(char *)trace_get_link(&packet);23 if (filter && !trace_bpf_filter(filter,&packet))24 continue;67 while(trace_read_packet(trace,&packet)> 0 ){ 68 time_t sec = (time_t)trace_get_seconds(&packet); 69 char *link=(char *)trace_get_link(&packet); 70 if (filter && !trace_bpf_filter(filter,&packet)) 71 continue; 25 72 26 printf("%s",ctime(&sec)); 27 per_packet(trace_get_link_type(&packet), 28 link, 29 packet.size-(link-packet.buffer)); 73 printf("%s",ctime(&sec)); 74 per_packet(trace_get_link_type(&packet), 75 link, 76 packet.size-(link-packet.buffer)); 77 if(count) { 78 numpackets++; 79 if (numpackets == count) 80 break; 81 } 82 } 83 84 trace_destroy(trace); 85 optind ++; 30 86 } 31 32 trace_destroy(trace);33 87 return 0; 34 88 }
Note: See TracChangeset
for help on using the changeset viewer.