Changeset fe76c55
- Timestamp:
- 02/21/06 16:06:17 (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:
- c1db742
- Parents:
- 9ff68ff
- Location:
- lib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
r6dbc47a rfe76c55 275 275 OUTPUT.file = 0; 276 276 277 return 1;277 return 0; 278 278 } 279 279 … … 547 547 } 548 548 549 static int erf_dump_packet( structlibtrace_out_t *libtrace,549 static int erf_dump_packet(libtrace_out_t *libtrace, 550 550 dag_record_t *erfptr, int pad, void *buffer, size_t size) { 551 551 int numbytes = 0; 552 assert(size>=0 && size<=65536); 553 /* FIXME: Shouldn't this return != dag_record_size+pad on error? */ 552 554 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, erfptr, dag_record_size + pad)) == 0) { 553 555 trace_set_err(errno,"write(%s)",libtrace->uridata); … … 569 571 OPTIONS.erf.fileflag); 570 572 if (!OUTPUT.file) { 571 printf("%s\n",trace_err.problem);572 573 return -1; 573 574 } … … 579 580 { 580 581 int numbytes = 0; 581 dag_record_t erfhdr;582 582 int pad = 0; 583 583 dag_record_t *dag_hdr = (dag_record_t *)packet->header; … … 606 606 ); 607 607 } else { 608 dag_record_t erfhdr; 608 609 /* convert format - build up a new erf header */ 609 610 /* Timestamp */ … … 611 612 erfhdr.type = libtrace_to_erf_type(trace_get_link_type(packet)); 612 613 /* Flags. Can't do this */ 613 memset(&erfhdr.flags,1, 1);614 memset(&erfhdr.flags,1,sizeof(erfhdr.flags)); 614 615 /* Packet length (rlen includes format overhead) */ 615 erfhdr.rlen = trace_get_capture_length(packet) + erf_get_framing_length(packet); 616 erfhdr.rlen = trace_get_capture_length(packet) 617 + erf_get_framing_length(packet); 616 618 /* loss counter. Can't do this */ 617 619 erfhdr.lctr = 0; 618 620 /* Wire length */ 619 621 erfhdr.wlen = trace_get_wire_length(packet); 620 622 621 623 /* Write it out */ 622 624 numbytes = erf_dump_packet(libtrace, -
lib/format_helper.c
r0a6638f rfe76c55 144 144 #endif 145 145 146 /* open a file or stdin using gzip compression if necessary (and supported) 147 * @internal 148 */ 146 149 LIBTRACE_FILE trace_open_file(libtrace_t *trace) 147 150 { … … 167 170 } 168 171 172 /* Create a file or write to stdout using compression if requested 173 * @internal 174 */ 169 175 LIBTRACE_FILE trace_open_file_out(libtrace_out_t *trace,int level, int fileflag) 170 176 { -
lib/format_pcap.c
r6dbc47a rfe76c55 167 167 OUTPUT.trace.pcap = NULL; 168 168 OUTPUT.trace.dump = NULL; 169 return 1;169 return 0; 170 170 } 171 171 … … 254 254 numbytes = pcaphdr->len; 255 255 256 packet->header = (void *)pcaphdr; 256 packet->buf_control = PACKET; 257 if (!packet->buffer) { 258 /* We only need struct pcap_pkthdr, but we have no way 259 * to say how much we malloc'd so that formats can determine 260 * if they need to malloc more, so at the moment we just 261 * malloc 64k 262 */ 263 packet->buffer=malloc(65536); 264 } 265 memcpy(packet->buffer,pcaphdr,sizeof(struct pcap_pkthdr)); 266 packet->header = packet->buffer; 257 267 packet->payload = (void *)pcappkt; 258 268 259 260 269 packet->size = numbytes + sizeof(struct pcap_pkthdr); 270 271 assert(pcaphdr->caplen>=0 && pcaphdr->caplen<=65536); 261 272 } 262 273 … … 388 399 struct pcap_pkthdr *pcapptr = 0; 389 400 pcapptr = (struct pcap_pkthdr *)packet->header; 401 assert(pcapptr->caplen>=0 && pcapptr->caplen<=65536); 390 402 return pcapptr->caplen; 391 403 } -
lib/format_wag.c
r6dbc47a rfe76c55 146 146 malloc(sizeof(struct libtrace_format_data_t)); 147 147 148 return 1; 149 } 150 151 static int wtf_start_input(libtrace_t *libtrace) 152 { 148 153 libtrace->format_data->input.file = trace_open_file(libtrace); 149 154 … … 155 160 156 161 static int wtf_init_output(struct libtrace_out_t *libtrace) { 157 char *filemode = 0;158 162 libtrace->format_data = (struct libtrace_format_data_out_t *) 159 163 calloc(1,sizeof(struct libtrace_format_data_out_t)); 160 164 161 OPTIONS.zlib.level = 0; 162 asprintf(&filemode,"wb%d",OPTIONS.zlib.level); 163 if (!strncmp(libtrace->uridata,"-",1)) { 164 /* STDOUT */ 165 OUTPUT.file = LIBTRACE_FDOPEN(dup(1), filemode); 166 } else { 167 int fd; 168 /* TRACE */ 169 fd=open(libtrace->uridata,OPTIONS.zlib.filemode, 170 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); 171 if (fd==-1) { 172 trace_set_err(errno,"open(%s)",libtrace->uridata); 173 return 0; 174 } 175 OUTPUT.file = LIBTRACE_FDOPEN(fd, filemode); 176 } 177 178 return 1; 165 return 0; 166 } 167 168 static int wtf_start_output(libtrace_out_t *libtrace) { 169 OUTPUT.file = trace_open_file_out(libtrace, 170 OPTIONS.zlib.level, 171 OPTIONS.zlib.filemode); 172 if (!OUTPUT.file) { 173 return -1; 174 } 175 return 0; 179 176 } 180 177 … … 248 245 } 249 246 247 250 248 framesize = ntohs(((struct frame_t *)buffer)->size); 251 249 magic = ntohs(((struct frame_t *)buffer)->magic); … … 282 280 int numbytes; 283 281 284 if (packet->buf_control == EXTERNAL ) {282 if (packet->buf_control == EXTERNAL || !packet->buffer) { 285 283 packet->buf_control = PACKET; 286 284 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 287 285 } 288 286 289 287 … … 304 302 static int wtf_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 305 303 int numbytes; 306 void *buffer = packet->buffer;307 void *buffer2 = packet->buffer;304 void *buffer; 305 void *buffer2; 308 306 int framesize; 309 307 int size; 310 308 311 if (packet->buf_control == EXTERNAL ) {309 if (packet->buf_control == EXTERNAL || !packet->buffer) { 312 310 packet->buf_control = PACKET; 313 311 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 314 312 } 315 313 314 buffer2 = buffer = packet->buffer; 316 315 317 316 if ((numbytes = LIBTRACE_READ(INPUT.file, buffer, sizeof(struct frame_t))) == -1) { 318 trace_set_err(errno,"read(%s )",packet->trace->uridata);317 trace_set_err(errno,"read(%s,frame_t)",packet->trace->uridata); 319 318 return -1; 320 319 } … … 322 321 if (numbytes == 0) { 323 322 return 0; 323 } 324 325 if (htons(((struct frame_t *)buffer)->magic) != 0xdaa1) { 326 trace_set_err(TRACE_ERR_BAD_PACKET,"Insufficient magic"); 327 return -1; 324 328 } 325 329 … … 331 335 332 336 if ((numbytes=LIBTRACE_READ(INPUT.file, buffer2, size)) != size) { 333 trace_set_err(errno,"read(%s )",packet->trace->uridata);337 trace_set_err(errno,"read(%s,buffer)",packet->trace->uridata); 334 338 return -1; 335 339 } … … 351 355 } 352 356 353 /* We could just read from packet->buffer, but I feel it is more technically correct354 * t o read from the header and payload pointers357 /* We could just read from packet->buffer, but I feel it is more 358 * technically correct to read from the header and payload pointers 355 359 */ 356 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, packet->header, trace_get_framing_length(packet))) == -1) { 360 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, packet->header, 361 trace_get_framing_length(packet))) == -1) { 357 362 trace_set_err(errno,"write(%s)",packet->trace->uridata); 358 363 return -1; 359 364 } 360 365 if ((numbytes = LIBTRACE_WRITE(OUTPUT.file, packet->payload, 361 packet->size - trace_get_framing_length(packet))) == 0) {366 packet->size - trace_get_framing_length(packet))) == -1) { 362 367 trace_set_err(errno,"write(%s)",packet->trace->uridata); 363 368 return -1; … … 472 477 wtf_init_input, /* init_input */ 473 478 NULL, /* config input */ 474 NULL,/* start input */479 wtf_start_input, /* start input */ 475 480 NULL, /* pause_input */ 476 481 wtf_init_output, /* init_output */ 477 482 wtf_config_output, /* config_output */ 478 NULL,/* start output */483 wtf_start_output, /* start output */ 479 484 wtf_fin_input, /* fin_input */ 480 485 wtf_fin_output, /* fin_output */ -
lib/trace.c
r6dbc47a rfe76c55 370 370 371 371 if (libtrace->format->init_output) { 372 if(!libtrace->format->init_output( libtrace)) { 373 return 0; 372 /* 0 on success, -1 on failure */ 373 switch(libtrace->format->init_output(libtrace)) { 374 case -1: /* failure */ 375 free(libtrace); 376 return 0; 377 case 0: /* success */ 378 break; 379 default: 380 assert(!"init_output() should return -1 for failure, or 0 for success"); 374 381 } 375 382 } else { 376 383 trace_set_err(TRACE_ERR_NO_INIT_OUT, 377 384 "Format does not support writing (%s)",scan); 385 free(libtrace); 378 386 return 0; 379 387 }
Note: See TracChangeset
for help on using the changeset viewer.