Changeset 3073c04
- Timestamp:
- 08/24/05 15:34:32 (16 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:
- 1974620
- Parents:
- e01bfa8
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
r8781f93 r3073c04 31 31 - Version 2.0.20 32 32 * byte-ordering fixups for WAG 33 * writer functions for pcap and wag 33 34 34 35 - Version 2.0.19 -
lib/format_erf.c
rffc8c8d r3073c04 284 284 calloc(1,sizeof(struct libtrace_format_data_out_t)); 285 285 286 OPTIONS.erf.level = 1;286 OPTIONS.erf.level = 0; 287 287 asprintf(&filemode,"wb%d",OPTIONS.erf.level); 288 288 … … 290 290 // STDOUT 291 291 #if HAVE_ZLIB 292 libtrace->format_data->output.file = gzdopen(dup(1), filemode);292 OUTPUT.file = gzdopen(dup(1), filemode); 293 293 #else 294 libtrace->format_data->output.file = stdout;294 OUTPUT.file = stdout; 295 295 #endif 296 296 } … … 301 301 // ourselves. However, this way is messy and 302 302 // we lose any error checking on "open" 303 libtrace->format_data->output.file = gzdopen(open(304 305 306 303 OUTPUT.file = gzdopen(open( 304 libtrace->uridata, 305 O_CREAT | O_LARGEFILE | O_WRONLY, 306 S_IRUSR | S_IWUSR), filemode); 307 307 #else 308 libtrace->format_data->output.file = fdopen(open(309 310 311 308 OUTPUT.file = fdopen(open( 309 libtrace->uridata, 310 O_CREAT | O_LARGEFILE | O_WRONLY, 311 S_IRUSR | S_IWUSR), "w"); 312 312 #endif 313 313 } … … 352 352 353 353 static int erf_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 354 #if HAVE_ZLIB 354 355 int opt; 355 356 int level = OPTIONS.erf.level; … … 374 375 } else { 375 376 OPTIONS.erf.level = level; 376 return gzsetparams(libtrace->format_data->output.file, level, Z_DEFAULT_STRATEGY); 377 } 378 } 377 return gzsetparams(OUTPUT.file, level, Z_DEFAULT_STRATEGY); 378 } 379 } 380 #endif 379 381 return 0; 380 382 … … 405 407 static int erf_fin_output(struct libtrace_out_t *libtrace) { 406 408 #if HAVE_ZLIB 407 gzclose( libtrace->format_data->output.file);409 gzclose(OUTPUT.file); 408 410 #else 409 fclose( libtrace->format_data->output.file);411 fclose(OUTPUT.file); 410 412 #endif 411 413 } … … 413 415 414 416 static int rtclient_fin_output(struct libtrace_out_t *libtrace) { 415 rtserver_destroy( libtrace->format_data->output.rtserver);417 rtserver_destroy(OUTPUT.rtserver); 416 418 } 417 419 -
lib/format_pcap.c
rffc8c8d r3073c04 64 64 #if HAVE_PCAP 65 65 66 static struct libtrace_format_t *pcap_ptr = 0; 67 static struct libtrace_format_t *pcapint_ptr = 0; 68 66 69 #define CONNINFO libtrace->format_data->conn_info 67 70 #define INPUT libtrace->format_data->input 68 71 #define OUTPUT libtrace->format_data->output 69 72 struct libtrace_format_data_t { 70 73 union { … … 75 78 /** Information about the current state of the input device */ 76 79 union { 77 int fd;78 FILE *file;79 80 pcap_t *pcap; 80 81 } input; 81 82 }; 83 84 struct libtrace_format_data_out_t { 85 union { 86 char *path; 87 char *interface; 88 } conn_info; 89 struct { 90 pcap_t *pcap; 91 pcap_dumper_t *dump; 92 } output; 93 }; 94 95 static int linktype_to_dlt(libtrace_linktype_t t) { 96 static int table[] = { 97 -1, /* LEGACY */ 98 -1, /* HDLC over POS */ 99 DLT_EN10MB, /* Ethernet */ 100 -1, /* ATM */ 101 DLT_IEEE802_11, /* 802.11 */ 102 -1 /* END OF TABLE */ 103 }; 104 if (t>sizeof(table)/sizeof(*table)) { 105 return -1; 106 } 107 return table[t]; 108 } 82 109 83 110 static int pcap_init_input(struct libtrace_t *libtrace) { … … 126 153 } 127 154 155 static int pcap_init_output(struct libtrace_out_t *libtrace) { 156 char errbuf[PCAP_ERRBUF_SIZE]; 157 struct stat buf; 158 libtrace->format_data = (struct libtrace_format_data_out_t *) 159 malloc(sizeof(struct libtrace_format_data_out_t)); 160 CONNINFO.path = libtrace->uridata; 161 OUTPUT.pcap = NULL; 162 OUTPUT.dump = NULL; 163 } 164 128 165 static int pcapint_init_input(struct libtrace_t *libtrace) { 129 166 char errbuf[PCAP_ERRBUF_SIZE]; … … 145 182 146 183 static int pcap_fin_input(struct libtrace_t *libtrace) { 147 return -1; 184 pcap_close(INPUT.pcap); 185 free(libtrace->format_data); 186 return 0; 187 } 188 189 static int pcap_fin_output(struct libtrace_out_t *libtrace) { 190 pcap_dump_flush(OUTPUT.dump); 191 pcap_dump_close(OUTPUT.dump); 192 return 0; 148 193 } 149 194 … … 173 218 } 174 219 return (packet->size - sizeof(struct pcap_pkthdr)); 220 } 221 222 static int pcap_write_packet(struct libtrace_out_t *libtrace, struct libtrace_packet_t *packet) { 223 struct pcap_pkthdr pcap_pkt_hdr; 224 void *link = trace_get_link(packet); 225 226 if (!OUTPUT.pcap) { 227 OUTPUT.pcap = pcap_open_dead( 228 linktype_to_dlt(trace_get_link_type(packet)), 229 65536); 230 OUTPUT.dump = pcap_dump_open(OUTPUT.pcap,CONNINFO.path); 231 fflush((FILE *)OUTPUT.dump); 232 } 233 if (packet->trace->format == pcap_ptr || 234 packet->trace->format == pcapint_ptr) { 235 //if (!strncasecmp(packet->trace->format->name,"pcap",4)) { 236 // this is a pcap trace anyway 237 238 pcap_dump((u_char*)OUTPUT.dump,(struct pcap_pkthdr *)packet->buffer,link); 239 } else { 240 pcap_pkt_hdr.ts = trace_get_timeval(packet); 241 pcap_pkt_hdr.caplen = trace_get_capture_length(packet); 242 pcap_pkt_hdr.len = trace_get_wire_length(packet); 243 244 pcap_dump((u_char*)OUTPUT.pcap, &pcap_pkt_hdr, link); 245 } 246 return 0; 175 247 } 176 248 … … 322 394 "$Id$", 323 395 pcap_init_input, /* init_input */ 324 NULL,/* init_output */396 pcap_init_output, /* init_output */ 325 397 NULL, /* config_output */ 326 398 pcap_fin_input, /* fin_input */ 327 NULL,/* fin_output */399 pcap_fin_output, /* fin_output */ 328 400 pcap_read_packet, /* read_packet */ 329 NULL,/* write_packet */401 pcap_write_packet, /* write_packet */ 330 402 pcap_get_link, /* get_link */ 331 403 pcap_get_link_type, /* get_link_type */ … … 368 440 }; 369 441 442 //pcap_ptr = &pcap; 443 //pcapint_ptr = &pcapint; 444 370 445 void __attribute__((constructor)) pcap_constructor() { 371 register_format(&pcap); 372 register_format(&pcapint); 446 pcap_ptr = &pcap; 447 pcapint_ptr = &pcapint; 448 register_format(pcap_ptr); 449 register_format(pcapint_ptr); 373 450 } 374 451 -
lib/format_wag.c
rffc8c8d r3073c04 63 63 #endif 64 64 65 static struct libtrace_format_t *wag_ptr = 0; 66 65 67 #define CONNINFO libtrace->format_data->conn_info 66 68 #define INPUT libtrace->format_data->input 69 #define OUTPUT libtrace->format_data->output 70 #define OPTIONS libtrace->format_data->options 71 67 72 struct libtrace_format_data_t { 68 73 union { … … 83 88 #endif 84 89 } input; 90 }; 91 92 struct libtrace_format_data_out_t { 93 union { 94 char *path; 95 } conn_info; 96 union { 97 struct { 98 int level; 99 } zlib; 100 } options; 101 union { 102 int fd; 103 #if HAVE_ZLIB 104 gzFile *file; 105 #else 106 FILE *file; 107 #endif 108 } output; 85 109 }; 86 110 … … 150 174 } 151 175 176 static int wag_init_output(struct libtrace_out_t *libtrace) { 177 char *filemode = 0; 178 libtrace->format_data = (struct libtrace_format_data_out_t *) 179 calloc(1,sizeof(struct libtrace_format_data_out_t)); 180 181 OPTIONS.zlib.level = 0; 182 asprintf(&filemode,"wb%d",OPTIONS.zlib.level); 183 if (!strncmp(libtrace->uridata,"-",1)) { 184 // STDOUT 185 #if HAVE_ZLIB 186 OUTPUT.file = gzdopen(dup(1), filemode); 187 #else 188 OUTPUT.file = stdout; 189 #endif 190 } else { 191 // TRACE 192 #if HAVE_ZLIB 193 OUTPUT.file = gzdopen(open( 194 libtrace->uridata, 195 O_CREAT | O_LARGEFILE | O_WRONLY, 196 S_IRUSR | S_IWUSR), filemode); 197 #else 198 OUTPUT.file = fdopen(open( 199 O_CREAT | O_LARGEFILE | O_WRONLY, 200 S_IRUSR | S_IWUSR), "w"); 201 #endif 202 } 203 204 return 1; 205 } 206 207 static int wag_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 208 #if HAVE_ZLIB 209 int opt; 210 int level = OPTIONS.zlib.level; 211 optind = 1; 212 while ((opt = getopt(argc, argv, "z:")) != EOF) { 213 switch (opt) { 214 case 'z': 215 level = atoi(optarg); 216 break; 217 default: 218 printf("Bad argument to wag: %s\n", opt); 219 return -1; 220 } 221 } 222 if (level != OPTIONS.zlib.level) { 223 if (level > 9 || level < 0) { 224 // retarded level choice 225 printf("Compression level must be between 0 and 9 inclusive - you selected %i \n", level); 226 } else { 227 OPTIONS.zlib.level = level; 228 return gzsetparams(OUTPUT.file, level, Z_DEFAULT_STRATEGY); 229 } 230 } 231 #endif 232 return 0; 233 } 234 152 235 static int wag_fin_input(struct libtrace_t *libtrace) { 153 236 #if HAVE_ZLIB … … 155 238 #else 156 239 fclose(INPUT.file); 240 #endif 241 } 242 243 static int wag_fin_output(struct libtrace_out_t *libtrace) { 244 #if HAVE_ZLIB 245 gzclose(OUTPUT.file); 246 #else 247 fclose(OUTPUT.file); 157 248 #endif 158 249 } … … 259 350 return numbytes; 260 351 } while(1); 352 } 353 354 static int wag_write_packet(struct libtrace_out_t *libtrace, struct libtrace_packet_t *packet) { 355 int numbytes =0 ; 356 if (packet->trace->format != wag_ptr) { 357 fprintf(stderr,"Cannot convert from wag to %s format yet\n", 358 packet->trace->format->name); 359 return -1; 360 } 361 #if HAVE_ZLIB 362 if ((numbytes = gzwrite(OUTPUT.file, packet->buffer, packet->size)) == 0) { 363 perror("gzwrite"); 364 return -1; 365 } 366 #else 367 if ((numbytes = write(OUTPUT.file, packet->buffer, packet->size)) == 0) { 368 perror("write"); 369 return -1; 370 } 371 #endif 372 return numbytes; 261 373 } 262 374 … … 333 445 "$Id$", 334 446 wag_init_input, /* init_input */ 335 NULL,/* init_output */336 NULL,/* config_output */447 wag_init_output, /* init_output */ 448 wag_config_output, /* config_output */ 337 449 wag_fin_input, /* fin_input */ 338 NULL,/* fin_output */450 wag_fin_output, /* fin_output */ 339 451 wag_read_packet, /* read_packet */ 340 NULL,/* write_packet */452 wag_write_packet, /* write_packet */ 341 453 wag_get_link, /* get_link */ 342 454 wag_get_link_type, /* get_link_type */ … … 355 467 356 468 void __attribute__((constructor)) wag_constructor() { 357 register_format(&wag); 358 } 469 wag_ptr = &wag; 470 register_format(wag_ptr); 471 }
Note: See TracChangeset
for help on using the changeset viewer.