- Timestamp:
- 08/03/05 14:24:59 (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:
- 283acce
- Parents:
- 1f2220f
- Location:
- lib
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile.am
r9a36e6d r91ebc50 1 1 lib_LTLIBRARIES = libtrace.la 2 2 include_HEADERS = libtrace.h dagformat.h wag.h 3 libtrace_la_SOURCES = trace.c fifo.c fifo.h common.h format_template.c format_erf.c format_pcap.c format_wag.c rtserver.c rtserver.h 3 libtrace_la_SOURCES = trace.c fifo.c fifo.h common.h format_template.c format_erf.c format_pcap.c format_wag.c rtserver.c rtserver.h parse_cmd.c parse_cmd.h 4 4 libtrace_la_CFLAGS = @ADD_INCLS@ 5 5 libtrace_la_LIBADD = @ADD_LIBS@ @LTLIBOBJS@ -
lib/format.h
r1fc2f6a r91ebc50 130 130 struct format_t * format; 131 131 132 char *uridata; 132 133 union { 133 134 struct { … … 139 140 } conn_info; 140 141 142 union { 143 struct { 144 int level; 145 } erf; 146 147 } options; 148 141 149 union { 142 150 int fd; … … 192 200 int (*init_input)(struct libtrace_t *libtrace); 193 201 int (*init_output)(struct libtrace_out_t *libtrace); 202 int (*config_output)(struct libtrace_out_t *libtrace, int argc, char *argv[]); 194 203 int (*fin_input)(struct libtrace_t *libtrace); 195 204 int (*fin_output)(struct libtrace_out_t *libtrace); -
lib/format_erf.c
r9a36e6d r91ebc50 32 32 #include "format.h" 33 33 #include "rtserver.h" 34 #include "parse_cmd.h" 34 35 35 36 #ifdef HAVE_INTTYPES_H … … 54 55 #include <netdb.h> 55 56 #include <fcntl.h> 57 #include <getopt.h> 56 58 57 59 /* Catch undefined O_LARGEFILE on *BSD etc */ … … 199 201 200 202 static int erf_init_output(struct libtrace_out_t *libtrace) { 201 struct stat buf; 202 203 if (!strncmp(libtrace->conn_info.path,"-",1)) { 203 char *filemode = 0; 204 205 libtrace->options.erf.level = 1; 206 asprintf(&filemode,"wb%d",libtrace->options.erf.level); 207 208 if (!strncmp(libtrace->uridata,"-",1)) { 204 209 // STDOUT 205 210 #if HAVE_ZLIB 206 libtrace->output.file = gzdopen(dup(1), "w");211 libtrace->output.file = gzdopen(dup(1), filemode); 207 212 #else 208 213 libtrace->output.file = stdout; … … 216 221 // we lose any error checking on "open" 217 222 libtrace->output.file = gzdopen(open( 218 libtrace->conn_info.path, 223 libtrace->uridata, 224 O_CREAT | O_LARGEFILE | O_WRONLY, 225 S_IRUSR | S_IWUSR), filemode); 226 #else 227 libtrace->output.file = fdopen(open( 228 libtrace->uridata, 219 229 O_CREAT | O_LARGEFILE | O_WRONLY, 220 230 S_IRUSR | S_IWUSR), "w"); 221 #else 222 libtrace->output.file = fdopen(open( 223 libtrace->conn_info.path, 224 O_CREAT | O_LARGEFILE | O_WRONLY, 225 S_IRUSR | S_IWUSR), "w"); 226 #endif 227 } 231 #endif 232 } 233 228 234 229 235 } 230 236 231 237 static int rtclient_init_output(struct libtrace_out_t *libtrace) { 232 char * uridata = libtrace-> conn_info.path;238 char * uridata = libtrace->uridata; 233 239 char * scan; 234 240 // extract conn_info from uridata … … 258 264 return 0; 259 265 266 } 267 268 static int erf_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 269 int opt; 270 int level = libtrace->options.erf.level; 271 optind = 1; 272 273 while ((opt = getopt(argc, argv, "z:")) != EOF) { 274 switch (opt) { 275 case 'z': 276 level = atoi(optarg); 277 break; 278 default: 279 printf("Bad argument to erf: %s\n", opt); 280 // maybe spit out some help here 281 return -1; 282 } 283 } 284 if (level != libtrace->options.erf.level) { 285 if (level > 9 || level < 0) { 286 // retarded level choice 287 printf("Compression level must be between 0 and 9 inclusive - you selected %i \n", level); 288 289 } else { 290 libtrace->options.erf.level = level; 291 return gzsetparams(libtrace->output.file, level, Z_DEFAULT_STRATEGY); 292 } 293 } 294 return 0; 295 296 } 297 298 static int rtclient_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 299 return 0; 260 300 } 261 301 … … 534 574 535 575 fifo_out_update(libtrace->fifo, size); 536 // Need an ack to come back 537 // TODO: Obviously this is a little unfinished 538 if ("ACK_ARRIVES") { 539 fifo_ack_update(libtrace->fifo, size); 540 return numbytes; 541 } else { 542 fifo_out_reset(libtrace->fifo); 543 } 576 fifo_ack_update(libtrace->fifo, size); 544 577 } while(1); 545 578 } … … 618 651 erf_init_input, /* init_input */ 619 652 erf_init_output, /* init_output */ 653 erf_config_output, /* config_output */ 620 654 erf_fin_input, /* fin_input */ 621 655 erf_fin_output, /* fin_output */ … … 640 674 dag_init_input, /* init_input */ 641 675 NULL, /* init_output */ 676 NULL, /* config_output */ 642 677 dag_fin_input, /* fin_input */ 643 678 NULL, /* fin_output */ … … 662 697 rtclient_init_input, /* init_input */ 663 698 rtclient_init_output, /* init_output */ 699 rtclient_config_output, /* config_output */ 664 700 rtclient_fin_input, /* fin_input */ 665 701 rtclient_fin_output, /* fin_output */ -
lib/format_pcap.c
r7050c10 r91ebc50 54 54 # endif 55 55 #endif 56 57 #if HAVE_PCAP 56 58 57 59 static int pcap_init_input(struct libtrace_t *libtrace) { … … 260 262 pcap_init_input, /* init_input */ 261 263 NULL, /* init_output */ 264 NULL, /* config_output */ 262 265 pcap_fin_input, /* fin_input */ 263 266 NULL, /* fin_output */ … … 282 285 pcapint_init_input, /* init_input */ 283 286 NULL, /* init_output */ 287 NULL, /* config_output */ 284 288 pcap_fin_input, /* fin_input */ 285 289 NULL, /* fin_output */ … … 303 307 register_format(&pcapint); 304 308 } 309 310 311 #endif -
lib/format_template.c
r7050c10 r91ebc50 38 38 39 39 static int template_init_output(struct libtrace_out_t *libtrace) { 40 return -1; 41 } 42 43 static int template_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 40 44 return -1; 41 45 } … … 106 110 template_init_input, /* init_input */ 107 111 template_init_output, /* init_output */ 112 template_config_output, /* config_output */ 108 113 template_fin_input, /* fin_input */ 109 114 template_fin_output, /* fin_output */ -
lib/format_wag.c
r1f2220f r91ebc50 272 272 wag_init_input, /* init_input */ 273 273 NULL, /* init_output */ 274 NULL, /* config_output */ 274 275 wag_fin_input, /* fin_input */ 275 276 NULL, /* fin_output */ -
lib/libtrace.h
r74c7660 r91ebc50 231 231 struct libtrace_out_t *trace_output_create(char *uri); 232 232 233 int trace_output_config(struct libtrace_out_t *libtrace, char *options); 234 233 235 /** Close a trace file, freeing up any resources it may have been using 234 236 * -
lib/trace.c
r9a36e6d r91ebc50 103 103 #include "fifo.h" 104 104 #include "format.h" 105 #include "parse_cmd.h" 105 106 106 107 #if HAVE_PCAP_BPF_H … … 136 137 //#include "format/format_list.h" 137 138 #include <err.h> 139 140 #define MAXOPTS 1024 138 141 139 142 //typedef enum {SOCKET, TRACE, STDIN, DEVICE, INTERFACE, RT } source_t; … … 252 255 char *uridata = 0; 253 256 int i; 254 257 255 258 // parse the URI to determine what sort of event we are dealing with 256 259 257 260 // want snippet before the : to get the uri base type. 258 261 259 262 if((uridata = strchr(uri,':')) == NULL) { 260 263 // badly formed URI - needs a : … … 266 269 return 0; 267 270 } 268 strncpy(scan,uri, (uridata - uri)); 269 271 272 strncpy(scan,uri, (uridata - uri)); 273 270 274 (*libtrace)->format = 0; 271 275 for (i = 0; i < nformats; i++) { … … 283 287 return 0; 284 288 } 285 289 286 290 // push uridata past the delimiter 287 291 uridata++; 288 (*libtrace)->conn_info.path = strdup(uridata); 289 292 (*libtrace)->uridata = strdup(uridata); 293 294 290 295 // libtrace->format now contains the type of uri 291 296 // libtrace->uridata contains the appropriate data for this … … 299 304 } 300 305 301 306 302 307 (*libtrace)->fifo = create_fifo(1048576); 303 308 assert( (*libtrace)->fifo); … … 355 360 return 0; 356 361 357 /*358 * switch(libtrace->outputformat) {359 case RTSERVER:360 if ((he=gethostbyname(libtrace->conn_info.rt.hostname)) == NULL) {361 perror("gethostbyname");362 return 0;363 }364 if ((libtrace->output.fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {365 perror("socket");366 return 0;367 }368 // Need to set up a listening server here369 bzero((char *) &remote, sizeof(remote));370 remote.sin_family = AF_INET;371 remote.sin_addr.s_addr = INADDR_ANY;372 remote.sin_port = htons(libtrace->conn_info.rt.port);373 374 if (bind(libtrace->output.fd, (struct sockaddr *) &remote, sizeof(remote)) < 0) {375 perror("bind");376 return 0;377 }378 fprintf(stderr, "Waiting for client to connect\n");379 380 listen(libtrace->output.fd, 5);381 clilen = sizeof(client);382 if ((client_fd = accept(libtrace->output.fd, (struct sockaddr *) &client, &clilen)) < 0) {383 perror("accept");384 return 0;385 }386 libtrace->output.fd = client_fd;387 fprintf(stderr, "Client connected\n");388 break;389 390 391 case GZERF:392 #ifndef O_LARGEFILE393 # define O_LARGEFILE 0394 #endif395 396 #if HAVE_ZLIB397 // using gzdopen means we can set O_LARGEFILE398 // ourselves. However, this way is messy and399 // we lose any error checking on "open"400 libtrace->output.file = gzdopen(open(libtrace->conn_info.path, O_CREAT | O_LARGEFILE | O_WRONLY, S_IRUSR | S_IWUSR), "w");401 #else402 libtrace->output.file = fdopen(open(libtrace->conn_info.path,O_CREAT | O_LARGEFILE | O_WRONLY, S_IRUSR | S_IWUSR), "w");403 #endif404 if (!libtrace->output.file) {405 perror("gzdopen (or fdopen)");406 return 0;407 }408 break;409 default:410 fprintf(stderr, "Unrecognised output type - failure to create output instance \n");411 exit(0);412 }413 */414 362 return libtrace; 363 } 364 365 int trace_output_config(struct libtrace_out_t *libtrace, char *options) { 366 char *opt_string = 0; 367 char *opt_argv[MAXOPTS]; 368 int opt_argc = 0; 369 370 assert(libtrace); 371 372 if (!options) { 373 printf("No options specified\n"); 374 return 0; 375 } 376 377 asprintf(&opt_string, "%s %s", libtrace->format->name, options); 378 parse_cmd(opt_string, &opt_argc, opt_argv, MAXOPTS); 379 380 if (libtrace->format->config_output) 381 return libtrace->format->config_output(libtrace, opt_argc, opt_argv); 382 415 383 } 416 384
Note: See TracChangeset
for help on using the changeset viewer.