Changeset 91ebc50 for lib/trace.c
- Timestamp:
- 08/03/05 14:24:59 (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:
- 283acce
- Parents:
- 1f2220f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.