Changeset 0a6638f
- Timestamp:
- 02/20/06 18:36:13 (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:
- 5b91b48
- Parents:
- 8ee7caa
- Location:
- lib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
r65a5900 r0a6638f 281 281 } 282 282 283 static int erf_open_output(struct libtrace_out_t *libtrace) {284 char *filemode;285 int fd;286 287 #if HAVE_ZLIB288 asprintf(&filemode,"wb%d",OPTIONS.erf.level);289 #else290 asprintf(&filemode,"w");291 #endif292 293 if (!strncmp(libtrace->uridata,"-",1)) {294 /* STDOUT */295 OUTPUT.file = LIBTRACE_FDOPEN(fileno(stdout),filemode);296 }297 else {298 /* TRACE */299 fd = open(libtrace->uridata,300 OPTIONS.erf.fileflag,301 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);302 if (fd <= 0) {303 trace_set_err(errno,"OPEN(%s,\"w\")",304 libtrace->uridata);305 return 0;306 }307 OUTPUT.file = LIBTRACE_FDOPEN(fd,filemode);308 309 }310 free(filemode);311 return 1;312 }313 314 283 static int erf_config_output(struct libtrace_out_t *libtrace, trace_option_t option, void *value) { 315 284 … … 428 397 void *buffer2 = packet->buffer; 429 398 int rlen; 430 if (packet->buf_control == EXTERNAL) { 431 packet->buf_control = PACKET; 432 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 433 } 434 packet->header = packet->buffer; 435 436 if (packet->buffer) { 399 400 if (!packet->buffer) { 437 401 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 438 402 packet->buf_control = PACKET; 439 403 } 440 404 405 packet->header = packet->buffer; 441 406 442 407 if ((numbytes=LIBTRACE_READ(INPUT.file, … … 455 420 size = rlen - dag_record_size; 456 421 assert(size < LIBTRACE_PACKET_BUFSIZE); 422 457 423 458 424 /* Unknown/corrupt */ … … 589 555 } 590 556 591 if (buffer) { 592 if ((numbytes=LIBTRACE_WRITE(OUTPUT.file, buffer, size)) == 0) { 593 trace_set_err(errno,"write(%s)",libtrace->uridata); 594 return -1; 595 } 596 597 return numbytes + pad + dag_record_size; 598 } 599 return numbytes; 557 if ((numbytes=LIBTRACE_WRITE(OUTPUT.file, buffer, size)) == 0) { 558 trace_set_err(errno,"write(%s)",libtrace->uridata); 559 return -1; 560 } 561 562 return numbytes + pad + dag_record_size; 563 } 564 565 static int erf_start_output(libtrace_out_t *libtrace) 566 { 567 OUTPUT.file = trace_open_file_out(libtrace, 568 OPTIONS.erf.level, 569 OPTIONS.erf.fileflag); 570 if (!OUTPUT.file) { 571 printf("%s\n",trace_err.problem); 572 return -1; 573 } 574 return 0; 600 575 } 601 576 602 static int erf_write_packet(struct libtrace_out_t *libtrace, const struct libtrace_packet_t *packet) { 577 static int erf_write_packet(libtrace_out_t *libtrace, 578 const libtrace_packet_t *packet) 579 { 603 580 int numbytes = 0; 604 581 dag_record_t erfhdr; … … 607 584 void *payload = packet->payload; 608 585 609 /* Because of configuration, we don't actually open the output file 610 until we get the first packet. Not ideal, but it'll do for now */ 611 if (!OUTPUT.file) { 612 if (erf_open_output(libtrace) <= 0) { 613 trace_set_err(errno,"open(%s)",libtrace->uridata); 614 return -1; 615 } 616 } 586 assert(OUTPUT.file); 617 587 618 588 pad = erf_get_padding(packet); … … 633 603 pad, 634 604 payload, 635 packet->size -636 (dag_record_size + pad));605 trace_get_capture_length(packet) 606 ); 637 607 } else { 638 608 /* convert format - build up a new erf header */ … … 810 780 erf_init_output, /* init_output */ 811 781 erf_config_output, /* config_output */ 812 NULL,/* start_output */782 erf_start_output, /* start_output */ 813 783 erf_fin_input, /* fin_input */ 814 784 erf_fin_output, /* fin_output */ -
lib/format_helper.c
r3d4d52d r0a6638f 46 46 47 47 #include <sys/ioctl.h> 48 #include <assert.h> 48 49 49 50 struct libtrace_eventobj_t trace_event_device(struct libtrace_t *trace, struct libtrace_packet_t *packet) { … … 165 166 return ret; 166 167 } 168 169 LIBTRACE_FILE trace_open_file_out(libtrace_out_t *trace,int level, int fileflag) 170 { 171 int fd; 172 LIBTRACE_FILE ret; 173 char filemode[4]; /* wb9\0 */ 174 assert(level<10); 175 assert(level>=0); 176 #if HAVE_ZLIB 177 sprintf(filemode,"wb%d",level); 178 #else 179 sprintf(filemode,"w"); 180 #endif 181 182 if (strcmp(trace->uridata,"-")==0) { 183 ret=LIBTRACE_FDOPEN(fileno(stdout),filemode); 184 return ret; 185 } 186 187 /* We open the file with open(2), so we can provide O_LARGEFILE 188 * as zlib doesn't always do it itself 189 */ 190 fd=open(trace->uridata,fileflag,0666); 191 if (fd==-1) { 192 trace_set_err(errno,"Unable to open %s",trace->uridata); 193 return 0; 194 } 195 ret=LIBTRACE_FDOPEN(fd,filemode); 196 if (ret==NULL) { 197 printf("%s\n",filemode); 198 trace_set_err(TRACE_ERR_INIT_FAILED,"gz out of memory"); 199 } 200 return ret; 201 } 202 203 204 -
lib/format_helper.h
r3d4d52d r0a6638f 39 39 40 40 LIBTRACE_FILE trace_open_file(libtrace_t *libtrace); 41 LIBTRACE_FILE trace_open_file_out(libtrace_out_t *libtrace, 42 int level, 43 int filemode); 41 44 #endif /* FORMAT_HELPER_H */ -
lib/libtrace.h
r3d4d52d r0a6638f 86 86 typedef struct libtrace_filter_t libtrace_filter_t; 87 87 88 typedef enum {PACKET, EXTERNAL } buf_control_t; 88 /* the letters p and e are magic numbers used to detect if the packet 89 * wasn't created properly 90 */ 91 typedef enum {PACKET='p', EXTERNAL='e' } buf_control_t; 89 92 /** Structure holding information about a packet */ 90 93 #define LIBTRACE_PACKET_BUFSIZE 65536 -
lib/libtrace_int.h
rdf338b3 r0a6638f 116 116 char *uridata; 117 117 struct tracefifo_t *fifo; 118 bool started; 118 119 }; 119 120 -
lib/trace.c
rdf338b3 r0a6638f 331 331 */ 332 332 333 structlibtrace_out_t *trace_create_output(const char *uri) {333 libtrace_out_t *trace_create_output(const char *uri) { 334 334 struct libtrace_out_t *libtrace = malloc(sizeof(struct libtrace_out_t)); 335 335 … … 382 382 assert( libtrace->fifo); 383 383 free(scan); 384 libtrace->started=false; 384 385 return libtrace; 385 386 } … … 403 404 404 405 libtrace->started=true; 406 return 0; 407 } 408 409 int trace_start_output(libtrace_out_t *libtrace) 410 { 411 assert(libtrace); 412 if (libtrace->format->start_output) { 413 int ret=libtrace->format->start_output(libtrace); 414 if (ret < 0) { 415 return ret; 416 } 417 } 418 419 libtrace->started=false; 405 420 return 0; 406 421 } … … 495 510 libtrace_packet_t *trace_create_packet() { 496 511 libtrace_packet_t *packet = calloc(1,sizeof(libtrace_packet_t)); 497 /* This used to malloc a packet! Why do we need to malloc a packet 498 * if we're doing zero copy? 499 */ 512 packet->buf_control=PACKET; 500 513 return packet; 501 514 } … … 525 538 assert(libtrace->started && "BUG: You must call libtrace_start() before trace_read_packet()\n"); 526 539 assert(packet); 540 assert((packet->buf_control==PACKET || packet->buf_control==EXTERNAL)&& 541 "BUG: You must allocate a packet using packet_create()"); 527 542 528 543 /* Store the trace we are reading from into the packet opaque … … 1555 1570 * @param errcode either an Econstant from libc, or a LIBTRACE_ERROR 1556 1571 * @param msg a plaintext error message 1572 * @internal 1557 1573 */ 1558 1574 void trace_set_err(int errcode,const char *msg,...)
Note: See TracChangeset
for help on using the changeset viewer.