Changeset 9c4b5e3
- Timestamp:
- 03/20/06 18:29:00 (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:
- c219603
- Parents:
- 25efeac
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_erf.c
r25efeac r9c4b5e3 206 206 { 207 207 libtrace->format_data = malloc(sizeof(struct erf_format_data_t)); 208 208 209 209 INPUT.file = NULL; 210 210 … … 552 552 } 553 553 if (numbytes == 0) { 554 printf("eof\n"); 554 555 return 0; 555 556 } -
lib/format_helper.c
r0c820d3 r9c4b5e3 65 65 event.type = TRACE_EVENT_TERMINATE; 66 66 return event; 67 } 68 if (data>0) { 67 } 68 69 if (data>=0) { 69 70 event.size = trace_read_packet(trace,packet); 70 71 event.type = TRACE_EVENT_PACKET; -
lib/format_rt.c
r2ffda28 r9c4b5e3 115 115 rt_hello_t hello_opts; 116 116 uint8_t reason; 117 int oldflags; 118 117 119 118 120 if ((he=gethostbyname(RT_INFO->hostname)) == NULL) { … … 137 139 return -1; 138 140 } 141 142 143 #if 0 144 oldflags = fcntl(RT_INFO->input_fd, F_GETFL, 0); 145 if (oldflags == -1) { 146 trace_set_err(libtrace, errno, 147 "Could not get fd flags from fd %d\n", 148 RT_INFO->input_fd); 149 return -1; 150 } 151 oldflags |= O_NONBLOCK; 152 if (fcntl(RT_INFO->input_fd, F_SETFL, oldflags) == -1) { 153 trace_set_err(libtrace, errno, 154 "Could not set fd flags for fd %d\n", 155 RT_INFO->input_fd); 156 return -1; 157 } 158 #endif 159 139 160 140 161 /* We are connected, now receive message from server */ … … 146 167 return -1; 147 168 } 148 169 149 170 switch (connect_msg.type) { 150 171 case RT_DENY_CONN: … … 264 285 #define RT_BUF_SIZE 4000 265 286 266 static int rt_read(struct libtrace_t *libtrace, void **buffer, size_t len ) {287 static int rt_read(struct libtrace_t *libtrace, void **buffer, size_t len, int block) { 267 288 int numbytes; 289 int i; 290 char *buf_ptr; 268 291 269 292 assert(len <= RT_BUF_SIZE); … … 274 297 RT_INFO->buf_left = 0; 275 298 } 299 300 if (block) 301 block=0; 302 else 303 block=MSG_DONTWAIT; 276 304 277 305 … … 289 317 RT_INFO->buf_left, 290 318 RT_BUF_SIZE-RT_INFO->buf_left, 291 MSG_NOSIGNAL)) == -1) { 319 MSG_NOSIGNAL|block)) <= 0) { 320 if (numbytes == 0) { 321 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 322 "No data received"); 323 return -1; 324 } 325 292 326 if (errno == EINTR) { 293 327 /* ignore EINTR in case … … 296 330 continue; 297 331 } 332 if (errno == EAGAIN) { 333 trace_set_err(libtrace, 334 EAGAIN, 335 "EAGAIN"); 336 return -1; 337 } 338 298 339 perror("recv"); 340 trace_set_err(libtrace, TRACE_ERR_RECV_FAILED, 341 "Failed to read data into rt recv buffer"); 299 342 return -1; 300 343 } 344 /* 345 buf_ptr = RT_INFO->pkt_buffer; 346 for (i = 0; i < RT_BUF_SIZE ; i++) { 347 348 printf("%02x", (unsigned char)*buf_ptr); 349 buf_ptr ++; 350 } 351 printf("\n"); 352 */ 301 353 RT_INFO->buf_left+=numbytes; 302 354 } … … 339 391 case RT_DATA_LEGACY_POS: 340 392 printf("Sending legacy over RT is currently not supported\n"); 393 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Legacy packet cannot be sent over rt"); 341 394 return -1; 342 395 default: 343 396 printf("Unrecognised format: %d\n", packet->type); 397 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, "Unrecognised packet format"); 344 398 return -1; 345 399 } … … 400 454 else { 401 455 printf("Error sending ack\n"); 456 trace_set_err(libtrace, TRACE_ERR_BAD_PACKET, 457 "Error sending ack"); 402 458 return -1; 403 459 } … … 410 466 return 1; 411 467 } 412 413 static int rt_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 468 469 470 static int rt_read_packet_versatile(libtrace_t *libtrace, 471 libtrace_packet_t *packet,int blocking) { 414 472 rt_header_t rt_hdr; 415 473 rt_header_t *pkt_hdr = &rt_hdr; … … 422 480 } 423 481 424 packet->header = packet->buffer;425 482 426 483 /* FIXME: Better error handling required */ 427 if (rt_read(libtrace, (void **)&pkt_hdr, sizeof(rt_header_t) ) !=484 if (rt_read(libtrace, (void **)&pkt_hdr, sizeof(rt_header_t),blocking) != 428 485 sizeof(rt_header_t)) { 429 printf("Error receiving rt header\n");430 486 return -1; 431 487 } … … 436 492 437 493 if (packet->type >= RT_DATA_SIMPLE) { 438 if (rt_read(libtrace, &packet->buffer, pkt_size ) != pkt_size) {494 if (rt_read(libtrace, &packet->buffer, pkt_size,1) != pkt_size) { 439 495 printf("Error receiving packet\n"); 440 496 return -1; 441 497 } 498 packet->header = packet->buffer; 442 499 443 500 if (rt_set_format(libtrace, packet) < 0) { … … 459 516 case RT_DUCK: 460 517 if (rt_read(libtrace, &packet->buffer, 461 pkt_size ) !=518 pkt_size,1) != 462 519 pkt_size) { 463 520 printf("Error receiving status packet\n"); … … 483 540 } 484 541 /* Return the number of bytes read from the stream */ 485 return sizeof(rt_header_t) + packet->size; 486 } 542 return packet->size; 543 } 544 545 static int rt_read_packet(libtrace_t *libtrace, 546 libtrace_packet_t *packet) { 547 rt_read_packet_versatile(libtrace,packet,1); 548 } 549 487 550 488 551 static int rt_get_capture_length(const struct libtrace_packet_t *packet) { … … 516 579 return 0; 517 580 } 581 582 static int rt_get_wire_length(const libtrace_packet_t *packet) { 583 return 0; 584 } 518 585 519 586 static int rt_get_framing_length(const libtrace_packet_t *packet) { … … 521 588 } 522 589 523 524 590 static int rt_get_fd(const libtrace_t *trace) { 525 591 return ((struct rt_format_data_t *)trace->format_data)->input_fd; 526 592 } 527 593 528 594 struct libtrace_eventobj_t trace_event_rt(struct libtrace_t *trace, struct libtrace_packet_t *packet) { 595 struct libtrace_eventobj_t event = {0,0,0.0,0}; 596 libtrace_err_t read_err; 597 int data; 598 599 assert(trace); 600 assert(packet); 601 602 if (trace->format->get_fd) { 603 event.fd = trace->format->get_fd(trace); 604 } else { 605 event.fd = 0; 606 } 607 608 event.size = rt_read_packet_versatile(trace, packet, 0); 609 if (event.size == -1) { 610 read_err = trace_get_err(trace); 611 if (read_err.err_num == EAGAIN) { 612 event.type = TRACE_EVENT_IOWAIT; 613 } 614 else { 615 printf("packet error\n"); 616 event.type = TRACE_EVENT_PACKET; 617 } 618 } else if (event.size == 0) { 619 event.type = TRACE_EVENT_TERMINATE; 620 621 } 622 else { 623 event.type = TRACE_EVENT_PACKET; 624 } 625 626 return event; 627 } 529 628 530 629 static void rt_help() { … … 567 666 NULL, /* seek_seconds */ 568 667 rt_get_capture_length, /* get_capture_length */ 569 NULL, /* get_wire_length */668 rt_get_wire_length, /* get_wire_length */ 570 669 rt_get_framing_length, /* get_framing_length */ 571 670 NULL, /* set_capture_length */ 572 671 rt_get_fd, /* get_fd */ 573 trace_event_ device, /* trace_event */672 trace_event_rt, /* trace_event */ 574 673 rt_help, /* help */ 575 674 NULL /* next pointer */ -
lib/libtrace.h
red636fb4 r9c4b5e3 133 133 TRACE_ERR_NO_CONVERSION = -8, 134 134 TRACE_ERR_BAD_PACKET = -9, 135 TRACE_ERR_OPTION_UNAVAIL= -10 135 TRACE_ERR_OPTION_UNAVAIL= -10, 136 TRACE_ERR_RECV_FAILED = -11 136 137 }; 137 138 -
tools/tracertstats/tracertstats.c
r3d4fb8f r9c4b5e3 54 54 #include "libtrace.h" 55 55 #include "output.h" 56 #include "rt_protocol.h" 57 #include "dagformat.h" 56 58 57 59 struct libtrace_t *trace; … … 128 130 for (;;) { 129 131 int psize; 132 dag_record_t *erf_hdr; 130 133 if ((psize = trace_read_packet(trace, packet)) <1) { 131 134 break; 132 135 } 136 erf_hdr = (dag_record_t *)packet->header; 137 138 if (trace_get_link(packet) == NULL) { 139 continue; 140 } 141 133 142 ts = trace_get_seconds(packet); 134 135 143 for(i=0;i<filter_count;++i) { 136 144 if(trace_bpf_filter(filters[i].filter,packet)) {
Note: See TracChangeset
for help on using the changeset viewer.