Changeset 1974620 for examples/munge/munge.c
- Timestamp:
- 08/25/05 20:01:13 (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:
- b5cd711
- Parents:
- 3073c04
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/munge/munge.c
raca3ff4 r1974620 12 12 #include <time.h> 13 13 14 static int trace_link_type_to_dlt(libtrace_linktype_t t)15 {16 static int table[] = {17 -1, /* LEGACY */18 -1, /* HDLC over POS */19 DLT_EN10MB, /* Ethernet */20 -1, /* ATM */21 DLT_IEEE802_11, /* 802.11 */22 };23 if (t>sizeof(table)/sizeof(*table)) {24 return -1;25 }26 return table[t];27 }28 14 29 15 void usage(char *argv0) 30 16 { 31 17 fprintf(stderr,"Usage:\n" 32 "%s flags inputfile >outputfile\n"18 "%s flags inputfile outputfile\n" 33 19 "-s --encrypt-source Encrypt the source addresses\n" 34 20 "-d --encrypt-dest Encrypt the destination addresses\n" … … 144 130 } 145 131 146 struct libtrace_write_t {147 pcap_dumper_t *pcap;148 };149 150 void trace_write(struct libtrace_write_t *hdl,struct libtrace_packet_t *pkt)151 {152 struct pcap_pkthdr pcap_pkt_hdr;153 void *link = trace_get_link(pkt);154 155 pcap_pkt_hdr.ts=trace_get_timeval(pkt);156 pcap_pkt_hdr.caplen = trace_get_capture_length(pkt);157 pcap_pkt_hdr.len = trace_get_wire_length(pkt);158 pcap_dump((u_char*)hdl->pcap, &pcap_pkt_hdr, link);159 }160 161 132 double parse_date(const char *date) 162 133 { … … 205 176 char *key = NULL; 206 177 struct libtrace_filter_t *filter = NULL; 207 struct libtrace_t *trace ;178 struct libtrace_t *trace = 0; 208 179 struct libtrace_packet_t packet; 209 struct libtrace_ write_t writer;180 struct libtrace_out_t *writer = 0; 210 181 bool enc_source = false; 211 182 bool enc_dest = false; 212 183 double start_time = 0; 213 184 double end_time = 1e100; 214 pcap_t *p = NULL;185 char *output = 0; 215 186 216 187 if (argc<2) … … 278 249 trace_enc_init(enc_type,key); 279 250 280 p = NULL; 281 282 while(optind<argc) { 283 /* Do the actual processing */ 284 trace = trace_create(argv[optind]); 285 if (!trace) { 286 fprintf(stderr,"Cannot open %s\n",argv[optind]); 287 return 1; 288 } 289 for(;;) { 290 struct libtrace_ip *ipptr; 291 int psize; 292 double ts; 293 if ((psize = trace_read_packet(trace, &packet)) <= 0) { 294 break; 295 } 296 if (!p) { 297 p=pcap_open_dead( 298 trace_link_type_to_dlt( 299 trace_get_link_type(&packet)), 300 65536); 301 writer.pcap = pcap_dump_open(p,"-"); 302 fflush((FILE *)writer.pcap); 303 } 304 305 /* Skip packets that don't match the filter */ 306 if (filter && !trace_bpf_filter(filter,&packet)) { 307 continue; 308 } 309 310 ts = trace_get_seconds(&packet); 311 312 /* skip packets before/after the time */ 313 if (ts < start_time || ts > end_time) { 314 continue; 315 } 316 317 ipptr = trace_get_ip(&packet); 318 319 if (ipptr && (enc_source || enc_dest)) 320 encrypt_ips(ipptr,enc_source,enc_dest); 321 322 /* TODO: Encrypt IP's in ARP packets */ 323 324 trace_write(&writer,&packet); 325 } 326 optind++; 251 // open input uri 252 trace = trace_create(argv[optind]); 253 if (!trace) { 254 fprintf(stderr,"Cannot open %s\n",argv[optind]); 255 trace_perror(argv[optind]); 256 return 1; 257 } 258 259 if (optind == argc) { 260 // no output specified, output in same format to stdout 261 asprintf(&output,"%s:-","erf"); 262 writer = trace_output_create(output); 263 } else { 264 writer = trace_output_create(argv[optind +1]); 265 } 266 if (!writer) { 267 trace_perror("trace_output_create"); 268 return 1; 269 } 270 271 272 for(;;) { 273 struct libtrace_ip *ipptr; 274 int psize; 275 double ts; 276 if ((psize = trace_read_packet(trace, &packet)) <= 0) { 277 break; 278 } 279 280 /* Skip packets that don't match the filter */ 281 if (filter && !trace_bpf_filter(filter,&packet)) { 282 continue; 283 } 284 285 ts = trace_get_seconds(&packet); 286 287 /* skip packets before/after the time */ 288 if (ts < start_time || ts > end_time) { 289 continue; 290 } 291 292 ipptr = trace_get_ip(&packet); 293 294 if (ipptr && (enc_source || enc_dest)) 295 encrypt_ips(ipptr,enc_source,enc_dest); 296 297 /* TODO: Encrypt IP's in ARP packets */ 298 299 trace_write_packet(writer,&packet); 327 300 } 328 301 return 0;
Note: See TracChangeset
for help on using the changeset viewer.