Changeset 538
- Timestamp:
- 12/09/05 11:03:51 (7 years ago)
- File:
-
- 1 edited
-
branches/libtrace-2_0_25/lib/format_wag.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/libtrace-2_0_25/lib/format_wag.c
r536 r538 77 77 78 78 static struct libtrace_format_t wag; 79 static struct libtrace_format_t wag_trace; 79 80 80 81 #define CONNINFO libtrace->format_data->conn_info … … 126 127 static int wag_init_input(struct libtrace_t *libtrace) { 127 128 struct stat buf; 128 struct sockaddr_un unix_sock;129 //struct sockaddr_un unix_sock; 129 130 libtrace->format_data = (struct libtrace_format_data_t *) 130 131 calloc(1,sizeof(struct libtrace_format_data_t)); 131 132 CONNINFO.path = libtrace->uridata; 133 134 if (stat(CONNINFO.path,&buf) == -1 ) { 135 perror("stat"); 136 return 0; 137 } 138 if (S_ISCHR(buf.st_mode)) { 139 libtrace->sourcetype = DEVICE; 140 141 INPUT.fd = open(CONNINFO.path, O_RDONLY); 142 143 } else { 144 fprintf(stderr, "%s is not a valid char device, exiting\n", 145 CONNINFO.path); 146 return 0; 147 148 } 149 return 1; 150 } 151 152 static int wtf_init_input(struct libtrace_t *libtrace) { 153 struct stat buf; 154 struct sockaddr_un unix_sock; 155 156 libtrace->format_data = (struct libtrace_format_data_t *) 157 calloc(1,sizeof(struct libtrace_format_data_t)); 158 CONNINFO.path = libtrace->uridata; 159 132 160 if (!strncmp(CONNINFO.path,"-",1)) { 133 161 // STDIN … … 136 164 137 165 } 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 171 172 /* 138 173 if (stat(CONNINFO.path,&buf) == -1 ) { 139 174 perror("stat"); … … 161 196 } 162 197 } else { 198 */ 163 199 // TRACE 164 200 libtrace->sourcetype = TRACE; … … 172 208 O_LARGEFILE), "r"); 173 209 174 }210 //} 175 211 } 176 212 return 1; 177 213 } 178 214 179 static int wag_init_output(struct libtrace_out_t *libtrace) { 215 216 static int wtf_init_output(struct libtrace_out_t *libtrace) { 180 217 char *filemode = 0; 181 218 libtrace->format_data = (struct libtrace_format_data_out_t *) … … 192 229 libtrace->uridata, 193 230 O_CREAT | O_LARGEFILE | O_WRONLY, 194 S_IRUSR | S_IWUSR ), filemode);231 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP), filemode); 195 232 } 196 233 … … 198 235 } 199 236 200 static int w ag_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) {237 static int wtf_config_output(struct libtrace_out_t *libtrace, int argc, char *argv[]) { 201 238 #if HAVE_ZLIB 202 239 int opt; … … 227 264 228 265 static int wag_fin_input(struct libtrace_t *libtrace) { 266 close(INPUT.fd); 267 return 0; 268 } 269 270 static int wtf_fin_input(struct libtrace_t *libtrace) { 229 271 LIBTRACE_CLOSE(INPUT.file); 230 272 return 0; 231 273 } 232 274 233 static int w ag_fin_output(struct libtrace_out_t *libtrace) {275 static int wtf_fin_output(struct libtrace_out_t *libtrace) { 234 276 LIBTRACE_CLOSE(OUTPUT.file); 235 277 return 0; … … 238 280 static int wag_read(struct libtrace_t *libtrace, void *buffer, size_t len) { 239 281 int numbytes; 282 int framesize; 240 283 assert(libtrace); 241 284 … … 243 286 buffer = malloc(len); 244 287 245 while(1) { 246 switch(libtrace->sourcetype) { 247 case DEVICE: 248 if ((numbytes=read(INPUT.fd, 249 buffer, 250 len)) == -1) { 251 perror("read"); 252 return -1; 253 } 254 break; 255 default: 256 if ((numbytes=LIBTRACE_READ(INPUT.file, 257 buffer, 258 len)) == -1) { 259 perror("libtrace_read"); 260 return -1; 261 } 262 } 263 break; 264 } 265 return numbytes; 266 288 // read in wag_frame_hdr 289 if ((numbytes = read(INPUT.fd, 290 buffer, 291 sizeof(struct wag_frame_hdr))) != sizeof(struct wag_frame_hdr)) { 292 return -1; 293 } 294 295 framesize = ntohs(((struct wag_frame_hdr *)buffer)->size); 296 297 if (framesize > len) { 298 return -1; 299 } 300 301 // read in remainder of packet 302 if((numbytes = read(INPUT.fd, 303 buffer + sizeof(struct wag_frame_hdr), 304 framesize - sizeof(struct wag_frame_hdr))) != 305 (framesize - sizeof(struct wag_frame_hdr))) { 306 307 return -1; 308 309 } 310 311 return framesize; 267 312 } 268 313 … … 270 315 static int wag_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 271 316 int numbytes; 317 318 char buf[RP_BUFSIZE]; 319 320 321 packet->trace = libtrace; 322 323 if ((numbytes = wag_read(libtrace, buf, RP_BUFSIZE)) <= 0) { 324 325 return numbytes; 326 } 327 328 memcpy(packet->buffer, buf, numbytes); 329 330 packet->status.type = RT_DATA; 331 packet->status.message = 0; 332 packet->size = numbytes; 333 return numbytes; 334 } 335 336 static int wtf_read_packet(struct libtrace_t *libtrace, struct libtrace_packet_t *packet) { 337 int numbytes; 338 void *buffer = packet->buffer; 339 void *buffer2 = packet->buffer; 340 int framesize; 272 341 int size; 273 char buf[RP_BUFSIZE]; 274 int read_required = 0; 275 276 void *buffer = 0; 277 278 packet->trace = libtrace; 279 buffer = packet->buffer; 280 281 282 do { 283 if (tracefifo_out_available(libtrace->fifo) == 0 || read_required) { 284 if ((numbytes = wag_read(libtrace,buf,RP_BUFSIZE)) <= 0) { 285 return numbytes; 286 } 287 assert(libtrace->fifo); 288 tracefifo_write(libtrace->fifo,buf,numbytes); 289 read_required = 0; 290 } 291 // read in wag_frame_hdr 292 if ((numbytes = tracefifo_out_read(libtrace->fifo, 293 buffer, 294 sizeof(struct wag_frame_hdr))) 295 == 0 ) { 296 tracefifo_out_reset(libtrace->fifo); 297 read_required = 1; 298 continue; 299 } 300 301 size = ntohs(((struct wag_frame_hdr *)buffer)->size); 302 303 // wag isn't in network byte order yet 304 //size = htons(size); 305 //printf("%d %d\n",size,htons(size)); 306 307 // read in full packet 308 if((numbytes = tracefifo_out_read(libtrace->fifo,buffer,size)) == 0) { 309 tracefifo_out_reset(libtrace->fifo); 310 read_required = 1; 311 continue; 312 } 313 314 // have the whole packet 315 tracefifo_out_update(libtrace->fifo,size); 316 tracefifo_ack_update(libtrace->fifo,size); 317 318 packet->status.type = RT_DATA; 319 packet->status.message = 0; 320 packet->size = numbytes; 321 return numbytes; 322 } while(1); 323 } 324 325 static int wag_write_packet(struct libtrace_out_t *libtrace, const struct libtrace_packet_t *packet) { 342 343 if ((numbytes = LIBTRACE_READ(INPUT.file, buffer, sizeof(struct wag_frame_hdr))) == -1) { 344 perror("libtrace_read"); 345 return -1; 346 } 347 348 if (numbytes == 0) { 349 return 0; 350 } 351 352 framesize = ntohs(((struct wag_frame_hdr *)buffer)->size); 353 buffer2 = buffer + sizeof(struct wag_frame_hdr); 354 size = framesize - sizeof(struct wag_frame_hdr); 355 assert(size < LIBTRACE_PACKET_BUFSIZE); 356 357 358 if ((numbytes=LIBTRACE_READ(INPUT.file, buffer2, size)) != size) { 359 perror("libtrace read"); 360 return -1; 361 } 362 363 packet->status.type = RT_DATA; 364 packet->status.message = 0; 365 packet->size = framesize; 366 return framesize; 367 368 } 369 370 static int wtf_write_packet(struct libtrace_out_t *libtrace, const struct libtrace_packet_t *packet) { 326 371 int numbytes =0 ; 327 if (packet->trace->format != &wag ) {328 fprintf(stderr,"Cannot convert from wag t o %s format yet\n",372 if (packet->trace->format != &wag_trace) { 373 fprintf(stderr,"Cannot convert from wag trace format to %s format yet\n", 329 374 packet->trace->format->name); 330 375 return -1; … … 358 403 struct wag_data_frame *wagptr = (struct wag_data_frame *)packet->buffer; 359 404 uint64_t timestamp = 0; 360 timestamp = (((uint64_t)wagptr->ts.secs) << 32) + wagptr->ts.subsecs; 361 //timestamp |= (uint64_t)wagptr->ts.secs<<32; 362 //timestamp = ((timestamp%44000000)*(UINT_MAX/44000000)) 363 // | ((timestamp/44000000)<<32); 405 timestamp = ((uint64_t)(ntohl(wagptr->ts.secs)) << 32) | (uint64_t)(ntohl(wagptr->ts.subsecs)); 364 406 return timestamp; 365 407 } … … 397 439 printf("Supported input URIs:\n"); 398 440 printf("\twag:/dev/wagn\n"); 399 printf("\twag:/path/to/trace.wag\n");400 printf("\twag:/path/to/trace.wag.gz\n");401 441 printf("\n"); 402 442 printf("\te.g.: wag:/dev/wag0\n"); 403 printf("\te.g.: wag:/tmp/trace.wag.gz\n");404 443 printf("\n"); 405 444 printf("Supported output URIs:\n"); 406 printf("\tnone\n"); 445 printf("\tNone\n"); 446 printf("\n"); 447 } 448 449 static void wtf_help() { 450 printf("wag trace format module: $Revision$\n"); 451 printf("Supported input URIs:\n"); 452 printf("\twtf:/path/to/trace.wag\n"); 453 printf("\twtf:/path/to/trace.wag.gz\n"); 454 printf("\n"); 455 printf("\te.g.: wtf:/tmp/trace.wag.gz\n"); 456 printf("\n"); 457 printf("Supported output URIs:\n"); 458 printf("\twtf:/path/to/trace.wag\n"); 459 printf("\twtf:/path/to/trace.wag.gz\n"); 460 printf("\n"); 461 printf("\te.g.: wtf:/tmp/trace.wag.gz\n"); 407 462 printf("\n"); 408 463 } … … 411 466 "wag", 412 467 "$Id$", 413 "w ag",468 "wtf", 414 469 wag_init_input, /* init_input */ 415 wag_init_output,/* init_output */416 wag_config_output,/* config_output */470 NULL, /* init_output */ 471 NULL, /* config_output */ 417 472 wag_fin_input, /* fin_input */ 418 wag_fin_output,/* fin_output */473 NULL, /* fin_output */ 419 474 wag_read_packet, /* read_packet */ 420 wag_write_packet,/* write_packet */475 NULL, /* write_packet */ 421 476 wag_get_link, /* get_link */ 422 477 wag_get_link_type, /* get_link_type */ … … 435 490 }; 436 491 492 /* wtf stands for Wag Trace Format */ 493 494 static struct libtrace_format_t wag_trace = { 495 "wtf", 496 "$Id$", 497 "wtf", 498 wtf_init_input, /* init_input */ 499 wtf_init_output, /* init_output */ 500 wtf_config_output, /* config_output */ 501 wtf_fin_input, /* fin_input */ 502 wtf_fin_output, /* fin_output */ 503 wtf_read_packet, /* read_packet */ 504 wtf_write_packet, /* write_packet */ 505 wag_get_link, /* get_link */ 506 wag_get_link_type, /* get_link_type */ 507 wag_get_direction, /* get_direction */ 508 NULL, /* set_direction */ 509 wag_get_erf_timestamp, /* get_erf_timestamp */ 510 NULL, /* get_timeval */ 511 NULL, /* get_seconds */ 512 wag_get_capture_length, /* get_capture_length */ 513 wag_get_wire_length, /* get_wire_length */ 514 wag_get_framing_length, /* get_framing_length */ 515 NULL, /* set_capture_length */ 516 wag_get_fd, /* get_fd */ 517 wag_event_trace, /* trace_event */ 518 wtf_help /* help */ 519 }; 520 521 437 522 void __attribute__((constructor)) wag_constructor() { 438 523 register_format(&wag); 439 } 524 register_format(&wag_trace); 525 }
Note: See TracChangeset
for help on using the changeset viewer.
