- Timestamp:
- 08/04/05 15:37:08 (17 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:
- ef55d05
- Parents:
- fe43699
- Location:
- lib
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
rfe43699 r9e2a109 30 30 31 31 #include "libtrace.h" 32 #include " format.h"32 #include "libtrace_int.h" 33 33 #include "rtserver.h" 34 34 #include "parse_cmd.h" … … 62 62 #endif 63 63 64 #define CONNINFO libtrace->format_data->conn_info 65 #define INPUT libtrace->format_data->input 66 #define DAG libtrace->format_data->dag 67 struct libtrace_format_data_t { 68 union { 69 /** Information about rtclients */ 70 struct { 71 char *hostname; 72 short port; 73 } rt; 74 char *path; /**< information for local sockets */ 75 } conn_info; 76 /** Information about the current state of the input device */ 77 union { 78 int fd; 79 #if HAVE_ZLIB 80 gzFile *file; 81 #else 82 FILE *file; 83 #endif 84 } input; 85 86 struct { 87 void *buf; 88 unsigned bottom; 89 unsigned top; 90 unsigned diff; 91 unsigned curr; 92 unsigned offset; 93 } dag; 94 }; 95 96 struct libtrace_format_data_out_t { 97 union { 98 struct { 99 char *hostname; 100 short port; 101 } rt; 102 char *path; 103 } conn_info; 104 105 union { 106 struct { 107 int level; 108 } erf; 109 110 } options; 111 112 union { 113 int fd; 114 struct rtserver_t * rtserver; 115 #if HAVE_ZLIB 116 gzFile *file; 117 #else 118 FILE *file; 119 #endif 120 } output; 121 }; 122 64 123 #ifdef HAVE_DAG 65 124 static int dag_init_input(struct libtrace_t *libtrace) { 66 125 struct stat buf; 67 if (stat(libtrace->conn_info.path,&buf) == -1) { 126 libtrace->format_data = (struct libtrace_format_data_t *) 127 malloc(sizeof(struct libtrace_format_data_t)); 128 129 CONNINFO.path = libtrace->uridata; 130 if (stat(CONNINFO.path,&buf) == -1) { 68 131 perror("stat"); 69 132 return 0; … … 71 134 if (S_ISCHR(buf.st_mode)) { 72 135 // DEVICE 73 if(( libtrace->input.fd =74 dag_open( libtrace->conn_info.path)) < 0) {136 if((INPUT.fd = 137 dag_open(CONNINFO.path)) < 0) { 75 138 fprintf(stderr,"Cannot open DAG %s: %m\n", 76 libtrace->conn_info.path,errno);139 CONNINFO.path,errno); 77 140 exit(0); 78 141 } 79 if(( libtrace->dag.buf = (void *)80 dag_mmap( libtrace->input.fd)) == MAP_FAILED) {142 if((DAG.buf = (void *) 143 dag_mmap(INPUT.fd)) == MAP_FAILED) { 81 144 fprintf(stderr,"Cannot mmap DAG %s: %m\n", 82 libtrace->conn_info.path,errno);145 CONNINFO.path,errno); 83 146 exit(0); 84 147 } 85 if(dag_start( libtrace->input.fd) < 0) {148 if(dag_start(INPUT.fd) < 0) { 86 149 fprintf(stderr,"Cannot start DAG %s: %m\n", 87 libtrace->conn_info.path,errno);150 CONNINFO.path,errno); 88 151 exit(0); 89 152 } 90 153 } else { 91 154 fprintf(stderr,"%s isn't a valid char device, exiting\n", 92 libtrace->conn_info.path);155 CONNINFO.path); 93 156 return 0; 94 157 } … … 101 164 struct sockaddr_in remote; 102 165 struct sockaddr_un unix_sock; 103 if (!strncmp(libtrace->conn_info.path,"-",1)) { 166 libtrace->format_data = (struct libtrace_format_data_t *) 167 malloc(sizeof(struct libtrace_format_data_t)); 168 169 CONNINFO.path = libtrace->uridata; 170 if (!strncmp(CONNINFO.path,"-",1)) { 104 171 // STDIN 105 172 #if HAVE_ZLIB 106 libtrace->input.file = gzdopen(STDIN, "r");173 INPUT.file = gzdopen(STDIN, "r"); 107 174 #else 108 libtrace->input.file = stdin;175 INPUT.file = stdin; 109 176 #endif 110 177 111 178 } else { 112 if (stat( libtrace->conn_info.path,&buf) == -1 ) {179 if (stat(CONNINFO.path,&buf) == -1 ) { 113 180 perror("stat"); 114 181 return 0; … … 116 183 if (S_ISSOCK(buf.st_mode)) { 117 184 // SOCKET 118 if (( libtrace->input.fd = socket(185 if ((INPUT.fd = socket( 119 186 AF_UNIX, SOCK_STREAM, 0)) == -1) { 120 187 perror("socket"); … … 125 192 snprintf(unix_sock.sun_path, 126 193 108,"%s" 127 , libtrace->conn_info.path);128 129 if (connect( libtrace->input.fd,194 ,CONNINFO.path); 195 196 if (connect(INPUT.fd, 130 197 (struct sockaddr *)&unix_sock, 131 198 sizeof(struct sockaddr)) == -1) { … … 139 206 // ourselves. However, this way is messy and 140 207 // we lose any error checking on "open" 141 libtrace->input.file =208 INPUT.file = 142 209 gzdopen(open( 143 libtrace->conn_info.path,210 CONNINFO.path, 144 211 O_LARGEFILE), "r"); 145 212 #else 146 libtrace->input.file =213 INPUT.file = 147 214 fdopen(open( 148 libtrace->conn_info.path,215 CONNINFO.path, 149 216 O_LARGEFILE), "r"); 150 217 #endif … … 156 223 static int rtclient_init_input(struct libtrace_t *libtrace) { 157 224 char *scan; 158 char *uridata = libtrace-> conn_info.path;225 char *uridata = libtrace->uridata; 159 226 struct hostent *he; 160 227 struct sockaddr_in remote; 228 libtrace->format_data = (struct libtrace_format_data_t *) 229 malloc(sizeof(struct libtrace_format_data_t)); 161 230 162 231 if (strlen(uridata) == 0) { 163 libtrace->conn_info.rt.hostname =232 CONNINFO.rt.hostname = 164 233 strdup("localhost"); 165 libtrace->conn_info.rt.port =234 CONNINFO.rt.port = 166 235 COLLECTOR_PORT; 167 236 } else { 168 237 if ((scan = strchr(uridata,':')) == NULL) { 169 libtrace->conn_info.rt.hostname =238 CONNINFO.rt.hostname = 170 239 strdup(uridata); 171 libtrace->conn_info.rt.port =240 CONNINFO.rt.port = 172 241 COLLECTOR_PORT; 173 242 } else { 174 libtrace->conn_info.rt.hostname =243 CONNINFO.rt.hostname = 175 244 (char *)strndup(uridata, 176 245 (scan - uridata)); 177 libtrace->conn_info.rt.port =246 CONNINFO.rt.port = 178 247 atoi(++scan); 179 248 } 180 249 } 181 250 182 if ((he=gethostbyname( libtrace->conn_info.rt.hostname)) == NULL) {251 if ((he=gethostbyname(CONNINFO.rt.hostname)) == NULL) { 183 252 perror("gethostbyname"); 184 253 return 0; 185 254 } 186 if (( libtrace->input.fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {255 if ((INPUT.fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 187 256 perror("socket"); 188 257 return 0; … … 190 259 191 260 remote.sin_family = AF_INET; 192 remote.sin_port = htons( libtrace->conn_info.rt.port);261 remote.sin_port = htons(CONNINFO.rt.port); 193 262 remote.sin_addr = *((struct in_addr *)he->h_addr); 194 263 bzero(&(remote.sin_zero), 8); 195 264 196 if (connect( libtrace->input.fd, (struct sockaddr *)&remote,265 if (connect(INPUT.fd, (struct sockaddr *)&remote, 197 266 sizeof(struct sockaddr)) == -1) { 198 267 perror("connect (inet)"); … … 203 272 static int erf_init_output(struct libtrace_out_t *libtrace) { 204 273 char *filemode = 0; 205 206 libtrace->options.erf.level = 1; 207 asprintf(&filemode,"wb%d",libtrace->options.erf.level); 274 libtrace->format_data = (struct libtrace_format_data_out_t *) 275 calloc(1,sizeof(struct libtrace_format_data_out_t)); 276 277 libtrace->format_data->options.erf.level = 1; 278 asprintf(&filemode,"wb%d",libtrace->format_data->options.erf.level); 208 279 209 280 if (!strncmp(libtrace->uridata,"-",1)) { 210 281 // STDOUT 211 282 #if HAVE_ZLIB 212 libtrace-> output.file = gzdopen(dup(1), filemode);283 libtrace->format_data->output.file = gzdopen(dup(1), filemode); 213 284 #else 214 libtrace-> output.file = stdout;285 libtrace->format_data->output.file = stdout; 215 286 #endif 216 287 } … … 221 292 // ourselves. However, this way is messy and 222 293 // we lose any error checking on "open" 223 libtrace-> output.file = gzdopen(open(294 libtrace->format_data->output.file = gzdopen(open( 224 295 libtrace->uridata, 225 296 O_CREAT | O_LARGEFILE | O_WRONLY, 226 297 S_IRUSR | S_IWUSR), filemode); 227 298 #else 228 libtrace-> output.file = fdopen(open(299 libtrace->format_data->output.file = fdopen(open( 229 300 libtrace->uridata, 230 301 O_CREAT | O_LARGEFILE | O_WRONLY, … … 239 310 char * uridata = libtrace->uridata; 240 311 char * scan; 312 libtrace->format_data = (struct libtrace_format_data_out_t *) 313 calloc(1,sizeof(struct libtrace_format_data_out_t)); 241 314 // extract conn_info from uridata 242 315 if (strlen(uridata) == 0) { 243 libtrace->conn_info.rt.hostname = strdup("localhost"); 244 libtrace->conn_info.rt.port = COLLECTOR_PORT; 316 libtrace->format_data->conn_info.rt.hostname = 317 strdup("localhost"); 318 libtrace->format_data->conn_info.rt.port = COLLECTOR_PORT; 245 319 } 246 320 else { 247 321 if ((scan = strchr(uridata,':')) == NULL) { 248 libtrace-> conn_info.rt.hostname =322 libtrace->format_data->conn_info.rt.hostname = 249 323 strdup(uridata); 250 libtrace-> conn_info.rt.port =324 libtrace->format_data->conn_info.rt.port = 251 325 COLLECTOR_PORT; 252 326 } else { 253 libtrace-> conn_info.rt.hostname =327 libtrace->format_data->conn_info.rt.hostname = 254 328 (char *)strndup(uridata, 255 329 (scan - uridata)); 256 libtrace-> conn_info.rt.port =330 libtrace->format_data->conn_info.rt.port = 257 331 atoi(++scan); 258 332 } … … 260 334 261 335 262 libtrace->output.rtserver = rtserver_create(libtrace->conn_info.rt.hostname, 263 libtrace->conn_info.rt.port); 264 if (!libtrace->output.rtserver) 336 libtrace->format_data->output.rtserver = 337 rtserver_create(libtrace->format_data->conn_info.rt.hostname, 338 libtrace->format_data->conn_info.rt.port); 339 if (!libtrace->format_data->output.rtserver) 265 340 return 0; 266 341 … … 269 344 static int erf_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 270 345 int opt; 271 int level = libtrace-> options.erf.level;346 int level = libtrace->format_data->options.erf.level; 272 347 optind = 1; 273 348 … … 283 358 } 284 359 } 285 if (level != libtrace-> options.erf.level) {360 if (level != libtrace->format_data->options.erf.level) { 286 361 if (level > 9 || level < 0) { 287 362 // retarded level choice … … 289 364 290 365 } else { 291 libtrace-> options.erf.level = level;292 return gzsetparams(libtrace-> output.file, level, Z_DEFAULT_STRATEGY);366 libtrace->format_data->options.erf.level = level; 367 return gzsetparams(libtrace->format_data->output.file, level, Z_DEFAULT_STRATEGY); 293 368 } 294 369 } … … 303 378 #ifdef HAVE_DAG 304 379 static int dag_fin_input(struct libtrace_t *libtrace) { 305 dag_stop( libtrace->input.fd);380 dag_stop(INPUT.fd); 306 381 } 307 382 #endif … … 309 384 static int erf_fin_input(struct libtrace_t *libtrace) { 310 385 #if HAVE_ZLIB 311 gzclose( libtrace->input.file);386 gzclose(INPUT.file); 312 387 #else 313 fclose( libtrace->input.file);388 fclose(INPUT.file); 314 389 #endif 315 390 } 316 391 317 392 static int rtclient_fin_input(struct libtrace_t *libtrace) { 318 close( libtrace->input.fd);393 close(INPUT.fd); 319 394 } 320 395 321 396 static int erf_fin_output(struct libtrace_out_t *libtrace) { 322 397 #if HAVE_ZLIB 323 gzclose(libtrace-> output.file);398 gzclose(libtrace->format_data->output.file); 324 399 #else 325 fclose(libtrace-> output.file);400 fclose(libtrace->format_data->output.file); 326 401 #endif 327 402 } … … 329 404 330 405 static int rtclient_fin_output(struct libtrace_out_t *libtrace) { 331 rtserver_destroy(libtrace-> output.rtserver);406 rtserver_destroy(libtrace->format_data->output.rtserver); 332 407 } 333 408 … … 342 417 buffer = malloc(len); 343 418 344 libtrace->dag.bottom = libtrace->dag.top;345 libtrace->dag.top = dag_offset(346 libtrace->input.fd,347 &( libtrace->dag.bottom),419 DAG.bottom = DAG.top; 420 DAG.top = dag_offset( 421 INPUT.fd, 422 &(DAG.bottom), 348 423 0); 349 libtrace->dag.diff = libtrace->dag.top -350 libtrace->dag.bottom;351 352 numbytes= libtrace->dag.diff;353 libtrace->dag.offset = 0;424 DAG.diff = DAG.top - 425 DAG.bottom; 426 427 numbytes=DAG.diff; 428 DAG.offset = 0; 354 429 return numbytes; 355 430 } … … 403 478 int rlen; 404 479 405 if ((numbytes=gzread( libtrace->input.file,480 if ((numbytes=gzread(INPUT.file, 406 481 buffer, 407 482 dag_record_size)) == -1) { … … 418 493 419 494 // read in the rest of the packet 420 if ((numbytes=gzread( libtrace->input.file,495 if ((numbytes=gzread(INPUT.file, 421 496 buffer2, 422 497 size)) == -1) { … … 440 515 # define MSG_NOSIGNAL 0 441 516 #endif 442 if ((numbytes = recv( libtrace->input.fd,517 if ((numbytes = recv(INPUT.fd, 443 518 buffer, 444 519 len, … … 471 546 if (fifo_out_available(libtrace->fifo) == 0 || read_required) { 472 547 if ((numbytes = rtclient_read( 473 548 libtrace,buf,RP_BUFSIZE))<=0) { 474 549 return numbytes; 475 550 } … … 516 591 int numbytes = 0; 517 592 518 if ((numbytes = gzwrite(libtrace-> output.file, packet->buffer, packet->size)) == 0) {593 if ((numbytes = gzwrite(libtrace->format_data->output.file, packet->buffer, packet->size)) == 0) { 519 594 perror("gzwrite"); 520 595 return -1; … … 532 607 533 608 do { 534 if (rtserver_checklisten(libtrace-> output.rtserver) < 0)609 if (rtserver_checklisten(libtrace->format_data->output.rtserver) < 0) 535 610 return -1; 536 611 … … 564 639 memcpy(buf, &packet->status, intsize); 565 640 566 if ((numbytes = rtserver_sendclients(libtrace-> output.rtserver, buf, size + sizeof(int))) < 0) {641 if ((numbytes = rtserver_sendclients(libtrace->format_data->output.rtserver, buf, size + sizeof(int))) < 0) { 567 642 write_required = 0; 568 643 continue; … … 591 666 dag_record_t *erfptr = 0; 592 667 erfptr = (dag_record_t *)packet->buffer; 668 printf("%d\n",erfptr->type); 593 669 switch (erfptr->type) { 594 670 case TYPE_ETH: return TRACE_TYPE_ETH; … … 690 766 691 767 692 static struct format_t erf = {768 static struct libtrace_format_t erf = { 693 769 "erf", 694 770 "$Id$", … … 715 791 716 792 #ifdef HAVE_DAG 717 static struct format_t dag = {793 static struct libtrace_format_t dag = { 718 794 "dag", 719 795 "$Id$", … … 740 816 #endif 741 817 742 static struct format_t rtclient = {818 static struct libtrace_format_t rtclient = { 743 819 "rtclient", 744 820 "$Id$", -
lib/format_pcap.c
r7d69878 r9e2a109 32 32 #include "config.h" 33 33 #include "libtrace.h" 34 #include " format.h"34 #include "libtrace_int.h" 35 35 #include <inttypes.h> 36 36 #include <sys/types.h> … … 57 57 #if HAVE_PCAP 58 58 59 struct libtrace_format_data_t { 60 union { 61 char *path; /**< information for local sockets */ 62 char *interface; /**< intormation for reading of network 63 interfaces */ 64 } conn_info; 65 /** Information about the current state of the input device */ 66 union { 67 int fd; 68 FILE *file; 69 pcap_t *pcap; 70 } input; 71 }; 72 59 73 static int pcap_init_input(struct libtrace_t *libtrace) { 60 74 char errbuf[PCAP_ERRBUF_SIZE]; 61 75 struct stat buf; 62 if (!strncmp(libtrace->conn_info.path,"-",1)) { 63 if ((libtrace->input.pcap = 64 pcap_open_offline(libtrace->conn_info.path, 76 libtrace->format_data = (struct libtrace_format_data_t *) 77 malloc(sizeof(struct libtrace_format_data_t)); 78 libtrace->format_data->conn_info.path = libtrace->uridata; 79 if (!strncmp(libtrace->format_data->conn_info.path,"-",1)) { 80 if ((libtrace->format_data->input.pcap = 81 pcap_open_offline(libtrace->format_data->conn_info.path, 65 82 errbuf)) == NULL) { 66 83 fprintf(stderr,"%s\n",errbuf); … … 68 85 } 69 86 } else { 70 if (stat(libtrace-> conn_info.path,&buf) == -1) {87 if (stat(libtrace->format_data->conn_info.path,&buf) == -1) { 71 88 perror("stat"); 72 89 return 0; 73 90 } 74 91 if (S_ISCHR(buf.st_mode)) { 75 if ((libtrace-> input.pcap =76 pcap_open_live(libtrace-> conn_info.path,92 if ((libtrace->format_data->input.pcap = 93 pcap_open_live(libtrace->format_data->conn_info.path, 77 94 4096, 78 95 1, … … 83 100 } 84 101 } else { 85 if ((libtrace-> input.pcap =86 pcap_open_offline(libtrace-> conn_info.path,102 if ((libtrace->format_data->input.pcap = 103 pcap_open_offline(libtrace->format_data->conn_info.path, 87 104 errbuf)) == NULL) { 88 105 fprintf(stderr,"%s\n",errbuf); … … 93 110 fprintf(stderr, 94 111 "Unsupported scheme (%s) for format pcap\n", 95 libtrace-> conn_info.path);112 libtrace->format_data->conn_info.path); 96 113 return 0; 97 114 … … 100 117 static int pcapint_init_input(struct libtrace_t *libtrace) { 101 118 char errbuf[PCAP_ERRBUF_SIZE]; 102 if ((libtrace-> input.pcap =103 pcap_open_live(libtrace-> conn_info.path,119 if ((libtrace->format_data->input.pcap = 120 pcap_open_live(libtrace->format_data->conn_info.path, 104 121 4096, 105 122 1, … … 132 149 int pcapbytes = 0; 133 150 134 while ((pcapbytes = pcap_dispatch(libtrace-> input.pcap,151 while ((pcapbytes = pcap_dispatch(libtrace->format_data->input.pcap, 135 152 1, /* number of packets */ 136 153 &trace_pcap_handler, … … 151 168 int linktype = 0; 152 169 pcapptr = (struct pcap_pkthdr *)packet->buffer; 153 linktype = pcap_datalink(packet->trace-> input.pcap);170 linktype = pcap_datalink(packet->trace->format_data->input.pcap); 154 171 switch(linktype) { 155 172 case DLT_NULL: … … 280 297 printf("\n"); 281 298 } 282 static struct format_t pcap = { 299 300 301 static struct libtrace_format_t pcap = { 283 302 "pcap", 284 303 "$Id$", … … 304 323 }; 305 324 306 static struct format_t pcapint = {325 static struct libtrace_format_t pcapint = { 307 326 "pcapint", 308 327 "$Id$", -
lib/format_template.c
rdd22d84 r9e2a109 30 30 31 31 #include "libtrace.h" 32 #include " format.h"32 #include "libtrace_int.h" 33 33 #include <inttypes.h> 34 34 35 struct libtrace_format_data_t { 36 int fd; 37 }; 35 38 static int template_init_input(struct libtrace_t *libtrace) { 39 libtrace->format_data = (struct libtrace_format_data_t *) 40 malloc(sizeof(struct libtrace_format_data_t)); 36 41 return -1; 37 42 } … … 108 113 return; 109 114 } 110 static struct format_t template = {115 static struct libtrace_format_t template = { 111 116 "template", 112 117 "$Id$", -
lib/format_wag.c
rfe43699 r9e2a109 30 30 31 31 #include "libtrace.h" 32 #include " format.h"32 #include "libtrace_int.h" 33 33 #include "wag.h" 34 34 … … 58 58 #define O_LARGEFILE 0 59 59 #endif 60 61 struct libtrace_format_data_t { 62 union { 63 /** Information about rtclients */ 64 struct { 65 char *hostname; 66 short port; 67 } rt; 68 char *path; /**< information for local sockets */ 69 } conn_info; 70 /** Information about the current state of the input device */ 71 union { 72 int fd; 73 #if HAVE_ZLIB 74 gzFile *file; 75 #else 76 FILE *file; 77 #endif 78 } input; 79 }; 80 60 81 static int wag_init_input(struct libtrace_t *libtrace) { 61 82 struct stat buf; … … 63 84 struct sockaddr_in remote; 64 85 struct sockaddr_un unix_sock; 65 if (!strncmp(libtrace->conn_info.path,"-",1)) { 86 libtrace->format_data = (struct libtrace_format_data_t *) 87 calloc(1,sizeof(struct libtrace_format_data_t)); 88 libtrace->format_data->conn_info.path = libtrace->uridata; 89 if (!strncmp(libtrace->format_data->conn_info.path,"-",1)) { 66 90 // STDIN 67 91 #if HAVE_ZLIB 68 libtrace-> input.file = gzdopen(STDIN, "r");92 libtrace->format_data->input.file = gzdopen(STDIN, "r"); 69 93 #else 70 libtrace-> input.file = stdin;94 libtrace->format_data->input.file = stdin; 71 95 #endif 72 96 73 97 } else { 74 if (stat(libtrace-> conn_info.path,&buf) == -1 ) {98 if (stat(libtrace->format_data->conn_info.path,&buf) == -1 ) { 75 99 perror("stat"); 76 100 return 0; … … 78 102 if (S_ISSOCK(buf.st_mode)) { 79 103 // SOCKET 80 if ((libtrace-> input.fd = socket(104 if ((libtrace->format_data->input.fd = socket( 81 105 AF_UNIX, SOCK_STREAM, 0)) == -1) { 82 106 perror("socket"); … … 87 111 snprintf(unix_sock.sun_path, 88 112 108,"%s" 89 ,libtrace-> conn_info.path);90 91 if (connect(libtrace-> input.fd,113 ,libtrace->format_data->conn_info.path); 114 115 if (connect(libtrace->format_data->input.fd, 92 116 (struct sockaddr *)&unix_sock, 93 117 sizeof(struct sockaddr)) == -1) { … … 101 125 // ourselves. However, this way is messy and 102 126 // we lose any error checking on "open" 103 libtrace-> input.file =127 libtrace->format_data->input.file = 104 128 gzdopen(open( 105 libtrace-> conn_info.path,129 libtrace->format_data->conn_info.path, 106 130 O_LARGEFILE), "r"); 107 131 #else 108 libtrace-> input.file =132 libtrace->format_data->input.file = 109 133 fdopen(open( 110 libtrace-> conn_info.path,134 libtrace->format_data->conn_info.path, 111 135 O_LARGEFILE), "r"); 112 136 #endif … … 118 142 static int wag_fin_input(struct libtrace_t *libtrace) { 119 143 #if HAVE_ZLIB 120 gzclose(libtrace-> input.file);144 gzclose(libtrace->format_data->input.file); 121 145 #else 122 fclose(libtrace-> input.file);146 fclose(libtrace->format_data->input.file); 123 147 #endif 124 148 } … … 137 161 switch(libtrace->sourcetype) { 138 162 case DEVICE: 139 if ((numbytes=read(libtrace-> input.fd,163 if ((numbytes=read(libtrace->format_data->input.fd, 140 164 buffer, 141 165 len)) == -1) { … … 146 170 default: 147 171 #if HAVE_ZLIB 148 if ((numbytes=gzread(libtrace-> input.file,172 if ((numbytes=gzread(libtrace->format_data->input.file, 149 173 buffer, 150 174 len)) == -1) { … … 154 178 #else 155 179 if ((numbytes=fread(buffer,len,1, 156 libtrace-> input.file)) == 0 ) {157 if(feof(libtrace-> input.file)) {180 libtrace->format_data->input.file)) == 0 ) { 181 if(feof(libtrace->format_data->input.file)) { 158 182 return 0; 159 183 } 160 if(ferror(libtrace-> input.file)) {184 if(ferror(libtrace->format_data->input.file)) { 161 185 perror("fread"); 162 186 return -1; … … 283 307 } 284 308 285 static struct format_t wag = {309 static struct libtrace_format_t wag = { 286 310 "wag", 287 311 "$Id$", -
lib/libtrace_int.h
rdd22d84 r9e2a109 29 29 */ 30 30 31 #ifndef FORMAT_H32 #define FORMAT_H31 #ifndef LIBTRACE_INT_H 32 #define LIBTRACE_INT_H 33 33 34 34 #ifdef __cplusplus … … 75 75 #define RP_BUFSIZE 65536 76 76 77 /** The information about traces that are open 78 * @internal 79 */ 80 struct libtrace_t { 81 struct format_t *format; /**< format driver pointer */ 82 source_t sourcetype; /**< The type (device,file, etc */ 77 struct libtrace_format_data_t; 83 78 84 union { 85 /** Information about rtclients */ 86 struct { 87 char *hostname; 88 short port; 89 } rt; 90 char *path; /**< information for local sockets */ 91 char *interface; /**< intormation for reading of network 92 interfaces */ 93 } conn_info; 94 /** Information about the current state of the input device */ 95 union { 96 int fd; 97 #if HAVE_ZLIB 98 gzFile *file; 99 #else 100 FILE *file; 101 #endif 102 #if HAVE_PCAP 103 pcap_t *pcap; 104 #endif 105 } input; 106 107 struct fifo_t *fifo; 108 struct { 109 void *buf; 110 unsigned bottom; 111 unsigned top; 112 unsigned diff; 113 unsigned curr; 114 unsigned offset; 115 } dag; 79 struct libtrace_event_t { 116 80 struct { 117 81 void *buffer; … … 127 91 }; 128 92 93 /** The information about traces that are open 94 * @internal 95 */ 96 struct libtrace_t { 97 struct libtrace_format_t *format; /**< format driver pointer */ 98 struct libtrace_format_data_t *format_data; /**<format data pointer */ 99 source_t sourcetype; /**< The type (device,file, etc */ 100 101 struct libtrace_event_t event; 102 char *uridata; 103 struct fifo_t *fifo; 104 105 }; 106 129 107 struct libtrace_out_t { 130 struct format_t * format; 108 struct libtrace_format_t *format; 109 struct libtrace_format_data_out_t *format_data; 131 110 132 111 char *uridata; 133 union {134 struct {135 char *hostname;136 short port;137 } rt;138 char *path;139 char *interface;140 } conn_info;141 142 union {143 struct {144 int level;145 } erf;146 147 } options;148 149 union {150 int fd;151 struct rtserver_t * rtserver;152 #if HAVE_ZLIB153 gzFile *file;154 #else155 FILE *file;156 #endif157 #if HAVE_PCAP158 pcap_t *pcap;159 #endif160 } output;161 162 112 struct fifo_t *fifo; 163 164 165 113 }; 166 114 … … 195 143 }; 196 144 197 struct format_t {145 struct libtrace_format_t { 198 146 char *name; 199 147 char *version; … … 219 167 }; 220 168 221 extern struct format_t *form;169 extern struct libtrace_format_t *form; 222 170 223 void register_format(struct format_t *format);171 void register_format(struct libtrace_format_t *format); 224 172 225 173 #ifdef __cplusplus … … 227 175 #endif 228 176 229 #endif // FORMAT_H177 #endif // LIBTRACE_INT_H -
lib/trace.c
rfe43699 r9e2a109 102 102 #include "libtrace.h" 103 103 #include "fifo.h" 104 #include " format.h"104 #include "libtrace_int.h" 105 105 #include "parse_cmd.h" 106 106 … … 134 134 #endif 135 135 136 #include " format.h"136 #include "libtrace_int.h" 137 137 //#include "format/format_list.h" 138 138 #include <err.h> … … 157 157 #endif 158 158 159 struct format_t **format_list = 0;159 struct libtrace_format_t **format_list = 0; 160 160 int format_size = 0; 161 161 int nformats = 0; 162 162 163 void register_format(struct format_t *f) {163 void register_format(struct libtrace_format_t *f) { 164 164 fprintf(stderr,"Registering input format %s\n",f->name); 165 165 if (format_list == 0) { 166 166 format_size = 10; 167 format_list = malloc(sizeof(struct format_t *) * format_size);167 format_list = malloc(sizeof(struct libtrace_format_t *) * format_size); 168 168 } else if (format_size == nformats) { 169 169 format_size = format_size + 10; 170 170 format_list = realloc(format_list, 171 sizeof(struct format_t *) * format_size);171 sizeof(struct libtrace_format_t *) * format_size); 172 172 } 173 173 format_list[nformats] = f; … … 192 192 193 193 #define RP_BUFSIZE 65536 194 195 194 #define URI_PROTO_LINE 16 196 static int init_trace(struct libtrace_t **libtrace, char *uri) {197 char *scan = calloc(sizeof(char),URI_PROTO_LINE);198 char *uridata = 0;199 int i = 0;200 struct stat buf;201 202 // parse the URI to determine what sort of event we are dealing with203 204 // want snippet before the : to get the uri base type.205 206 if((uridata = strchr(uri,':')) == NULL) {207 // badly formed URI - needs a :208 return 0;209 }210 211 if ((*uridata - *uri) > URI_PROTO_LINE) {212 // badly formed URI - uri type is too long213 return 0;214 }215 strncpy(scan,uri, (uridata - uri));216 217 (*libtrace)->tdelta = 0.0;218 219 220 (*libtrace)->format = 0;221 for (i = 0; i < nformats; i++) {222 if (strlen(scan) == strlen(format_list[i]->name) &&223 !strncasecmp(scan,224 format_list[i]->name,225 strlen(scan))) {226 (*libtrace)->format=format_list[i];227 break;228 }229 }230 if ((*libtrace)->format == 0) {231 fprintf(stderr,232 "libtrace has no support for this format (%s)\n",scan);233 return 0;234 }235 236 // push uridata past the delimiter237 uridata++;238 (*libtrace)->conn_info.path = strdup(uridata);239 240 // libtrace->format now contains the type of uri241 // libtrace->uridata contains the appropriate data for this242 243 if ((*libtrace)->format->init_input) {244 (*libtrace)->format->init_input( (*libtrace));245 } else {246 fprintf(stderr,247 "No init function for format %s\n",scan);248 return 0;249 }250 251 252 (*libtrace)->fifo = create_fifo(1048576);253 assert( (*libtrace)->fifo);254 //(*libtrace)->packet.buffer = 0;255 //(*libtrace)->packet.size = 0;256 257 return 1;258 }259 195 260 196 /** Initialises the data contained within the libtrace_out_t structure, based on the provided uri. … … 354 290 struct libtrace_t *trace_create(char *uri) { 355 291 struct libtrace_t *libtrace = malloc(sizeof(struct libtrace_t)); 356 357 if(init_trace(&libtrace,uri) == 0) { 292 char *scan = calloc(sizeof(char),URI_PROTO_LINE); 293 char *uridata = 0; 294 int i = 0; 295 struct stat buf; 296 297 // parse the URI to determine what sort of event we are dealing with 298 299 // want snippet before the : to get the uri base type. 300 301 if((uridata = strchr(uri,':')) == NULL) { 302 // badly formed URI - needs a : 358 303 return 0; 359 304 } 360 305 306 if ((*uridata - *uri) > URI_PROTO_LINE) { 307 // badly formed URI - uri type is too long 308 return 0; 309 } 310 strncpy(scan,uri, (uridata - uri)); 311 312 libtrace->event.tdelta = 0.0; 313 314 315 libtrace->format = 0; 316 for (i = 0; i < nformats; i++) { 317 if (strlen(scan) == strlen(format_list[i]->name) && 318 !strncasecmp(scan, 319 format_list[i]->name, 320 strlen(scan))) { 321 libtrace->format=format_list[i]; 322 break; 323 } 324 } 325 if (libtrace->format == 0) { 326 fprintf(stderr, 327 "libtrace has no support for this format (%s)\n",scan); 328 return 0; 329 } 330 331 // push uridata past the delimiter 332 uridata++; 333 libtrace->uridata = strdup(uridata); 334 335 // libtrace->format now contains the type of uri 336 // libtrace->uridata contains the appropriate data for this 337 338 if (libtrace->format->init_input) { 339 libtrace->format->init_input( libtrace); 340 } else { 341 fprintf(stderr, 342 "No init function for format %s\n",scan); 343 return 0; 344 } 345 346 347 libtrace->fifo = create_fifo(1048576); 348 assert( libtrace->fifo); 349 361 350 return libtrace; 362 351 } … … 958 947 { 959 948 int data; 960 event.fd = pcap_fileno(trace->input.pcap); 949 // XXX FIXME 950 //event.fd = pcap_fileno(trace->input.pcap); 961 951 if(ioctl(event.fd,FIONREAD,&data)==-1){ 962 952 perror("ioctl(FIONREAD)"); … … 976 966 { 977 967 int data; 978 event.fd = trace->input.fd; 968 // XXX FIXME 969 //event.fd = trace->input.fd; 979 970 if(ioctl(event.fd,FIONREAD,&data)==-1){ 980 971 perror("ioctl(FIONREAD)"); … … 995 986 struct timeval stv; 996 987 /* "Prime" the pump */ 997 if (!trace-> packet.buffer) {998 trace-> packet.buffer = malloc(4096);999 trace-> packet.size=988 if (!trace->event.packet.buffer) { 989 trace->event.packet.buffer = malloc(4096); 990 trace->event.packet.size= 1000 991 trace_read_packet(trace,packet); 1001 event.size = trace-> packet.size;1002 if (trace-> packet.size > 0 ) {1003 memcpy(trace-> packet.buffer,packet->buffer,trace->packet.size);992 event.size = trace->event.packet.size; 993 if (trace->event.packet.size > 0 ) { 994 memcpy(trace->event.packet.buffer,packet->buffer,trace->event.packet.size); 1004 995 } else { 1005 996 // return here, the test for event.size will sort out the error … … 1010 1001 1011 1002 ts=trace_get_seconds(packet); 1012 if (trace-> tdelta!=0) {1003 if (trace->event.tdelta!=0) { 1013 1004 // Get the adjusted current time 1014 1005 gettimeofday(&stv, NULL); 1015 1006 now = stv.tv_sec + ((double)stv.tv_usec / 1000000.0); 1016 now -= trace-> tdelta; // adjust for trace delta1007 now -= trace->event.tdelta; // adjust for trace delta 1017 1008 1018 1009 … … 1020 1011 // return a SLEEP event, otherwise fire the packet 1021 1012 if (ts > now) { 1022 event.seconds = ts - trace-> trace_last_ts;1013 event.seconds = ts - trace->event.trace_last_ts; 1023 1014 event.type = TRACE_EVENT_SLEEP; 1024 1015 return event; … … 1028 1019 // work out the difference between the start of trace replay, 1029 1020 // and the first packet in the trace 1030 trace-> tdelta = stv.tv_sec + ((double)stv.tv_usec / 1000000.0);1031 trace-> tdelta -= ts;1021 trace->event.tdelta = stv.tv_sec + ((double)stv.tv_usec / 1000000.0); 1022 trace->event.tdelta -= ts; 1032 1023 1033 1024 } 1034 1025 1035 1026 // This is the first packet, so just fire away. 1036 packet->size = trace-> packet.size;1037 memcpy(packet->buffer,trace-> packet.buffer,trace->packet.size);1038 1039 free(trace-> packet.buffer);1040 trace-> packet.buffer = 0;1027 packet->size = trace->event.packet.size; 1028 memcpy(packet->buffer,trace->event.packet.buffer,trace->event.packet.size); 1029 1030 free(trace->event.packet.buffer); 1031 trace->event.packet.buffer = 0; 1041 1032 event.type = TRACE_EVENT_PACKET; 1042 1033 1043 trace-> trace_last_ts = ts;1034 trace->event.trace_last_ts = ts; 1044 1035 1045 1036 return event;
Note: See TracChangeset
for help on using the changeset viewer.