Changeset 7068467 for lib/trace.c
- Timestamp:
- 02/10/06 18:02:32 (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:
- 6eb91ff
- Parents:
- 7f32bb5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/trace.c
r37195b4 r7068467 264 264 trace_err.err_num = E_NOERROR; 265 265 266 / / parse the URI to determine what sort of event we are dealing with266 /* parse the URI to determine what sort of event we are dealing with */ 267 267 if ((uridata = trace_parse_uri(uri, &scan)) == 0) { 268 268 return 0; … … 284 284 trace_err.err_num = E_BAD_FORMAT; 285 285 strcpy(trace_err.problem, scan); 286 //trace_err.problem = scan;287 286 return 0; 288 287 } 289 288 290 289 libtrace->uridata = strdup(uridata); 291 // libtrace->format now contains the type of uri 292 // libtrace->uridata contains the appropriate data for this 290 /* libtrace->format now contains the type of uri 291 * libtrace->uridata contains the appropriate data for this 292 */ 293 293 294 294 if (libtrace->format->init_input) { … … 296 296 trace_err.err_num = E_INIT_FAILED; 297 297 strcpy(trace_err.problem, scan); 298 //trace_err.problem = scan;299 298 return 0; 300 299 } … … 302 301 trace_err.err_num = E_NO_INIT; 303 302 strcpy(trace_err.problem, scan); 304 //trace_err.problem = scan;305 303 return 0; 306 304 } … … 350 348 trace_err.err_num = E_BAD_FORMAT; 351 349 strcpy(trace_err.problem, scan); 352 //trace_err.problem = scan;353 350 return 0; 354 351 } … … 383 380 384 381 trace_err.err_num = E_NOERROR; 385 / / parse the URI to determine what sort of event we are dealing with382 /* parse the URI to determine what sort of event we are dealing with */ 386 383 387 384 if ((uridata = trace_parse_uri(uri, &scan)) == 0) { … … 403 400 trace_err.err_num = E_BAD_FORMAT; 404 401 strcpy(trace_err.problem, scan); 405 //trace_err.problem = scan;406 402 return 0; 407 403 } … … 409 405 410 406 411 // libtrace->format now contains the type of uri 412 // libtrace->uridata contains the appropriate data for this 407 /* libtrace->format now contains the type of uri 408 * libtrace->uridata contains the appropriate data for this 409 */ 413 410 414 411 if (libtrace->format->init_output) { … … 419 416 trace_err.err_num = E_NO_INIT_OUT; 420 417 strcpy(trace_err.problem, scan); 421 //trace_err.problem = scan;422 418 return 0; 423 419 } … … 458 454 * @author Shane Alcock 459 455 */ 460 int trace_config_output(struct libtrace_out_t *libtrace, char *options) { 461 char *opt_string = 0; 462 char *opt_argv[MAXOPTS]; 463 int opt_argc = 0; 464 465 assert(libtrace); 466 467 if (!options) { 468 return 0; 469 } 470 asprintf(&opt_string, "%s %s", libtrace->format->name, options); 471 parse_cmd(opt_string, &opt_argc, opt_argv, MAXOPTS); 472 456 int trace_config_output(struct libtrace_out_t *libtrace, 457 trace_option_output_t option, 458 void *value) { 473 459 if (libtrace->format->config_output) { 474 return libtrace->format->config_output(libtrace, opt _argc, opt_argv);460 return libtrace->format->config_output(libtrace, option, value); 475 461 } 476 462 return -1; … … 483 469 assert(libtrace); 484 470 libtrace->format->fin_input(libtrace); 485 / / need to free things!471 /* need to free things! */ 486 472 free(libtrace->uridata); 487 473 destroy_tracefifo(libtrace->fifo); … … 508 494 } 509 495 510 /** Create a new packet object 511 * 512 * @ return a pointer to an initialised libtrace_packet_t structure 513 */ 514 struct libtrace_packet_t *trace_create_packet() { 515 struct libtrace_packet_t *packet = calloc(1,sizeof(struct libtrace_packet_t)); 516 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 517 packet->buf_control = PACKET; 496 libtrace_packet_t *trace_create_packet() { 497 libtrace_packet_t *packet = calloc(1,sizeof(libtrace_packet_t)); 498 /* This used to malloc a packet! Why do we need to malloc a packet 499 * if we're doing zero copy? 500 */ 518 501 return packet; 519 502 } … … 607 590 case TRACE_TYPE_80211_PRISM: 608 591 { 609 struct ieee_802_11_header *wifi = trace_get_link(packet)+144;592 struct ieee_802_11_header *wifi = (char*)trace_get_link(packet)+144; 610 593 if (!wifi) { 611 594 ipptr = NULL; … … 613 596 } 614 597 615 / / Data packet?598 /* Data packet? */ 616 599 if (wifi->type != 2) { 617 600 ipptr = NULL; … … 644 627 } 645 628 646 / / Data packet?629 /* Data packet? */ 647 630 if (wifi->type != 2) { 648 631 ipptr = NULL; … … 727 710 case TRACE_TYPE_LEGACY_POS: 728 711 { 729 / / 64 byte capture.712 /* 64 byte capture. */ 730 713 struct libtrace_pos *pos = 731 714 trace_get_link(packet); … … 741 724 case TRACE_TYPE_ATM: 742 725 { 743 / / 64 byte capture.726 /* 64 byte capture. */ 744 727 struct libtrace_llcsnap *llc = 745 728 trace_get_link(packet); 746 729 747 // advance the llc ptr +4 into the link layer. 748 // need to check what is in these 4 bytes. 749 // don't have time! 730 /* advance the llc ptr +4 into the link layer. 731 * need to check what is in these 4 bytes. 732 * don't have time! 733 */ 750 734 llc = (void *)llc + 4; 751 735 if (ntohs(llc->type) == 0x0800) { … … 796 780 * Skipped can be NULL, in which case it will be ignored 797 781 */ 798 void *trace_get_transport_from_ip(const struct libtrace_ip*ip, int *skipped) {782 void *trace_get_transport_from_ip(const libtrace_ip_t *ip, int *skipped) { 799 783 void *trans_ptr = 0; 800 784 … … 814 798 * @returns a pointer to the TCP header, or NULL if there is not a TCP packet 815 799 */ 816 struct libtrace_tcp *trace_get_tcp(const struct libtrace_packet_t *packet) {800 libtrace_tcp_t *trace_get_tcp(const libtrace_packet_t *packet) { 817 801 struct libtrace_tcp *tcpptr = 0; 818 802 struct libtrace_ip *ipptr = 0; … … 835 819 * Skipped can be NULL, in which case it will be ignored by the program. 836 820 */ 837 struct libtrace_tcp *trace_get_tcp_from_ip(const struct libtrace_ip*ip, int *skipped)821 libtrace_tcp_t *trace_get_tcp_from_ip(const libtrace_ip_t *ip, int *skipped) 838 822 { 839 #define SW_IP_OFFMASK 0xff1f840 823 struct libtrace_tcp *tcpptr = 0; 841 824 … … 958 941 *optlen = *(*ptr+1); 959 942 if (*optlen<2) 960 return 0; // I have no idea wtf is going on 961 // with these packets 943 return 0; /* I have no idea wtf is going on 944 * with these packets 945 */ 962 946 (*len)-=*optlen; 963 947 (*data)=(*ptr+2); … … 985 969 986 970 if (packet->trace->format->get_erf_timestamp) { 987 / / timestamp -> timestamp971 /* timestamp -> timestamp */ 988 972 timestamp = packet->trace->format->get_erf_timestamp(packet); 989 973 } else if (packet->trace->format->get_timeval) { 990 / / timeval -> timestamp974 /* timeval -> timestamp */ 991 975 ts = packet->trace->format->get_timeval(packet); 992 976 timestamp = ((((uint64_t)ts.tv_sec) << 32) + \ 993 977 (((uint64_t)ts.tv_usec * UINT_MAX)/1000000)); 994 978 } else if (packet->trace->format->get_seconds) { 995 / / seconds -> timestamp979 /* seconds -> timestamp */ 996 980 seconds = packet->trace->format->get_seconds(packet); 997 981 timestamp = ((uint64_t)((uint32_t)seconds) << 32) + \ … … 1014 998 assert(packet->size>0 && packet->size<65536); 1015 999 if (packet->trace->format->get_timeval) { 1016 / / timeval -> timeval1000 /* timeval -> timeval */ 1017 1001 tv = packet->trace->format->get_timeval(packet); 1018 1002 } else if (packet->trace->format->get_erf_timestamp) { 1019 / / timestamp -> timeval1003 /* timestamp -> timeval */ 1020 1004 ts = packet->trace->format->get_erf_timestamp(packet); 1021 1005 #if __BYTE_ORDER == __BIG_ENDIAN … … 1034 1018 } 1035 1019 } else if (packet->trace->format->get_seconds) { 1036 / / seconds -> timeval1020 /* seconds -> timeval */ 1037 1021 seconds = packet->trace->format->get_seconds(packet); 1038 1022 tv.tv_sec = (uint32_t)seconds; … … 1056 1040 1057 1041 if (packet->trace->format->get_seconds) { 1058 / / seconds->seconds1042 /* seconds->seconds */ 1059 1043 seconds = packet->trace->format->get_seconds(packet); 1060 1044 } else if (packet->trace->format->get_erf_timestamp) { 1061 / / timestamp -> seconds1045 /* timestamp -> seconds */ 1062 1046 ts = packet->trace->format->get_erf_timestamp(packet); 1063 1047 seconds = (ts>>32) + ((ts & UINT_MAX)*1.0 / UINT_MAX); 1064 1048 } else if (packet->trace->format->get_timeval) { 1065 / / timeval -> seconds1049 /* timeval -> seconds */ 1066 1050 tv = packet->trace->format->get_timeval(packet); 1067 1051 seconds = tv.tv_sec + ((tv.tv_usec * UINT_MAX * 1.0)/1000000); … … 1265 1249 pcap_t *pcap; 1266 1250 struct bpf_program bpfprog; 1267 1268 switch (trace_get_link_type(packet)) { 1269 case TRACE_TYPE_ETH: 1270 pcap = (pcap_t *)pcap_open_dead(DLT_EN10MB, 1500); 1271 break; 1272 #ifdef DLT_LINUX_SLL 1273 case TRACE_TYPE_LINUX_SLL: 1274 pcap = (pcap_t *)pcap_open_dead(DLT_LINUX_SLL, 1500); 1275 break; 1276 #endif 1277 #ifdef DLT_PFLOG 1278 case TRACE_TYPE_PFLOG: 1279 pcap = (pcap_t *)pcap_open_dead(DLT_PFLOG, 1500); 1280 break; 1281 #endif 1282 default: 1283 printf("only works for ETH and LINUX_SLL (ppp) at the moment\n"); 1284 assert(0); 1285 } 1286 1287 // build filter 1251 pcap=(pcap_t *)pcap_open_dead( 1252 libtrace_to_pcap_dlt(trace_get_link_type(packet)), 1253 1500); 1254 /* build filter */ 1288 1255 if (pcap_compile( pcap, &bpfprog, filter->filterstring, 1, 0)) { 1289 1256 printf("bpf compilation error: %s: %s\n", … … 1481 1448 return USE_DEST; 1482 1449 */ 1483 / / failing that test...1450 /* failing that test... */ 1484 1451 if (source < dest) { 1485 1452 return USE_SOURCE; … … 1516 1483 1517 1484 if((uridata = strchr(uri,':')) == NULL) { 1518 / / badly formed URI - needs a :1485 /* badly formed URI - needs a : */ 1519 1486 trace_err.err_num = E_URI_NOCOLON; 1520 1487 return 0; … … 1522 1489 1523 1490 if ((uridata - uri) > URI_PROTO_LINE) { 1524 / / badly formed URI - uri type is too long1491 /* badly formed URI - uri type is too long */ 1525 1492 trace_err.err_num = E_URI_LONG; 1526 1493 return 0; … … 1529 1496 *format=xstrndup(uri, (uridata - uri)); 1530 1497 1531 / / push uridata past the delimiter1498 /* push uridata past the delimiter */ 1532 1499 uridata++; 1533 1500
Note: See TracChangeset
for help on using the changeset viewer.