Changeset 5baec88
- Timestamp:
- 02/07/06 11:54:30 (15 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:
- bb09ce4
- Parents:
- 9c87732
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
r3b8a5ef r5baec88 127 127 } conn_info; 128 128 129 130 129 131 union { 130 132 struct { 131 133 int level; 134 int append; 132 135 } erf; 133 136 … … 321 324 322 325 static int erf_init_output(struct libtrace_out_t *libtrace) { 323 char *filemode = 0;324 326 int fd; 325 327 libtrace->format_data = (struct libtrace_format_data_out_t *) … … 327 329 328 330 OPTIONS.erf.level = 0; 331 OPTIONS.erf.append = 0; 332 OUTPUT.file = 0; 333 334 return 1; 335 } 336 337 static int erf_open_output(struct libtrace_out_t *libtrace) { 338 char *filemode; 339 int trunc_flag = O_TRUNC; 340 int fd; 341 329 342 #if HAVE_ZLIB 330 343 asprintf(&filemode,"wb%d",OPTIONS.erf.level); 331 344 #else 332 asprintf(&filemode,"w"); 333 #endif 334 335 if (!strncmp(libtrace->uridata,"-",1)) { 345 asprintf(&filemode,"w"); 346 #endif 347 348 if (OPTIONS.erf.append) { 349 trunc_flag = O_APPEND; 350 } 351 352 if (!strncmp(libtrace->uridata,"-",1)) { 336 353 // STDOUT 337 338 339 340 341 fd = open(libtrace->uridata, O_CREAT | O_LARGEFILE | O_WRONLY, S_IRUSR342 | S_IWUSR | S_IRGRP | S_IWGRP);343 344 345 346 347 348 349 free(filemode); 354 OUTPUT.file = LIBTRACE_FDOPEN(fileno(stdout),filemode); 355 } 356 else { 357 // TRACE 358 fd = open(libtrace->uridata, O_CREAT | O_LARGEFILE | O_WRONLY | trunc_flag, 359 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); 360 if (fd <= 0) { 361 return 0; 362 } 363 OUTPUT.file = LIBTRACE_FDOPEN(fd,filemode); 364 365 } 366 free(filemode); 350 367 return 1; 351 368 } 352 369 353 370 static int erf_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 354 #if HAVE_ZLIB355 371 int opt; 356 372 int level = OPTIONS.erf.level; … … 358 374 359 375 360 while ((opt = getopt(argc, argv, "z: ")) != EOF) {376 while ((opt = getopt(argc, argv, "z:a")) != EOF) { 361 377 switch (opt) { 362 378 case 'z': 363 379 level = atoi(optarg); 380 break; 381 case 'a': 382 OPTIONS.erf.append = 1; 364 383 break; 365 384 default: … … 369 388 } 370 389 } 371 if (level != OPTIONS.erf.level) { 372 if (level > 9 || level < 0) { 373 // retarded level choice 374 printf("Compression level must be between 0 and 9 inclusive - you selected %i \n", level); 375 376 } else { 377 OPTIONS.erf.level = level; 378 return gzsetparams(OUTPUT.file, level, Z_DEFAULT_STRATEGY); 379 } 380 } 381 #endif 390 382 391 return 0; 383 392 … … 409 418 } 410 419 411 412 413 420 #if HAVE_DAG 414 static int dag_read(struct libtrace_t *libtrace, void *buffer, size_t len ) {421 static int dag_read(struct libtrace_t *libtrace, void *buffer, size_t len, int block_flag) { 415 422 int numbytes; 416 423 static short lctr = 0; … … 425 432 INPUT.fd, 426 433 &(DAG.bottom), 427 0);434 block_flag); 428 435 DAG.diff = DAG.top - 429 436 DAG.bottom; … … 452 459 453 460 if (DAG.diff == 0) { 454 if ((numbytes = dag_read(libtrace,buf,RP_BUFSIZE )) <= 0)461 if ((numbytes = dag_read(libtrace,buf,RP_BUFSIZE, 0)) <= 0) 455 462 return numbytes; 456 463 } … … 484 491 return (size); 485 492 } 493 494 495 // Lots of repeated code in here - could easily be tidied up 496 static int dag_read_packet_nb(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 497 int numbytes; 498 int size; 499 char buf[RP_BUFSIZE]; 500 dag_record_t *erfptr; 501 void *buffer = packet->buffer; 502 void *buffer2 = buffer; 503 int rlen; 504 505 if (packet->buf_control == PACKET) { 506 packet->buf_control = EXTERNAL; 507 free(packet->buffer); 508 packet->buffer = 0; 509 } 510 511 if (DAG.diff == 0) { 512 if ((numbytes = dag_read(libtrace,buf,RP_BUFSIZE, DAGF_NONBLOCK)) <= 0) 513 return numbytes; 514 } 515 516 //DAG always gives us whole packets 517 erfptr = (dag_record_t *) ((void *)DAG.buf + 518 (DAG.bottom + DAG.offset)); 519 size = ntohs(erfptr->rlen); 520 521 if ( size > LIBTRACE_PACKET_BUFSIZE) { 522 assert( size < LIBTRACE_PACKET_BUFSIZE); 523 } 524 525 packet->buffer = erfptr; 526 packet->header = erfptr; 527 if (((dag_record_t *)buffer)->flags.rxerror == 1) { 528 packet->payload = NULL; 529 } else { 530 packet->payload = packet->buffer + erf_get_framing_length(packet); 531 } 532 533 534 packet->status.type = RT_DATA; 535 packet->status.message = 0; 536 packet->size = size; 537 DAG.offset += size; 538 DAG.diff -= size; 539 540 assert(DAG.diff >= 0); 541 542 return (size); 543 } 544 486 545 #endif 487 546 … … 702 761 dag_record_t *dag_hdr = (dag_record_t *)packet->header; 703 762 void *payload = packet->payload; 763 764 /* Because of configuration, we don't actually open the output file 765 until we get the first packet. Not ideal, but it'll do for now */ 766 if (!OUTPUT.file) { 767 if (erf_open_output(libtrace) <= 0) { 768 perror("erf_open_output"); 769 return -1; 770 } 771 } 704 772 705 773 pad = erf_get_padding(packet);
Note: See TracChangeset
for help on using the changeset viewer.