- Timestamp:
- 02/10/06 18:02: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:
- 6eb91ff
- Parents:
- 7f32bb5
- Location:
- lib
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile.am
r37195b4 r7068467 6 6 format_erf.c format_pcap.c format_wag.c format_legacy.c \ 7 7 format_helper.c format_helper.h \ 8 parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h 8 parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h \ 9 linktypes.c 9 10 if DAG2_4 10 11 nodist_libtrace_la_SOURCES = dagopts.c dagapi.c -
lib/common.h
rf66a4933 r7068467 25 25 #endif 26 26 27 #endif / / COMMON_H27 #endif /* COMMON_H */ -
lib/dagformat.h
rd91dd4e r7068467 38 38 39 39 typedef struct flags { 40 u int8_t iface:2;41 u int8_t vlen:1;42 u int8_t trunc:1;43 u int8_t rxerror:1;44 u int8_t dserror:1;45 u int8_t pad:2;40 unsigned int iface:2; 41 unsigned int vlen:1; 42 unsigned int trunc:1; 43 unsigned int rxerror:1; 44 unsigned int dserror:1; 45 unsigned int pad:2; 46 46 } __attribute__((packed)) flags_t; 47 47 … … 87 87 #define dag_record_size 16 88 88 89 #endif / / _DAGFORMAT_H_89 #endif /* _DAGFORMAT_H_ */ -
lib/fifo.c
r9c6aa95 r7068467 98 98 { 99 99 assert(fifo); 100 //free(tracefifo_stat_buffer);101 100 free(fifo->base); 102 101 free(fifo); … … 116 115 117 116 void tracefifo_flush(struct tracefifo_t *fifo __attribute__((unused))) { 118 / / do nothing117 /* do nothing */ 119 118 return; 120 119 } … … 220 219 size); 221 220 increment_pointer(fifo,which,size); 222 buffer +=size;221 buffer = (char*)buffer+size; 223 222 lenleft -= size; 224 223 } -
lib/fifo.h
rb5cd711 r7068467 32 32 #ifndef _FIFO_H_ 33 33 #define _FIFO_H_ 34 #include <inttypes.h> 34 35 35 36 struct tracefifo_t; 36 37 37 38 typedef struct tracefifo_state { 38 long long int in;39 long long int out;40 long long int ack;41 long long int length;42 long long int used;39 uint64_t in; 40 uint64_t out; 41 uint64_t ack; 42 uint64_t length; 43 uint64_t used; 43 44 } tracefifo_state_t; 44 45 … … 70 71 71 72 72 #endif / / _FIFO_H_73 #endif /* _FIFO_H_ */ -
lib/format_erf.c
r37195b4 r7068467 30 30 #define _GNU_SOURCE 31 31 32 #define RT_MSG 2 33 #define RT_DATA 1 34 32 35 #include "config.h" 33 36 #include "common.h" … … 98 101 gzFile *file; 99 102 #else 100 //FILE *file;101 103 int file; 102 104 #endif … … 129 131 struct { 130 132 int level; 131 int append;133 int fileflag; 132 134 } erf; 133 135 … … 140 142 gzFile *file; 141 143 #else 142 //FILE *file;143 144 int file; 144 145 #endif 145 146 } output; 146 147 }; 148 149 /** Structure holding status information for a packet */ 150 typedef struct libtrace_packet_status { 151 uint8_t type; 152 uint8_t reserved; 153 uint16_t message; 154 } libtrace_packet_status_t; 155 147 156 148 157 #ifdef HAVE_DAG … … 158 167 } 159 168 if (S_ISCHR(buf.st_mode)) { 160 / / DEVICE169 /* DEVICE */ 161 170 libtrace->sourcetype = DEVICE; 162 171 if((INPUT.fd = dag_open(CONNINFO.path)) < 0) { … … 209 218 CONNINFO.path = libtrace->uridata; 210 219 if (!strncmp(CONNINFO.path,"-",1)) { 211 / / STDIN220 /* STDIN */ 212 221 libtrace->sourcetype = STDIN; 213 222 INPUT.file = LIBTRACE_FDOPEN(fileno(stdin), "r"); … … 242 251 libtrace->sourcetype = TRACE; 243 252 244 // we use an FDOPEN call to reopen an FD 245 // returned from open(), so that we can set 246 // O_LARGEFILE. This gets around gzopen not 247 // letting you do this... 253 /* we use an FDOPEN call to reopen an FD 254 * returned from open(), so that we can set 255 * O_LARGEFILE. This gets around gzopen not 256 * letting you do this... 257 */ 248 258 INPUT.file = LIBTRACE_FDOPEN(open( 249 259 CONNINFO.path, … … 307 317 308 318 static int erf_init_output(struct libtrace_out_t *libtrace) { 309 int fd;310 319 libtrace->format_data = (struct libtrace_format_data_out_t *) 311 320 calloc(1,sizeof(struct libtrace_format_data_out_t)); 312 321 313 322 OPTIONS.erf.level = 0; 314 OPTIONS.erf. append = 0;323 OPTIONS.erf.fileflag = O_CREAT | O_LARGEFILE | O_WRONLY; 315 324 OUTPUT.file = 0; 316 325 … … 320 329 static int erf_open_output(struct libtrace_out_t *libtrace) { 321 330 char *filemode; 322 int trunc_flag = O_TRUNC;323 331 int fd; 324 332 … … 329 337 #endif 330 338 331 if (OPTIONS.erf.append) {332 trunc_flag = O_APPEND;333 }334 335 339 if (!strncmp(libtrace->uridata,"-",1)) { 336 / / STDOUT340 /* STDOUT */ 337 341 OUTPUT.file = LIBTRACE_FDOPEN(fileno(stdout),filemode); 338 342 } 339 343 else { 340 // TRACE 341 fd = open(libtrace->uridata, O_CREAT | O_LARGEFILE | O_WRONLY | trunc_flag, 344 /* TRACE */ 345 fd = open(libtrace->uridata, 346 OPTIONS.erf.fileflag, 342 347 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); 343 348 if (fd <= 0) { … … 351 356 } 352 357 353 static int erf_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 354 int opt; 355 int level = OPTIONS.erf.level; 356 optind = 1; 357 358 359 while ((opt = getopt(argc, argv, "z:a")) != EOF) { 360 switch (opt) { 361 case 'z': 362 level = atoi(optarg); 363 break; 364 case 'a': 365 OPTIONS.erf.append = 1; 366 break; 367 default: 368 printf("Bad argument to erf: %s\n", optarg); 369 // maybe spit out some help here 370 return -1; 371 } 372 } 373 374 return 0; 375 358 static int erf_config_output(struct libtrace_out_t *libtrace, trace_option_t option, void *value) { 359 360 switch (option) { 361 case TRACE_OPTION_OUTPUT_COMPRESS: 362 OPTIONS.erf.level = *(int*)value; 363 return 0; 364 case TRACE_OPTION_OUTPUT_FILEFLAGS: 365 OPTIONS.erf.fileflag = *(int*)value; 366 return 0; 367 default: 368 /* Unknown option */ 369 return -1; 370 } 376 371 } 377 372 … … 443 438 return numbytes; 444 439 445 / /DAG always gives us whole packets440 /*DAG always gives us whole packets */ 446 441 erfptr = (dag_record_t *) ((void *)DAG.buf + 447 442 (DAG.bottom + DAG.offset)); … … 460 455 } 461 456 462 463 packet->status.type = RT_DATA;464 packet->status.message = 0;465 457 packet->size = size; 466 458 DAG.offset += size; … … 476 468 int numbytes; 477 469 int size; 478 void *buffer = packet->buffer; 479 void *buffer2 = buffer; 470 void *buffer2 = packet->buffer; 480 471 int rlen; 481 472 if (packet->buf_control == EXTERNAL) { … … 483 474 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 484 475 } 485 buffer = packet->buffer;486 476 packet->header = packet->buffer; 487 477 478 if (packet->buffer) { 479 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 480 packet->buf_control = PACKET; 481 } 482 488 483 489 484 if ((numbytes=LIBTRACE_READ(INPUT.file, 490 buffer,485 packet->buffer, 491 486 dag_record_size)) == -1) { 492 487 perror("libtrace_read"); … … 497 492 } 498 493 499 rlen = ntohs(((dag_record_t *) buffer)->rlen);500 buffer2 = buffer + dag_record_size;494 rlen = ntohs(((dag_record_t *)packet->buffer)->rlen); 495 buffer2 = (char*)packet->buffer + dag_record_size; 501 496 size = rlen - dag_record_size; 502 497 assert(size < LIBTRACE_PACKET_BUFSIZE); … … 509 504 */ 510 505 /* Unknown/corrupt */ 511 assert(((dag_record_t *) buffer)->type < 10);512 513 / / read in the rest of the packet506 assert(((dag_record_t *)packet->buffer)->type < 10); 507 508 /* read in the rest of the packet */ 514 509 if ((numbytes=LIBTRACE_READ(INPUT.file, 515 510 buffer2, … … 518 513 return -1; 519 514 } 520 packet->status.type = RT_DATA;521 packet->status.message = 0;522 515 packet->size = rlen; 523 if (((dag_record_t *) buffer)->flags.rxerror == 1) {516 if (((dag_record_t *)packet->buffer)->flags.rxerror == 1) { 524 517 packet->payload = NULL; 525 518 } else { 526 packet->payload = packet->buffer + erf_get_framing_length(packet);519 packet->payload = (char*)packet->buffer + erf_get_framing_length(packet); 527 520 } 528 521 return rlen; … … 543 536 MSG_NOSIGNAL)) == -1) { 544 537 if (errno == EINTR) { 545 //ignore EINTR in case 546 // a caller is using signals 538 /*ignore EINTR in case 539 *a caller is using signals 540 */ 547 541 continue; 548 542 } … … 575 569 576 570 do { 571 struct libtrace_packet_status status; 577 572 if (tracefifo_out_available(libtrace->fifo) == 0 || read_required) { 578 573 if ((numbytes = rtclient_read( … … 583 578 read_required = 0; 584 579 } 585 / / Read status byte580 /* Read status byte */ 586 581 if (tracefifo_out_read(libtrace->fifo, 587 & packet->status, sizeof(uint32_t)) == 0) {582 &status, sizeof(uint32_t)) == 0) { 588 583 read_required = 1; 589 584 continue; 590 585 } 591 586 tracefifo_out_update(libtrace->fifo,sizeof(uint32_t)); 592 / / Read in packet size587 /* Read in packet size */ 593 588 if (tracefifo_out_read(libtrace->fifo, 594 589 &packet->size, sizeof(uint32_t)) == 0) { … … 608 603 } 609 604 */ 610 if ( packet->status.type == RT_MSG) {611 / / Need to skip this packet as it is a message packet605 if (status.type == RT_MSG) { 606 /* Need to skip this packet as it is a message packet */ 612 607 tracefifo_out_update(libtrace->fifo, packet->size); 613 608 tracefifo_ack_update(libtrace->fifo, packet->size + … … 617 612 } 618 613 619 //size = ntohs(((dag_record_t *)buffer)->rlen); 620 621 // read in the full packet 614 /* read in the full packet */ 622 615 if ((numbytes = tracefifo_out_read(libtrace->fifo, 623 616 buffer, packet->size)) == 0) { … … 627 620 } 628 621 629 / / got in our whole packet, so...622 /* got in our whole packet, so... */ 630 623 tracefifo_out_update(libtrace->fifo,packet->size); 631 624 … … 634 627 sizeof(libtrace_packet_status_t)); 635 628 636 //packet->size = numbytes;637 629 if (((dag_record_t *)buffer)->flags.rxerror == 1) { 638 630 packet->payload = NULL; 639 631 } else { 640 packet->payload = packet->buffer + erf_get_framing_length(packet);632 packet->payload = (char*)packet->buffer + erf_get_framing_length(packet); 641 633 } 642 634 return numbytes; … … 698 690 (dag_record_size + pad)); 699 691 } else { 700 / / convert format - build up a new erf header701 / / Timestamp692 /* convert format - build up a new erf header */ 693 /* Timestamp */ 702 694 erfhdr.ts = trace_get_erf_timestamp(packet); 703 // Flags. Can't do this 695 erfhdr.type = libtrace_to_erf_type(trace_get_link_type(packet)); 696 /* Flags. Can't do this */ 704 697 memset(&erfhdr.flags,1,1); 705 / / Packet length (rlen includes format overhead)698 /* Packet length (rlen includes format overhead) */ 706 699 erfhdr.rlen = trace_get_capture_length(packet) + erf_get_framing_length(packet); 707 / / loss counter. Can't do this700 /* loss counter. Can't do this */ 708 701 erfhdr.lctr = 0; 709 / / Wire length702 /* Wire length */ 710 703 erfhdr.wlen = trace_get_wire_length(packet); 711 704 712 / / Write it out705 /* Write it out */ 713 706 numbytes = erf_dump_packet(libtrace, 714 707 &erfhdr, … … 720 713 } 721 714 722 static void *erf_get_link(const struct libtrace_packet_t *packet) {723 return (void *)packet->payload;724 }725 726 715 static libtrace_linktype_t erf_get_link_type(const struct libtrace_packet_t *packet) { 727 716 dag_record_t *erfptr = 0; 728 717 erfptr = (dag_record_t *)packet->header; 729 switch (erfptr->type) { 730 case TYPE_LEGACY: return TRACE_TYPE_LEGACY; 731 case TYPE_ETH: return TRACE_TYPE_ETH; 732 case TYPE_ATM: return TRACE_TYPE_ATM; 733 default: 734 fprintf(stderr,"Unknown erf type %02x\n",erfptr->type); 735 assert(0); 736 } 737 return erfptr->type; 718 return erf_type_to_libtrace(erfptr->type); 738 719 } 739 720 … … 773 754 assert(packet); 774 755 if((size + erf_get_framing_length(packet)) > packet->size) { 775 / / can't make a packet larger756 /* can't make a packet larger */ 776 757 return (packet->size - erf_get_framing_length(packet)); 777 758 } -
lib/format_helper.h
r8184acc r7068467 36 36 struct libtrace_eventobj_t trace_event_device(struct libtrace_t *trace, struct libtrace_packet_t *packet); 37 37 struct libtrace_eventobj_t trace_event_trace(struct libtrace_t *trace, struct libtrace_packet_t *packet); 38 #endif / / FORMAT_HELPER_H38 #endif /* FORMAT_HELPER_H */ -
lib/format_legacy.c
r37195b4 r7068467 193 193 return -1; 194 194 } 195 packet->status.type = RT_DATA;196 packet->status.message = 0;197 195 packet->size = 64; 198 196 -
lib/format_pcap.c
r37195b4 r7068467 152 152 } 153 153 } 154 //fprintf(stderr, "Unsupported scheme (%s) for format pcap\n",155 // CONNINFO.path);156 154 return 1; 157 155 … … 209 207 int numbytes = 0; 210 208 209 /* 211 210 // pcap provides us with the right bits, in it's own buffers. 212 211 // We hijack them. 212 */ 213 213 numbytes = pcaphdr->len; 214 214 … … 231 231 return pcapbytes; 232 232 } 233 packet->status.type = RT_DATA;234 packet->status.message = 0;235 233 return (packet->size - sizeof(struct pcap_pkthdr)); 236 234 } … … 251 249 pcap_dump((u_char*)OUTPUT.trace.dump,(struct pcap_pkthdr *)packet->header,packet->payload); 252 250 } else { 253 // Leave the manual copy as it is, as it gets around 254 // some OS's having different structures in pcap_pkt_hdr 251 /* Leave the manual copy as it is, as it gets around 252 * some OS's having different structures in pcap_pkt_hdr 253 */ 255 254 struct timeval ts = trace_get_timeval(packet); 256 255 pcap_pkt_hdr.ts.tv_sec = ts.tv_sec; … … 265 264 266 265 static int pcapint_write_packet(struct libtrace_out_t *libtrace __attribute__((unused)), const struct libtrace_packet_t *packet __attribute__((unused))) { 267 // void *link = trace_get_link(packet);268 266 269 267 return 0; 270 }271 272 static void *pcap_get_link(const struct libtrace_packet_t *packet) {273 return (void *) packet->payload;274 268 } 275 269 … … 382 376 assert(packet); 383 377 if ((size + sizeof(struct pcap_pkthdr)) > packet->size) { 384 / / can't make a packet larger378 /* can't make a packet larger */ 385 379 return (packet->size - sizeof(struct pcap_pkthdr)); 386 380 } … … 478 472 }; 479 473 480 //pcap_ptr = &pcap;481 //pcapint_ptr = &pcapint;482 483 474 void __attribute__((constructor)) pcap_constructor() { 484 475 register_format(&pcap); -
lib/format_wag.c
r37195b4 r7068467 99 99 gzFile *file; 100 100 #else 101 //FILE *file;102 101 int file; 103 102 #endif … … 119 118 gzFile *file; 120 119 #else 121 //FILE *file;122 120 int file; 123 121 #endif … … 127 125 static int wag_init_input(struct libtrace_t *libtrace) { 128 126 struct stat buf; 129 //struct sockaddr_un unix_sock;130 127 libtrace->format_data = (struct libtrace_format_data_t *) 131 128 calloc(1,sizeof(struct libtrace_format_data_t)); … … 151 148 152 149 static int wtf_init_input(struct libtrace_t *libtrace) { 153 struct stat buf;154 struct sockaddr_un unix_sock;155 150 156 151 libtrace->format_data = (struct libtrace_format_data_t *) … … 159 154 160 155 if (!strncmp(CONNINFO.path,"-",1)) { 161 / / STDIN156 /* STDIN */ 162 157 libtrace->sourcetype = STDIN; 163 158 INPUT.file = LIBTRACE_FDOPEN(fileno(stdin),"r"); 164 159 165 160 } else { 166 167 168 // Do we need this socket stuff at all?? 169 // If we do, put it into wag_init_input as it uses 170 // INPUT.fd 161 /* Do we need this socket stuff at all?? 162 * If we do, put it into wag_init_input as it uses 163 * INPUT.fd 164 */ 171 165 172 166 /* … … 197 191 } else { 198 192 */ 199 / / TRACE193 /* TRACE */ 200 194 libtrace->sourcetype = TRACE; 201 195 202 // we use an FDOPEN call to reopen an FD 203 // returned from open(), so that we can set 204 // O_LARGEFILE. This gets around gzopen not 205 // letting you do this... 196 /* we use an FDOPEN call to reopen an FD 197 * returned from open(), so that we can set 198 * O_LARGEFILE. This gets around gzopen not 199 * letting you do this... 200 */ 206 201 INPUT.file = LIBTRACE_FDOPEN(open( 207 202 CONNINFO.path, 208 203 O_LARGEFILE), "r"); 209 204 210 //}211 205 } 212 206 return 1; … … 222 216 asprintf(&filemode,"wb%d",OPTIONS.zlib.level); 223 217 if (!strncmp(libtrace->uridata,"-",1)) { 224 / / STDOUT218 /* STDOUT */ 225 219 OUTPUT.file = LIBTRACE_FDOPEN(dup(1), filemode); 226 220 } else { 227 / / TRACE221 /* TRACE */ 228 222 OUTPUT.file = LIBTRACE_FDOPEN(open( 229 223 libtrace->uridata, … … 235 229 } 236 230 237 static int wtf_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 231 static int wtf_config_output(struct libtrace_out_t *libtrace, 232 trace_option_output_t option, 233 void *value) { 234 switch(option) { 238 235 #if HAVE_ZLIB 239 int opt; 240 int level = OPTIONS.zlib.level; 241 optind = 1; 242 while ((opt = getopt(argc, argv, "z:")) != EOF) { 243 switch (opt) { 244 case 'z': 245 level = atoi(optarg); 246 break; 247 default: 248 printf("Bad argument to wag: %s\n", optarg); 249 return -1; 250 } 251 } 252 if (level != OPTIONS.zlib.level) { 253 if (level > 9 || level < 0) { 254 // retarded level choice 255 printf("Compression level must be between 0 and 9 inclusive - you selected %i \n", level); 256 } else { 257 OPTIONS.zlib.level = level; 258 return gzsetparams(OUTPUT.file, level, Z_DEFAULT_STRATEGY); 259 } 260 } 261 #endif 262 return 0; 236 case TRACE_OPTION_OUTPUT_COMPRESS: 237 OPTIONS.zlib.level = *(int*)value; 238 assert(OPTIONS.zlib.level>=0 239 && OPTIONS.zlib.level<=9); 240 break; 241 #else 242 case TRACE_OPTION_OUTPUT_COMPRESS: 243 /* E feature unavailable */ 244 return -1; 245 #endif 246 default: 247 /* E unknown feature */ 248 return -1; 249 } 263 250 } 264 251 … … 280 267 static int wag_read(struct libtrace_t *libtrace, void *buffer, size_t len) { 281 268 int numbytes; 282 int framesize;269 size_t framesize; 283 270 assert(libtrace); 284 271 … … 286 273 buffer = malloc(len); 287 274 288 / / read in wag_frame_hdr275 /* read in wag_frame_hdr */ 289 276 if ((numbytes = read(INPUT.fd, 290 277 buffer, … … 299 286 } 300 287 301 / / read in remainder of packet288 /* read in remainder of packet */ 302 289 if((numbytes = read(INPUT.fd, 303 buffer + sizeof(struct wag_frame_hdr),290 (char*)buffer + sizeof(struct wag_frame_hdr), 304 291 framesize - sizeof(struct wag_frame_hdr))) != 305 292 (framesize - sizeof(struct wag_frame_hdr))) { … … 316 303 int numbytes; 317 304 318 char buf[RP_BUFSIZE];319 305 if (packet->buf_control == EXTERNAL) { 320 306 packet->buf_control = PACKET; … … 331 317 332 318 333 // memcpy(packet->buffer, buf, numbytes);334 335 packet->status.type = RT_DATA;336 packet->status.message = 0;337 319 packet->size = numbytes; 338 320 packet->header = packet->buffer; 339 packet->payload = packet->buffer +trace_get_framing_length(packet);321 packet->payload=(char*)packet->buffer+trace_get_framing_length(packet); 340 322 return numbytes; 341 323 } … … 364 346 365 347 framesize = ntohs(((struct wag_frame_hdr *)buffer)->size); 366 buffer2 = buffer + sizeof(struct wag_frame_hdr);348 buffer2 = (char*)buffer + sizeof(struct wag_frame_hdr); 367 349 size = framesize - sizeof(struct wag_frame_hdr); 368 350 assert(size < LIBTRACE_PACKET_BUFSIZE); … … 374 356 } 375 357 376 packet->status.type = RT_DATA;377 packet->status.message = 0;378 358 packet->size = framesize; 379 359 packet->header = packet->buffer; 380 packet->payload = packet->buffer +trace_get_framing_length(packet);360 packet->payload=(char*)packet->buffer+trace_get_framing_length(packet); 381 361 return framesize; 382 362 … … 406 386 } 407 387 408 static void *wag_get_link(const struct libtrace_packet_t *packet) {409 /*410 struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer;411 void *payload = wagptr->data;412 return (void*)payload;413 */414 return (void *)packet->payload;415 }416 417 388 static libtrace_linktype_t wag_get_link_type(const struct libtrace_packet_t *packet __attribute__((unused))) { 418 389 return TRACE_TYPE_80211; … … 436 407 static int wag_get_capture_length(const struct libtrace_packet_t *packet) { 437 408 struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer; 438 //return (wagptr->hdr.size);439 409 return ntohs(wagptr->hdr.size); 440 410 } … … 442 412 static int wag_get_wire_length(const struct libtrace_packet_t *packet) { 443 413 struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer; 444 //return (wagptr->hdr.size);445 414 return ntohs(wagptr->hdr.size); 446 415 } -
lib/libtrace.h
r7f32bb5 r7068467 71 71 # define SIMPLE_FUNCTION __attribute__((pure)) 72 72 # define UNUSED __attribute__((unused)) 73 # define PACKED __attribute__((packed)) 73 74 #else 74 75 # define SIMPLE_FUNCTION 75 76 # define UNUSED 76 77 #endif 77 78 #define RT_DATA 179 #define RT_MSG 280 81 78 82 79 /** Opaque structure holding information about an output trace */ … … 89 86 typedef struct libtrace_filter_t libtrace_filter_t; 90 87 91 /** Structure holding status information for a packet */92 typedef struct libtrace_packet_status {93 uint8_t type;94 uint8_t reserved;95 uint16_t message;96 97 } libtrace_packet_status_t;98 99 88 typedef enum {PACKET, EXTERNAL } buf_control_t; 100 89 /** Structure holding information about a packet */ … … 106 95 void *buffer; 107 96 size_t size; 108 libtrace_packet_status_t status;109 97 buf_control_t buf_control; 110 } __attribute__ ((packed))libtrace_packet_t;98 } libtrace_packet_t; 111 99 112 100 … … 114 102 enum {E_NOERROR, E_BAD_FORMAT, E_NO_INIT, E_NO_INIT_OUT, E_URI_LONG, E_URI_NOCOLON, E_INIT_FAILED }; 115 103 104 /** @name Packet structures 105 * These convenience structures are here as they are portable ways of dealing 106 * with various protocols. 107 * @{ 108 */ 109 116 110 /** Structure for dealing with IP packets */ 117 typedef struct libtrace_ip111 typedef PACKED struct libtrace_ip 118 112 { 119 113 #if BYTE_ORDER == LITTLE_ENDIAN … … 129 123 u_short ip_len; /**< total length */ 130 124 u_short ip_id; /**< identification */ 131 u_short ip_off; /**< fragment offset field */ 132 #define IP_RF 0x8000 /**< reserved fragment flag */ 133 #define IP_DF 0x4000 /**< dont fragment flag */ 134 #define IP_MF 0x2000 /**< more fragments flag */ 135 #define IP_OFFMASK 0x1fff /**< mask for fragmenting bits */ 125 #if BYTE_ORDER == LITTLE_ENDIAN 126 unsigned int ip_off:12; /**< fragment offset */ 127 unsigned int ip_mf:1; /**< more fragments flag */ 128 unsigned int ip_df:1; /**< dont fragment flag */ 129 unsigned int ip_rf:1; /**< reserved fragment flag */ 130 #elif BYTE_ORDER == BIG_ENDIAN 131 unsigned int ip_rf:1; 132 unsigned int ip_df:1; 133 unsigned int ip_mf:1; 134 unsigned int ip_off:12; 135 #else 136 # error "Adjust your <bits/endian.h> defines" 137 #endif 136 138 u_int8_t ip_ttl; /**< time to live */ 137 139 u_int8_t ip_p; /**< protocol */ … … 139 141 struct in_addr ip_src; /**< source address */ 140 142 struct in_addr ip_dst; /**< dest address */ 141 } __attribute__ ((packed))libtrace_ip_t143 } libtrace_ip_t 142 144 ; 143 145 … … 150 152 u_int32_t ack_seq; /**< Acknowledgement Number */ 151 153 # if BYTE_ORDER == LITTLE_ENDIAN 152 u _int16_t res1:4;/**< Reserved bits */153 u _int16_t doff:4;154 u _int16_t fin:1; /**< FIN */155 u _int16_t syn:1; /**< SYN flag */156 u _int16_t rst:1; /**< RST flag */157 u _int16_t psh:1; /**< PuSH flag */158 u _int16_t ack:1; /**< ACK flag */159 u _int16_t urg:1; /**< URG flag */160 u _int16_t res2:2;/**< Reserved */154 unsigned int res1:4; /**< Reserved bits */ 155 unsigned int doff:4; /**< data offset */ 156 unsigned int fin:1; /**< FIN */ 157 unsigned int syn:1; /**< SYN flag */ 158 unsigned int rst:1; /**< RST flag */ 159 unsigned int psh:1; /**< PuSH flag */ 160 unsigned int ack:1; /**< ACK flag */ 161 unsigned int urg:1; /**< URG flag */ 162 unsigned int res2:2; /**< Reserved */ 161 163 # elif BYTE_ORDER == BIG_ENDIAN 162 u _int16_t doff:4;163 u _int16_t res1:4;/**< Reserved bits */164 u _int16_t res2:2;/**< Reserved */165 u _int16_t urg:1; /**< URG flag */166 u _int16_t ack:1; /**< ACK flag */167 u _int16_t psh:1; /**< PuSH flag */168 u _int16_t rst:1; /**< RST flag */169 u _int16_t syn:1; /**< SYN flag */170 u _int16_t fin:1; /**< FIN flag */164 unsigned int doff:4; /**< Data offset */ 165 unsigned int res1:4; /**< Reserved bits */ 166 unsigned int res2:2; /**< Reserved */ 167 unsigned int urg:1; /**< URG flag */ 168 unsigned int ack:1; /**< ACK flag */ 169 unsigned int psh:1; /**< PuSH flag */ 170 unsigned int rst:1; /**< RST flag */ 171 unsigned int syn:1; /**< SYN flag */ 172 unsigned int fin:1; /**< FIN flag */ 171 173 # else 172 174 # error "Adjust your <bits/endian.h> defines" … … 231 233 u_int8_t ether_shost[6]; /* source ether addr */ 232 234 u_int16_t ether_type; /* packet type ID field , 0x8100 for VLAN */ 233 u _int16_t vlan_pri:3;/* vlan user priority */234 u _int16_t vlan_cfi:1;/* vlan format indicator, 0 for ethernet, 1 for token ring */235 u _int16_t vlan_id:12;/* vlan id */235 unsigned int vlan_pri:3; /* vlan user priority */ 236 unsigned int vlan_cfi:1; /* vlan format indicator, 0 for ethernet, 1 for token ring */ 237 unsigned int vlan_id:12; /* vlan id */ 236 238 u_int16_t vlan_ether_type; /* vlan sub-packet type ID field (next-header)*/ 237 239 } __attribute__ ((packed)) libtrace_8021q_t; … … 240 242 typedef struct libtrace_atm_cell 241 243 { 242 u _int8_t gfc:4;244 unsigned int gfc:4; 243 245 u_int8_t vpi; 244 246 u_int16_t vci; 245 u _int8_t pt:3;246 u _int8_t clp:1;247 u _int8_t hec;247 unsigned int pt:3; 248 unsigned int clp:1; 249 unsigned int hec; 248 250 } __attribute__ ((packed)) libtrace_atm_cell; 249 251 … … 254 256 u_int16_t ether_type; 255 257 } __attribute__ ((packed)) libtrace_pos; 258 /*@}*/ 256 259 257 260 /** Prints help information for libtrace … … 265 268 * 266 269 * @param libtrace the output trace to get the name of the format fo 267 * @return scallee-owned null-terminated char* containing the output format268 * 269 */ 270 SIMPLE_FUNCTION 271 char *trace_get_output_format(const structlibtrace_out_t *libtrace);270 * @return callee-owned null-terminated char* containing the output format 271 * 272 */ 273 SIMPLE_FUNCTION 274 char *trace_get_output_format(const libtrace_out_t *libtrace); 272 275 273 276 /** Prints error information … … 279 282 /** @name Creation and destruction of traces 280 283 * These members deal with creating, configuring and cleaning up a trace object 281 * /282 //@{ 284 *@{ 285 */ 283 286 284 287 /** Create a trace file from a URI 285 288 * 286 289 * @param uri containing a valid libtrace URI 287 * @return sopaque pointer to a libtrace_t290 * @return opaque pointer to a libtrace_t 288 291 * 289 292 * Valid URI's are: … … 310 313 /** Creates a "dummy" trace file that has only the format type set. 311 314 * 312 * @return sopaque pointer to a (sparsely initialised) libtrace_t315 * @return opaque pointer to a (sparsely initialised) libtrace_t 313 316 * 314 317 * IMPORTANT: Do not attempt to call trace_read_packet or other such functions with … … 321 324 * 322 325 * @param uri the uri string describing the output format and destination 323 * @return sopaque pointer to a libtrace_output_t326 * @return opaque pointer to a libtrace_output_t 324 327 * @author Shane Alcock 325 328 * … … 333 336 * and trace_errno is set. Use trace_perror() to get more information 334 337 */ 335 struct libtrace_out_t *trace_create_output(const char *uri); 336 337 /** Parses an output options string and calls the appropriate function to deal with output options. 338 * 339 * @param libtrace the output trace object to apply the options to 340 * @param options the options string 341 * @returns -1 if option configuration failed, 0 otherwise 342 * 343 * @author Shane Alcock 344 */ 345 int trace_config_output(struct libtrace_out_t *libtrace, char *options); 338 libtrace_out_t *trace_create_output(const char *uri); 339 340 /** Start the capture 341 * @param libtrace The trace to start 342 * @return 0 on success 343 * 344 * This does the actual work with starting the trace capture, and applying 345 * all the config options. This may fail. 346 */ 347 int trace_start(libtrace_t *libtrace); 348 349 /** Start an output trace 350 * @param libtrace The trace to start 351 * @return 0 on success 352 * 353 * This does the actual work with starting a trace for write. This generally 354 * creates the file. 355 */ 356 int trace_start_output(libtrace_out_t *libtrace); 357 358 /** Valid trace capture options */ 359 typedef enum { 360 TRACE_OPTION_SNAPLEN, /**< Number of bytes captured */ 361 TRACE_OPTION_PROMISC, /**< Capture packets to other hosts */ 362 TRACE_OPTION_FILTER /**< Apply this filter to all packets recieved */ 363 } trace_option_t; 364 365 /** Sets an input config option 366 * @param libtrace the trace object to apply the option to 367 * @param option the option to set 368 * @param value the value to set the option to 369 * @return -1 if option configuration failed, 0 otherwise 370 * This should be called after trace_create, and before trace_start 371 */ 372 int trace_config(libtrace_t *libtrace, 373 trace_option_t option, 374 void *value); 375 376 typedef enum { 377 TRACE_OPTION_OUTPUT_FILEFLAGS, /**< File flags to open the trace file 378 * with. eg O_APPEND 379 */ 380 TRACE_OPTION_OUTPUT_COMPRESS /**< Compression level, eg 6. */ 381 } trace_option_output_t; 382 383 /** Sets an output config option 384 * 385 * @param libtrace the output trace object to apply the option to 386 * @param option the option to set 387 * @param value the value to set the option to 388 * @return -1 if option configuration failed, 0 otherwise 389 * This should be called after trace_create_output, and before 390 * trace_start_output 391 */ 392 int trace_config_output(libtrace_out_t *libtrace, 393 trace_option_output_t option, 394 void *value 395 ); 346 396 347 397 /** Close a trace file, freeing up any resources it may have been using 348 398 * 349 399 */ 350 void trace_destroy( structlibtrace_t *trace);400 void trace_destroy(libtrace_t *trace); 351 401 352 402 /** Close a trace file, freeing up any resources it may have been using 353 403 * @param trace trace file to be destroyed 354 404 */ 355 void trace_destroy_dead( structlibtrace_t *trace);405 void trace_destroy_dead(libtrace_t *trace); 356 406 357 407 /** Close a trace output file, freeing up any resources it may have been using … … 361 411 * @author Shane Alcock 362 412 */ 363 void trace_destroy_output( structlibtrace_out_t *trace);364 / /@}413 void trace_destroy_output(libtrace_out_t *trace); 414 /*@}*/ 365 415 366 416 /** @name Reading/Writing packets 367 417 * These members deal with creating, reading and writing packets 368 */ 369 //@{ 418 * 419 * @{ 420 */ 370 421 371 422 /** Create a new packet object … … 373 424 * @return a pointer to an initialised libtrace_packet_t object 374 425 */ 375 structlibtrace_packet_t *trace_create_packet();426 libtrace_packet_t *trace_create_packet(); 376 427 377 428 /** Destroy a packet object … … 379 430 * sideeffect: sets packet to NULL 380 431 */ 381 void trace_destroy_packet( structlibtrace_packet_t **packet);432 void trace_destroy_packet(libtrace_packet_t **packet); 382 433 383 434 … … 386 437 * @param trace the libtrace opaque pointer 387 438 * @param packet the packet opaque pointer 388 * @returns 0 on EOF, negative value on error 389 * 390 */ 391 int trace_read_packet(struct libtrace_t *trace, struct libtrace_packet_t *packet); 439 * @return 0 on EOF, negative value on error 440 * 441 * @note the trace must have been started with trace_start before calling 442 * this function 443 */ 444 int trace_read_packet(libtrace_t *trace, libtrace_packet_t *packet); 445 446 /** Event types 447 * see \ref libtrace_eventobj_t and \ref trace_event 448 */ 449 typedef enum { 450 TRACE_EVENT_IOWAIT, /**< Need to block on fd */ 451 TRACE_EVENT_SLEEP, /**< Sleep for some time */ 452 TRACE_EVENT_PACKET, /**< packet has arrived */ 453 TRACE_EVENT_TERMINATE /**< End of trace */ 454 } libtrace_event_t; 455 456 /** structure returned by libtrace_event explaining what the current event is */ 457 typedef struct libtrace_eventobj_t { 458 libtrace_event_t type; /**< event type (iowait,sleep,packet) */ 459 int fd; /**< if IOWAIT, the fd to sleep on */ 460 double seconds; /**< if SLEEP, the amount of time to sleep for */ 461 int size; /**< if PACKET, the value returned from trace_read_packet */ 462 } libtrace_eventobj_t; 463 464 /** process a libtrace event 465 * @param trace the libtrace opaque pointer 466 * @param packet the libtrace_packet opaque pointer 467 * @return libtrace_event struct containing the type, and potential 468 * fd or seconds to sleep on 469 * 470 * Type can be: 471 * TRACE_EVENT_IOWAIT Waiting on I/O on fd 472 * TRACE_EVENT_SLEEP Next event in seconds 473 * TRACE_EVENT_PACKET Packet arrived in buffer with size size 474 * TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition) 475 */ 476 libtrace_eventobj_t trace_event(libtrace_t *trace, 477 libtrace_packet_t *packet); 478 392 479 393 480 /** Write one packet out to the output trace … … 395 482 * @param trace the libtrace_out opaque pointer 396 483 * @param packet the packet opaque pointer 397 * @return sthe number of bytes written out, if zero or negative then an error has occured.398 */ 399 int trace_write_packet( struct libtrace_out_t *trace, const struct libtrace_packet_t *packet);400 / /@}484 * @return the number of bytes written out, if zero or negative then an error has occured. 485 */ 486 int trace_write_packet(libtrace_out_t *trace, const libtrace_packet_t *packet); 487 /*@}*/ 401 488 402 489 /** @name Headers 403 490 * These functions locate and return a pointer to various headers inside a packet 404 * /405 //@{ 491 * @{ 492 */ 406 493 407 494 /** get a pointer to the link layer 408 495 * @param packet the packet opaque pointer 409 496 * 410 * @return sa pointer to the link layer, or NULL if there is no link layer497 * @return a pointer to the link layer, or NULL if there is no link layer 411 498 * 412 499 * @note you should call getLinkType() to find out what type of link layer … … 414 501 */ 415 502 SIMPLE_FUNCTION 416 void *trace_get_link(const structlibtrace_packet_t *packet);503 void *trace_get_link(const libtrace_packet_t *packet); 417 504 418 505 /** get a pointer to the IP header (if any) 419 506 * @param packet the packet opaque pointer 420 507 * 421 * @return sa pointer to the IP header, or NULL if there is not an IP packet422 */ 423 SIMPLE_FUNCTION 424 struct libtrace_ip *trace_get_ip(const struct libtrace_packet_t *packet);508 * @return a pointer to the IP header, or NULL if there is not an IP packet 509 */ 510 SIMPLE_FUNCTION 511 libtrace_ip_t *trace_get_ip(const libtrace_packet_t *packet); 425 512 426 513 /** Gets a pointer to the transport layer header (if any) 427 514 * @param packet a pointer to a libtrace_packet structure 428 515 * 429 * @return sa pointer to the transport layer header, or NULL if there is no header430 */ 431 void *trace_get_transport(const structlibtrace_packet_t *packet);516 * @return a pointer to the transport layer header, or NULL if there is no header 517 */ 518 void *trace_get_transport(const libtrace_packet_t *packet); 432 519 433 520 /** Gets a pointer to the transport layer header (if any) given a pointer to the … … 436 523 * @param[out] skipped An output variable of the number of bytes skipped 437 524 * 438 * @return sa pointer to the transport layer header, or NULL if there is no header525 * @return a pointer to the transport layer header, or NULL if there is no header 439 526 * 440 527 * Skipped can be NULL, in which case it will be ignored 441 528 */ 442 void *trace_get_transport_from_ip(const struct libtrace_ip*ip, int *skipped);529 void *trace_get_transport_from_ip(const libtrace_ip_t *ip, int *skipped); 443 530 444 531 /** get a pointer to the TCP header (if any) 445 532 * @param packet the packet opaque pointer 446 533 * 447 * @return sa pointer to the TCP header, or NULL if there is not a TCP packet448 */ 449 SIMPLE_FUNCTION 450 struct libtrace_tcp *trace_get_tcp(const struct libtrace_packet_t *packet);534 * @return a pointer to the TCP header, or NULL if there is not a TCP packet 535 */ 536 SIMPLE_FUNCTION 537 libtrace_tcp_t *trace_get_tcp(const libtrace_packet_t *packet); 451 538 452 539 /** get a pointer to the TCP header (if any) given a pointer to the IP header … … 454 541 * @param[out] skipped An output variable of the number of bytes skipped 455 542 * 456 * @return sa pointer to the TCP header, or NULL if this is not a TCP packet543 * @return a pointer to the TCP header, or NULL if this is not a TCP packet 457 544 * 458 545 * Skipped can be NULL, in which case it will be ignored by the program. … … 461 548 */ 462 549 SIMPLE_FUNCTION 463 struct libtrace_tcp *trace_get_tcp_from_ip(const struct libtrace_ip*ip,int *skipped);550 libtrace_tcp_t *trace_get_tcp_from_ip(const libtrace_ip_t *ip,int *skipped); 464 551 465 552 /** get a pointer to the UDP header (if any) 466 553 * @param packet the packet opaque pointer 467 554 * 468 * @return sa pointer to the UDP header, or NULL if this is not a UDP packet469 */ 470 SIMPLE_FUNCTION 471 struct libtrace_udp *trace_get_udp(const struct libtrace_packet_t *packet);555 * @return a pointer to the UDP header, or NULL if this is not a UDP packet 556 */ 557 SIMPLE_FUNCTION 558 libtrace_udp_t *trace_get_udp(const libtrace_packet_t *packet); 472 559 473 560 /** get a pointer to the UDP header (if any) given a pointer to the IP header … … 475 562 * @param[out] skipped An output variable of the number of bytes skipped 476 563 * 477 * @return sa pointer to the UDP header, or NULL if this is not an UDP packet564 * @return a pointer to the UDP header, or NULL if this is not an UDP packet 478 565 * 479 566 * Skipped may be NULL, in which case it will be ignored by this function. 480 567 */ 481 568 SIMPLE_FUNCTION 482 struct libtrace_udp *trace_get_udp_from_ip(const struct libtrace_ip*ip,int *skipped);569 libtrace_udp_t *trace_get_udp_from_ip(const libtrace_ip_t *ip,int *skipped); 483 570 484 571 /** get a pointer to the ICMP header (if any) 485 572 * @param packet the packet opaque pointer 486 573 * 487 * @return sa pointer to the ICMP header, or NULL if this is not a ICMP packet488 */ 489 SIMPLE_FUNCTION 490 struct libtrace_icmp *trace_get_icmp(const struct libtrace_packet_t *packet);574 * @return a pointer to the ICMP header, or NULL if this is not a ICMP packet 575 */ 576 SIMPLE_FUNCTION 577 libtrace_icmp_t *trace_get_icmp(const libtrace_packet_t *packet); 491 578 492 579 /** get a pointer to the ICMP header (if any) given a pointer to the IP header … … 494 581 * @param[out] skipped An output variable of the number of bytes skipped 495 582 * 496 * @return sa pointer to the ICMP header, or NULL if this is not an ICMP packet583 * @return a pointer to the ICMP header, or NULL if this is not an ICMP packet 497 584 * 498 585 * Skipped may be NULL, in which case it will be ignored by this function 499 586 */ 500 587 SIMPLE_FUNCTION 501 struct libtrace_icmp *trace_get_icmp_from_ip(const struct libtrace_ip*ip,int *skipped);502 / /@}588 libtrace_icmp_t *trace_get_icmp_from_ip(const libtrace_ip_t *ip,int *skipped); 589 /*@}*/ 503 590 504 591 /** parse an ip or tcp option … … 509 596 * @param[out] data the data of the option 510 597 * 511 * @return sbool true if there is another option (and the fields are filled in)598 * @return bool true if there is another option (and the fields are filled in) 512 599 * or false if this was the last option. 513 600 * … … 528 615 * These functions deal with time that a packet arrived and return it 529 616 * in various formats 530 * /531 //@{ 617 * @{ 618 */ 532 619 /** Get the current time in DAG time format 533 620 * @param packet the packet opaque pointer 534 621 * 535 * @return sa 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds622 * @return a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds 536 623 * past 1970-01-01, the lower 32bits are partial seconds) 537 624 * @author Daniel Lawson 538 625 */ 539 626 SIMPLE_FUNCTION 540 uint64_t trace_get_erf_timestamp(const structlibtrace_packet_t *packet);627 uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet); 541 628 542 629 /** Get the current time in struct timeval 543 630 * @param packet the packet opaque pointer 544 631 * 545 * @return stime that this packet was seen in a struct timeval632 * @return time that this packet was seen in a struct timeval 546 633 * @author Daniel Lawson 547 634 * @author Perry Lorier 548 635 */ 549 636 SIMPLE_FUNCTION 550 struct timeval trace_get_timeval(const structlibtrace_packet_t *packet);637 struct timeval trace_get_timeval(const libtrace_packet_t *packet); 551 638 552 639 /** Get the current time in floating point seconds 553 640 * @param packet the packet opaque pointer 554 641 * 555 * @return stime that this packet was seen in 64bit floating point seconds556 * @author Daniel Lawson 557 * @author Perry Lorier 558 */ 559 SIMPLE_FUNCTION 560 double trace_get_seconds(const structlibtrace_packet_t *packet);561 / /@}642 * @return time that this packet was seen in 64bit floating point seconds 643 * @author Daniel Lawson 644 * @author Perry Lorier 645 */ 646 SIMPLE_FUNCTION 647 double trace_get_seconds(const libtrace_packet_t *packet); 648 /*@}*/ 562 649 563 650 /** @name Sizes 564 651 * This section deals with finding or setting the various different lengths 565 652 * a packet can have 566 * /567 //@{ 653 * @{ 654 */ 568 655 /** Get the size of the packet in the trace 569 656 * @param packet the packet opaque pointer 570 * @return sthe size of the packet in the trace657 * @return the size of the packet in the trace 571 658 * @author Perry Lorier 572 659 * @note Due to this being a header capture, or anonymisation, this may not … … 578 665 */ 579 666 SIMPLE_FUNCTION 580 int trace_get_capture_length(const structlibtrace_packet_t *packet);667 int trace_get_capture_length(const libtrace_packet_t *packet); 581 668 582 669 /** Get the size of the packet as it was seen on the wire. 583 670 * @param packet the packet opaque pointer 584 * @return sthe size of the packet as it was on the wire.671 * @return the size of the packet as it was on the wire. 585 672 * @author Perry Lorier 586 673 * @author Daniel Lawson … … 589 676 */ 590 677 SIMPLE_FUNCTION 591 int trace_get_wire_length(const structlibtrace_packet_t *packet);678 int trace_get_wire_length(const libtrace_packet_t *packet); 592 679 593 680 /** Get the length of the capture framing headers. 594 681 * @param packet the packet opaque pointer 595 * @return sthe size of the packet as it was on the wire.682 * @return the size of the packet as it was on the wire. 596 683 * @author Perry Lorier 597 684 * @author Daniel Lawson … … 600 687 */ 601 688 SIMPLE_FUNCTION 602 int trace_get_framing_length(const structlibtrace_packet_t *packet);689 int trace_get_framing_length(const libtrace_packet_t *packet); 603 690 604 691 /** Truncate the packet at the suggested length 605 692 * @param packet the packet opaque pointer 606 693 * @param size the new length of the packet 607 * @return sthe new length of the packet, or the original length of the694 * @return the new length of the packet, or the original length of the 608 695 * packet if unchanged 609 696 * @author Daniel Lawson 610 697 */ 611 size_t trace_set_capture_length( structlibtrace_packet_t *packet, size_t size);612 613 / /@}698 size_t trace_set_capture_length(libtrace_packet_t *packet, size_t size); 699 700 /*@}*/ 614 701 615 702 … … 635 722 /** Get the type of the link layer 636 723 * @param packet the packet opaque pointer 637 * @return slibtrace_linktype_t638 * @author Perry Lorier 639 * @author Daniel Lawson 640 */ 641 SIMPLE_FUNCTION 642 inline libtrace_linktype_t trace_get_link_type(const structlibtrace_packet_t *packet);724 * @return libtrace_linktype_t 725 * @author Perry Lorier 726 * @author Daniel Lawson 727 */ 728 SIMPLE_FUNCTION 729 inline libtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet); 643 730 644 731 /** Get the destination MAC addres 645 732 * @param packet the packet opaque pointer 646 * @return sa pointer to the destination mac, (or NULL if there is no733 * @return a pointer to the destination mac, (or NULL if there is no 647 734 * destination MAC) 648 735 * @author Perry Lorier 649 736 */ 650 737 SIMPLE_FUNCTION 651 uint8_t *trace_get_destination_mac(const structlibtrace_packet_t *packet);738 uint8_t *trace_get_destination_mac(const libtrace_packet_t *packet); 652 739 653 740 /** Get the source MAC addres 654 741 * @param packet the packet opaque pointer 655 * @return sa pointer to the source mac, (or NULL if there is no source MAC)656 * @author Perry Lorier 657 */ 658 SIMPLE_FUNCTION 659 uint8_t *trace_get_source_mac(const structlibtrace_packet_t *packet);742 * @return a pointer to the source mac, (or NULL if there is no source MAC) 743 * @author Perry Lorier 744 */ 745 SIMPLE_FUNCTION 746 uint8_t *trace_get_source_mac(const libtrace_packet_t *packet); 660 747 661 748 /** Set the direction flag, if it has one 662 749 * @param packet the packet opaque pointer 663 750 * @param direction the new direction (0,1,2,3) 664 * @return sa signed value containing the direction flag, or -1 if this is not supported665 * @author Daniel Lawson 666 */ 667 int8_t trace_set_direction( structlibtrace_packet_t *packet, int8_t direction);751 * @return a signed value containing the direction flag, or -1 if this is not supported 752 * @author Daniel Lawson 753 */ 754 int8_t trace_set_direction(libtrace_packet_t *packet, int8_t direction); 668 755 669 756 /** Get the direction flag, if it has one 670 757 * @param packet the packet opaque pointer 671 * @return sa signed value containing the direction flag, or -1 if this is not supported758 * @return a signed value containing the direction flag, or -1 if this is not supported 672 759 * The direction is defined as 0 for packets originating locally (ie, outbound) 673 760 * and 1 for packets originating remotely (ie, inbound). … … 677 764 */ 678 765 SIMPLE_FUNCTION 679 int8_t trace_get_direction(const struct libtrace_packet_t *packet); 680 681 /** Event types 682 * see \ref libtrace_eventobj_t and \ref trace_event 683 */ 684 typedef enum { 685 TRACE_EVENT_IOWAIT, /**< Need to block on fd */ 686 TRACE_EVENT_SLEEP, /**< Sleep for some time */ 687 TRACE_EVENT_PACKET, /**< packet has arrived */ 688 TRACE_EVENT_TERMINATE /**< End of trace */ 689 } libtrace_event_t; 690 691 /** structure returned by libtrace_event explaining what the current event is */ 692 struct libtrace_eventobj_t { 693 libtrace_event_t type; /**< event type (iowait,sleep,packet) */ 694 int fd; /**< if IOWAIT, the fd to sleep on */ 695 double seconds; /**< if SLEEP, the amount of time to sleep for */ 696 int size; /**< if PACKET, the value returned from trace_read_packet */ 697 }; 698 699 /** process a libtrace event 700 * @param trace the libtrace opaque pointer 701 * @param packet the libtrace_packet opaque pointer 702 * @returns libtrace_event struct containing the type, and potential 703 * fd or seconds to sleep on 704 * 705 * Type can be: 706 * TRACE_EVENT_IOWAIT Waiting on I/O on fd 707 * TRACE_EVENT_SLEEP Next event in seconds 708 * TRACE_EVENT_PACKET Packet arrived in buffer with size size 709 * TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition) 710 */ 711 struct libtrace_eventobj_t trace_event(struct libtrace_t *trace, 712 struct libtrace_packet_t *packet); 766 int8_t trace_get_direction(const libtrace_packet_t *packet); 713 767 714 768 /** @name BPF 715 769 * This section deals with using Berkley Packet Filters 716 * /717 //@{ 770 * @{ 771 */ 718 772 /** setup a BPF filter 719 773 * @param filterstring a char * containing the bpf filter string 720 * @return sopaque pointer pointer to a libtrace_filter_t object774 * @return opaque pointer pointer to a libtrace_filter_t object 721 775 * @author Daniel Lawson 722 776 * @note The filter is not actually compiled at this point, so no correctness … … 726 780 */ 727 781 SIMPLE_FUNCTION 728 structlibtrace_filter_t *trace_bpf_setfilter(const char *filterstring);782 libtrace_filter_t *trace_bpf_setfilter(const char *filterstring); 729 783 730 784 /** apply a BPF filter 731 785 * @param filter the filter opaque pointer 732 786 * @param packet the packet opaque pointer 733 * @return s0 if the filter fails, 1 if it succeeds787 * @return 0 if the filter fails, 1 if it succeeds 734 788 * @author Daniel Lawson 735 789 * @note Due to the way BPF filters are built, the filter is not actually compiled 736 790 * until the first time trace_bpf_filter is called. If your filter is incorrect, it will generate an error message and assert, exiting the program. This behaviour may change to more graceful handling of this error in the future. 737 791 */ 738 int trace_bpf_filter( structlibtrace_filter_t *filter,739 const structlibtrace_packet_t *packet);740 / /@}792 int trace_bpf_filter(libtrace_filter_t *filter, 793 const libtrace_packet_t *packet); 794 /*@}*/ 741 795 742 796 /** Which port is the server port */ … … 748 802 /** Get the source port 749 803 * @param packet the packet to read from 750 * @return sa port in \em HOST byte order, or equivilent to ports for this804 * @return a port in \em HOST byte order, or equivilent to ports for this 751 805 * protocol, or 0 if this protocol has no ports. 752 806 * @author Perry Lorier 753 807 */ 754 808 SIMPLE_FUNCTION 755 uint16_t trace_get_source_port(const structlibtrace_packet_t *packet);809 uint16_t trace_get_source_port(const libtrace_packet_t *packet); 756 810 757 811 /** Get the destination port 758 812 * @param packet the packet to read from 759 * @return sa port in \em HOST byte order, or equivilent to ports for this813 * @return a port in \em HOST byte order, or equivilent to ports for this 760 814 * protocol, or 0 if this protocol has no ports. 761 815 * @author Perry Lorier 762 816 */ 763 817 SIMPLE_FUNCTION 764 uint16_t trace_get_destination_port(const structlibtrace_packet_t *packet);818 uint16_t trace_get_destination_port(const libtrace_packet_t *packet); 765 819 766 820 /** hint at the server port in specified protocol … … 768 822 * @param source the source port from the packet 769 823 * @param dest the destination port from the packet 770 * @return sone of USE_SOURCE or USE_DEST depending on which one you should use824 * @return one of USE_SOURCE or USE_DEST depending on which one you should use 771 825 * @note ports must be in \em HOST byte order! 772 826 * @author Daniel Lawson … … 779 833 * @param uri the uri to be parsed 780 834 * @param format destination location for the format component of the uri 781 * @return s 0 if an error occured, otherwise returnsthe uridata component835 * @return 0 if an error occured, otherwise return the uridata component 782 836 * @author Shane Alcock 783 837 */ 784 838 const char *trace_parse_uri(const char *uri, char **format); 785 839 #ifdef __cplusplus 786 } / / extern "C"787 #endif / / #ifdef __cplusplus788 #endif / / LIBTRACE_H_840 } /* extern "C" */ 841 #endif /* #ifdef __cplusplus */ 842 #endif /* LIBTRACE_H_ */ -
lib/libtrace_int.h
r37195b4 r7068467 77 77 78 78 extern struct trace_err_t{ 79 int err_num; // error code80 char problem[255]; / / the format, uri etc that caused the error for reporting purposes79 int err_num; /* error code */ 80 char problem[255]; /* the format, uri etc that caused the error for reporting purposes */ 81 81 } trace_err; 82 82 … … 153 153 char *type; 154 154 int (*init_input)(struct libtrace_t *libtrace); 155 int (*config_input)(struct libtrace_t *libtrace, char *option,void *value);155 int (*config_input)(struct libtrace_t *libtrace,trace_option_t option,void *value); 156 156 int (*start_input)(struct libtrace_t *libtrace); 157 157 int (*init_output)(struct libtrace_out_t *libtrace); 158 int (*config_output)(struct libtrace_out_t *libtrace, int argc, char *argv[]);158 int (*config_output)(struct libtrace_out_t *libtrace, trace_option_output_t, void *); 159 159 int (*start_output)(struct libtrace_out_t *libtrace); 160 160 int (*fin_input)(struct libtrace_t *libtrace); … … 180 180 181 181 void register_format(struct libtrace_format_t *format); 182 183 libtrace_linktype_t pcap_dlt_to_libtrace(int dlt); 184 char libtrace_to_pcap_dlt(libtrace_linktype_t type); 185 libtrace_linktype_t erf_type_to_libtrace(char erf); 186 char libtrace_to_erf_type(libtrace_linktype_t linktype); 187 182 188 183 189 #ifdef __cplusplus … … 185 191 #endif 186 192 187 #endif / / LIBTRACE_INT_H193 #endif /* LIBTRACE_INT_H */ -
lib/parse_cmd.h
r283acce r7068467 5 5 6 6 7 #endif / / PARSE_CMD_H7 #endif /* PARSE_CMD_H */ -
lib/trace.c
r37195b4 r7068467 264 264 trace_err.err_num = E_NOERROR; 265 265 266 / / parse the URI to determine what sort of event we are dealing with266 /* parse the URI to determine what sort of event we are dealing with */ 267 267 if ((uridata = trace_parse_uri(uri, &scan)) == 0) { 268 268 return 0; … … 284 284 trace_err.err_num = E_BAD_FORMAT; 285 285 strcpy(trace_err.problem, scan); 286 //trace_err.problem = scan;287 286 return 0; 288 287 } 289 288 290 289 libtrace->uridata = strdup(uridata); 291 // libtrace->format now contains the type of uri 292 // libtrace->uridata contains the appropriate data for this 290 /* libtrace->format now contains the type of uri 291 * libtrace->uridata contains the appropriate data for this 292 */ 293 293 294 294 if (libtrace->format->init_input) { … … 296 296 trace_err.err_num = E_INIT_FAILED; 297 297 strcpy(trace_err.problem, scan); 298 //trace_err.problem = scan;299 298 return 0; 300 299 } … … 302 301 trace_err.err_num = E_NO_INIT; 303 302 strcpy(trace_err.problem, scan); 304 //trace_err.problem = scan;305 303 return 0; 306 304 } … … 350 348 trace_err.err_num = E_BAD_FORMAT; 351 349 strcpy(trace_err.problem, scan); 352 //trace_err.problem = scan;353 350 return 0; 354 351 } … … 383 380 384 381 trace_err.err_num = E_NOERROR; 385 / / parse the URI to determine what sort of event we are dealing with382 /* parse the URI to determine what sort of event we are dealing with */ 386 383 387 384 if ((uridata = trace_parse_uri(uri, &scan)) == 0) { … … 403 400 trace_err.err_num = E_BAD_FORMAT; 404 401 strcpy(trace_err.problem, scan); 405 //trace_err.problem = scan;406 402 return 0; 407 403 } … … 409 405 410 406 411 // libtrace->format now contains the type of uri 412 // libtrace->uridata contains the appropriate data for this 407 /* libtrace->format now contains the type of uri 408 * libtrace->uridata contains the appropriate data for this 409 */ 413 410 414 411 if (libtrace->format->init_output) { … … 419 416 trace_err.err_num = E_NO_INIT_OUT; 420 417 strcpy(trace_err.problem, scan); 421 //trace_err.problem = scan;422 418 return 0; 423 419 } … … 458 454 * @author Shane Alcock 459 455 */ 460 int trace_config_output(struct libtrace_out_t *libtrace, char *options) { 461 char *opt_string = 0; 462 char *opt_argv[MAXOPTS]; 463 int opt_argc = 0; 464 465 assert(libtrace); 466 467 if (!options) { 468 return 0; 469 } 470 asprintf(&opt_string, "%s %s", libtrace->format->name, options); 471 parse_cmd(opt_string, &opt_argc, opt_argv, MAXOPTS); 472 456 int trace_config_output(struct libtrace_out_t *libtrace, 457 trace_option_output_t option, 458 void *value) { 473 459 if (libtrace->format->config_output) { 474 return libtrace->format->config_output(libtrace, opt _argc, opt_argv);460 return libtrace->format->config_output(libtrace, option, value); 475 461 } 476 462 return -1; … … 483 469 assert(libtrace); 484 470 libtrace->format->fin_input(libtrace); 485 / / need to free things!471 /* need to free things! */ 486 472 free(libtrace->uridata); 487 473 destroy_tracefifo(libtrace->fifo); … … 508 494 } 509 495 510 /** Create a new packet object 511 * 512 * @ return a pointer to an initialised libtrace_packet_t structure 513 */ 514 struct libtrace_packet_t *trace_create_packet() { 515 struct libtrace_packet_t *packet = calloc(1,sizeof(struct libtrace_packet_t)); 516 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 517 packet->buf_control = PACKET; 496 libtrace_packet_t *trace_create_packet() { 497 libtrace_packet_t *packet = calloc(1,sizeof(libtrace_packet_t)); 498 /* This used to malloc a packet! Why do we need to malloc a packet 499 * if we're doing zero copy? 500 */ 518 501 return packet; 519 502 } … … 607 590 case TRACE_TYPE_80211_PRISM: 608 591 { 609 struct ieee_802_11_header *wifi = trace_get_link(packet)+144;592 struct ieee_802_11_header *wifi = (char*)trace_get_link(packet)+144; 610 593 if (!wifi) { 611 594 ipptr = NULL; … … 613 596 } 614 597 615 / / Data packet?598 /* Data packet? */ 616 599 if (wifi->type != 2) { 617 600 ipptr = NULL; … … 644 627 } 645 628 646 / / Data packet?629 /* Data packet? */ 647 630 if (wifi->type != 2) { 648 631 ipptr = NULL; … … 727 710 case TRACE_TYPE_LEGACY_POS: 728 711 { 729 / / 64 byte capture.712 /* 64 byte capture. */ 730 713 struct libtrace_pos *pos = 731 714 trace_get_link(packet); … … 741 724 case TRACE_TYPE_ATM: 742 725 { 743 / / 64 byte capture.726 /* 64 byte capture. */ 744 727 struct libtrace_llcsnap *llc = 745 728 trace_get_link(packet); 746 729 747 // advance the llc ptr +4 into the link layer. 748 // need to check what is in these 4 bytes. 749 // don't have time! 730 /* advance the llc ptr +4 into the link layer. 731 * need to check what is in these 4 bytes. 732 * don't have time! 733 */ 750 734 llc = (void *)llc + 4; 751 735 if (ntohs(llc->type) == 0x0800) { … … 796 780 * Skipped can be NULL, in which case it will be ignored 797 781 */ 798 void *trace_get_transport_from_ip(const struct libtrace_ip*ip, int *skipped) {782 void *trace_get_transport_from_ip(const libtrace_ip_t *ip, int *skipped) { 799 783 void *trans_ptr = 0; 800 784 … … 814 798 * @returns a pointer to the TCP header, or NULL if there is not a TCP packet 815 799 */ 816 struct libtrace_tcp *trace_get_tcp(const struct libtrace_packet_t *packet) {800 libtrace_tcp_t *trace_get_tcp(const libtrace_packet_t *packet) { 817 801 struct libtrace_tcp *tcpptr = 0; 818 802 struct libtrace_ip *ipptr = 0; … … 835 819 * Skipped can be NULL, in which case it will be ignored by the program. 836 820 */ 837 struct libtrace_tcp *trace_get_tcp_from_ip(const struct libtrace_ip*ip, int *skipped)821 libtrace_tcp_t *trace_get_tcp_from_ip(const libtrace_ip_t *ip, int *skipped) 838 822 { 839 #define SW_IP_OFFMASK 0xff1f840 823 struct libtrace_tcp *tcpptr = 0; 841 824 … … 958 941 *optlen = *(*ptr+1); 959 942 if (*optlen<2) 960 return 0; // I have no idea wtf is going on 961 // with these packets 943 return 0; /* I have no idea wtf is going on 944 * with these packets 945 */ 962 946 (*len)-=*optlen; 963 947 (*data)=(*ptr+2); … … 985 969 986 970 if (packet->trace->format->get_erf_timestamp) { 987 / / timestamp -> timestamp971 /* timestamp -> timestamp */ 988 972 timestamp = packet->trace->format->get_erf_timestamp(packet); 989 973 } else if (packet->trace->format->get_timeval) { 990 / / timeval -> timestamp974 /* timeval -> timestamp */ 991 975 ts = packet->trace->format->get_timeval(packet); 992 976 timestamp = ((((uint64_t)ts.tv_sec) << 32) + \ 993 977 (((uint64_t)ts.tv_usec * UINT_MAX)/1000000)); 994 978 } else if (packet->trace->format->get_seconds) { 995 / / seconds -> timestamp979 /* seconds -> timestamp */ 996 980 seconds = packet->trace->format->get_seconds(packet); 997 981 timestamp = ((uint64_t)((uint32_t)seconds) << 32) + \ … … 1014 998 assert(packet->size>0 && packet->size<65536); 1015 999 if (packet->trace->format->get_timeval) { 1016 / / timeval -> timeval1000 /* timeval -> timeval */ 1017 1001 tv = packet->trace->format->get_timeval(packet); 1018 1002 } else if (packet->trace->format->get_erf_timestamp) { 1019 / / timestamp -> timeval1003 /* timestamp -> timeval */ 1020 1004 ts = packet->trace->format->get_erf_timestamp(packet); 1021 1005 #if __BYTE_ORDER == __BIG_ENDIAN … … 1034 1018 } 1035 1019 } else if (packet->trace->format->get_seconds) { 1036 / / seconds -> timeval1020 /* seconds -> timeval */ 1037 1021 seconds = packet->trace->format->get_seconds(packet); 1038 1022 tv.tv_sec = (uint32_t)seconds; … … 1056 1040 1057 1041 if (packet->trace->format->get_seconds) { 1058 / / seconds->seconds1042 /* seconds->seconds */ 1059 1043 seconds = packet->trace->format->get_seconds(packet); 1060 1044 } else if (packet->trace->format->get_erf_timestamp) { 1061 / / timestamp -> seconds1045 /* timestamp -> seconds */ 1062 1046 ts = packet->trace->format->get_erf_timestamp(packet); 1063 1047 seconds = (ts>>32) + ((ts & UINT_MAX)*1.0 / UINT_MAX); 1064 1048 } else if (packet->trace->format->get_timeval) { 1065 / / timeval -> seconds1049 /* timeval -> seconds */ 1066 1050 tv = packet->trace->format->get_timeval(packet); 1067 1051 seconds = tv.tv_sec + ((tv.tv_usec * UINT_MAX * 1.0)/1000000); … … 1265 1249 pcap_t *pcap; 1266 1250 struct bpf_program bpfprog; 1267 1268 switch (trace_get_link_type(packet)) { 1269 case TRACE_TYPE_ETH: 1270 pcap = (pcap_t *)pcap_open_dead(DLT_EN10MB, 1500); 1271 break; 1272 #ifdef DLT_LINUX_SLL 1273 case TRACE_TYPE_LINUX_SLL: 1274 pcap = (pcap_t *)pcap_open_dead(DLT_LINUX_SLL, 1500); 1275 break; 1276 #endif 1277 #ifdef DLT_PFLOG 1278 case TRACE_TYPE_PFLOG: 1279 pcap = (pcap_t *)pcap_open_dead(DLT_PFLOG, 1500); 1280 break; 1281 #endif 1282 default: 1283 printf("only works for ETH and LINUX_SLL (ppp) at the moment\n"); 1284 assert(0); 1285 } 1286 1287 // build filter 1251 pcap=(pcap_t *)pcap_open_dead( 1252 libtrace_to_pcap_dlt(trace_get_link_type(packet)), 1253 1500); 1254 /* build filter */ 1288 1255 if (pcap_compile( pcap, &bpfprog, filter->filterstring, 1, 0)) { 1289 1256 printf("bpf compilation error: %s: %s\n", … … 1481 1448 return USE_DEST; 1482 1449 */ 1483 / / failing that test...1450 /* failing that test... */ 1484 1451 if (source < dest) { 1485 1452 return USE_SOURCE; … … 1516 1483 1517 1484 if((uridata = strchr(uri,':')) == NULL) { 1518 / / badly formed URI - needs a :1485 /* badly formed URI - needs a : */ 1519 1486 trace_err.err_num = E_URI_NOCOLON; 1520 1487 return 0; … … 1522 1489 1523 1490 if ((uridata - uri) > URI_PROTO_LINE) { 1524 / / badly formed URI - uri type is too long1491 /* badly formed URI - uri type is too long */ 1525 1492 trace_err.err_num = E_URI_LONG; 1526 1493 return 0; … … 1529 1496 *format=xstrndup(uri, (uridata - uri)); 1530 1497 1531 / / push uridata past the delimiter1498 /* push uridata past the delimiter */ 1532 1499 uridata++; 1533 1500 -
lib/wag.h
r9a36e6d r7068467 31 31 #define _WAG_H_ 32 32 33 / / Generic field breakdowns33 /* Generic field breakdowns */ 34 34 struct wag_frame_hdr { 35 35 uint16_t magic; … … 44 44 }; 45 45 46 / / Received packet frame fields46 /* Received packet frame fields */ 47 47 struct wag_stream_info { 48 48 uint16_t unused_1; … … 73 73 }; 74 74 75 / / Transmit packet frame fields75 /* Transmit packet frame fields */ 76 76 struct wag_txparams { 77 77 uint8_t gain; … … 90 90 91 91 struct ieee_802_11_header { 92 u int8_tprotocol:2;93 u int8_ttype:2;94 u int8_tsubtype:4;95 u int8_tto_ds:1;96 u int8_tfrom_ds:1;97 u int8_tmore_frag:1;98 u int8_tretry:1;99 u int8_tpower:1;100 u int8_tmore_data:1;101 u int8_twep:1;102 u int8_torder:1;92 unsigned int protocol:2; 93 unsigned int type:2; 94 unsigned int subtype:4; 95 unsigned int to_ds:1; 96 unsigned int from_ds:1; 97 unsigned int more_frag:1; 98 unsigned int retry:1; 99 unsigned int power:1; 100 unsigned int more_data:1; 101 unsigned int wep:1; 102 unsigned int order:1; 103 103 uint16_t duration; 104 104 uint8_t mac1[6];
Note: See TracChangeset
for help on using the changeset viewer.