Changeset 2b9a4c7
- Timestamp:
- 11/21/09 00:42:12 (11 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:
- 05000f9
- Parents:
- 099c35e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/tracereplay/tracereplay.c
r9b8ece6 r2b9a4c7 17 17 #include <string.h> 18 18 #include <libtrace.h> 19 #include <getopt.h> 19 20 20 21 static libtrace_packet_t * per_packet(libtrace_packet_t *packet) { … … 28 29 29 30 trace_construct_packet(new_packet,linktype,pkt_buffer,wire_length); 30 31 31 32 32 return new_packet; … … 82 82 } 83 83 } 84 84 85 static void usage(char * argv) { 86 fprintf(stderr, "usage: %s [options] libtraceuri outputuri...\n", argv); 87 fprintf(stderr, " --filter bpfexpr\n"); 88 fprintf(stderr, " -f bpfexpr\n"); 89 fprintf(stderr, "\t\tApply a bpf filter expression\n"); 90 } 91 85 92 int main(int argc, char *argv[]) { 86 93 … … 88 95 libtrace_out_t *output; 89 96 libtrace_packet_t *packet; 97 libtrace_filter_t *filter=NULL; 90 98 int psize = 0; 91 99 char *uri = 0; 92 93 if (argc == 3) { 94 uri = strdup(argv[1]); 95 } else { 96 fprintf(stderr,"usage: %s <input uri> <outputuri>\n",argv[0]); 97 return -1; 98 } 100 101 while(1) { 102 int option_index; 103 struct option long_options[] = { 104 { "filter", 1, 0, 'f'}, 105 { "help", 0, 0, 'h'}, 106 { NULL, 0, 0, 0} 107 }; 108 109 int c = getopt_long(argc, argv, "f:", 110 long_options, &option_index); 111 112 if(c == -1) 113 break; 114 115 switch (c) { 116 case 'f': 117 filter = trace_create_filter(optarg); 118 break; 119 case 'h': 120 usage(argv[0]); 121 return 1; 122 default: 123 fprintf(stderr, "Unknown option: %c\n", c); 124 } 125 } 126 127 if(optind>=argc) { 128 fprintf(stderr, "Missing input uri\n"); 129 usage(argv[0]); 130 return 1; 131 } 132 if(optind+1>=argc) { 133 fprintf(stderr, "Missing output uri\n"); 134 usage(argv[0]); 135 return 1; 136 } 137 138 uri = strdup(argv[optind]); 99 139 100 140 /* Create the trace */ … … 104 144 return 1; 105 145 } 106 146 147 /* apply filter */ 148 if(filter) { 149 if(trace_config(trace, TRACE_OPTION_FILTER, filter)) { 150 trace_perror(trace, "ignoring: "); 151 } 152 } 153 107 154 /* Starting the trace */ 108 155 if (trace_start(trace) != 0) { … … 112 159 113 160 /* Creating output trace */ 114 output = trace_create_output(argv[ 2]);161 output = trace_create_output(argv[optind+1]); 115 162 116 163 if (trace_is_err_output(output)) { 117 trace_perror_output(output, "Opening output trace ");164 trace_perror_output(output, "Opening output trace: "); 118 165 return 1; 119 166 } 120 167 if (trace_start_output(output)) { 121 trace_perror_output(output, "Starting output trace ");168 trace_perror_output(output, "Starting output trace: "); 122 169 trace_destroy_output(output); 123 170 trace_destroy(trace); 124 171 return 1; 125 172 } 126 127 173 128 174 packet = trace_create_packet(); … … 147 193 free(uri); 148 194 trace_destroy(trace); 195 trace_destroy_filter(filter); 149 196 trace_destroy_output(output); 150 197 trace_destroy_packet(packet);
Note: See TracChangeset
for help on using the changeset viewer.