Changeset 9636216
- Timestamp:
- 02/23/16 16:03:14 (5 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, master, ndag_format, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- 7d1ada1
- Parents:
- 3fe009c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/trace.c
r6fc1ae7 r9636216 2 2 * This file is part of libtrace 3 3 * 4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton, 4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton, 5 5 * New Zealand. 6 6 * 7 * Authors: Daniel Lawson 7 * Authors: Daniel Lawson 8 8 * Perry Lorier 9 * Shane Alcock 10 * 9 * Shane Alcock 10 * 11 11 * All rights reserved. 12 12 * 13 * This code has been developed by the University of Waikato WAND 13 * This code has been developed by the University of Waikato WAND 14 14 * research group. For further information please see http://www.wand.net.nz/ 15 15 * … … 115 115 dest[n]='\0'; 116 116 } 117 117 118 118 static char *xstrndup(const char *src,size_t n) 119 { 119 { 120 120 char *ret=(char*)malloc(n+1); 121 121 if (ret==NULL) { … … 153 153 } 154 154 155 /* Prints help information for libtrace 155 /* Prints help information for libtrace 156 156 * 157 157 * Function prints out some basic help information regarding libtrace, … … 176 176 { 177 177 struct libtrace_format_t *tmp; 178 178 179 179 /* Try and guess based on filename */ 180 180 for(tmp = formats_list; tmp; tmp=tmp->next) { … … 198 198 } 199 199 } 200 200 201 201 /* Oh well */ 202 202 return; … … 211 211 * erf:/path/to/erf/file 212 212 * erf:/path/to/erf/file.gz 213 * erf:- 213 * erf:- (stdin) 214 214 * dag:/dev/dagcard 215 * pcapint:pcapinterface 215 * pcapint:pcapinterface (eg: pcapint:eth0) 216 216 * pcapfile:/path/to/pcap/file 217 217 * pcapfile:- … … 224 224 */ 225 225 DLLEXPORT libtrace_t *trace_create(const char *uri) { 226 libtrace_t *libtrace = 226 libtrace_t *libtrace = 227 227 (libtrace_t *)malloc(sizeof(libtrace_t)); 228 228 char *scan = 0; 229 const char *uridata = 0; 229 const char *uridata = 0; 230 230 231 231 trace_init(); … … 237 237 return NULL; 238 238 } 239 239 240 240 libtrace->err.err_num = TRACE_ERR_NOERROR; 241 241 libtrace->format=NULL; 242 242 243 243 libtrace->event.tdelta = 0.0; 244 244 libtrace->event.packet = NULL; … … 287 287 * libtrace->uridata contains the appropriate data for this 288 288 */ 289 290 /* Call the init_input function for the matching capture format */ 289 290 /* Call the init_input function for the matching capture format */ 291 291 if (libtrace->format->init_input) { 292 292 int err=libtrace->format->init_input(libtrace); 293 293 assert (err==-1 || err==0); 294 294 if (err==-1) { 295 /* init_input should call trace_set_err to set 296 * theerror message295 /* init_input should call trace_set_err to set the 296 * error message 297 297 */ 298 298 return libtrace; … … 303 303 return libtrace; 304 304 } 305 305 306 306 if (scan) 307 307 free(scan); … … 326 326 327 327 trace_init(); 328 328 329 329 libtrace->err.err_num = TRACE_ERR_NOERROR; 330 330 … … 334 334 xstrncpy(scan,uri, (size_t)(uridata - uri)); 335 335 } 336 336 337 337 libtrace->err.err_num = TRACE_ERR_NOERROR; 338 338 libtrace->format=NULL; 339 339 340 340 libtrace->event.tdelta = 0.0; 341 341 libtrace->event.packet = NULL; … … 348 348 libtrace->io = NULL; 349 349 libtrace->filtered_packets = 0; 350 350 351 351 for(tmp=formats_list;tmp;tmp=tmp->next) { 352 352 if (strlen(scan) == strlen(tmp->name) && … … 369 369 } 370 370 371 /* Creates an output trace from a URI. 371 /* Creates an output trace from a URI. 372 372 * 373 373 * @param uri the uri string describing the output format and destination 374 * @returns opaque pointer to a libtrace_output_t 374 * @returns opaque pointer to a libtrace_output_t 375 375 * 376 376 * If an error occured when attempting to open the output trace, NULL is 377 * returned and trace_errno is set. 378 */ 379 377 * returned and trace_errno is set. 378 */ 379 380 380 DLLEXPORT libtrace_out_t *trace_create_output(const char *uri) { 381 libtrace_out_t *libtrace = 381 libtrace_out_t *libtrace = 382 382 (libtrace_out_t*)malloc(sizeof(libtrace_out_t)); 383 383 384 384 char *scan = 0; 385 385 const char *uridata = 0; … … 392 392 libtrace->format = NULL; 393 393 libtrace->uridata = NULL; 394 394 395 395 /* Parse the URI to determine what capture format we want to write */ 396 396 … … 400 400 return libtrace; 401 401 } 402 402 403 403 /* Attempt to find the format in the list of supported formats */ 404 404 for(tmp=formats_list;tmp;tmp=tmp->next) { … … 469 469 470 470 /* Start an output trace */ 471 DLLEXPORT int trace_start_output(libtrace_out_t *libtrace) 471 DLLEXPORT int trace_start_output(libtrace_out_t *libtrace) 472 472 { 473 473 assert(libtrace); … … 505 505 return -1; 506 506 } 507 507 508 508 /* If the capture format supports configuration, try using their 509 509 * native configuration first */ … … 515 515 516 516 /* If we get here, either the native configuration failed or the 517 * format did not support configuration. However, libtrace can 517 * format did not support configuration. However, libtrace can 518 518 * deal with some options itself, so give that a go */ 519 519 switch(option) { … … 523 523 trace_get_err(libtrace); 524 524 } 525 if (*(int*)value<0 525 if (*(int*)value<0 526 526 || *(int*)value>LIBTRACE_PACKET_BUFSIZE) { 527 527 trace_set_err(libtrace,TRACE_ERR_BAD_STATE, … … 545 545 case TRACE_OPTION_META_FREQ: 546 546 if (!trace_is_err(libtrace)) { 547 trace_set_err(libtrace, 547 trace_set_err(libtrace, 548 548 TRACE_ERR_OPTION_UNAVAIL, 549 549 "This format does not support meta-data gathering"); … … 552 552 case TRACE_OPTION_EVENT_REALTIME: 553 553 if (!trace_is_err(libtrace)) { 554 trace_set_err(libtrace, 554 trace_set_err(libtrace, 555 555 TRACE_ERR_OPTION_UNAVAIL, 556 556 "This format does not support realtime events"); 557 557 } 558 558 return -1; 559 559 560 560 } 561 561 if (!trace_is_err(libtrace)) { … … 566 566 } 567 567 568 DLLEXPORT int trace_config_output(libtrace_out_t *libtrace, 568 DLLEXPORT int trace_config_output(libtrace_out_t *libtrace, 569 569 trace_option_output_t option, 570 570 void *value) { 571 571 572 572 /* Unlike the input options, libtrace does not natively support any of 573 573 * the output options - the format module must be able to deal with … … 623 623 * @param libtrace the output trace file to be destroyed 624 624 */ 625 DLLEXPORT void trace_destroy_output(libtrace_out_t *libtrace) 625 DLLEXPORT void trace_destroy_output(libtrace_out_t *libtrace) 626 626 { 627 627 assert(libtrace); … … 633 633 } 634 634 635 DLLEXPORT libtrace_packet_t *trace_create_packet(void) 636 { 637 libtrace_packet_t *packet = 635 DLLEXPORT libtrace_packet_t *trace_create_packet(void) 636 { 637 libtrace_packet_t *packet = 638 638 (libtrace_packet_t*)calloc((size_t)1,sizeof(libtrace_packet_t)); 639 639 … … 644 644 645 645 DLLEXPORT libtrace_packet_t *trace_copy_packet(const libtrace_packet_t *packet) { 646 libtrace_packet_t *dest = 646 libtrace_packet_t *dest = 647 647 (libtrace_packet_t *)malloc(sizeof(libtrace_packet_t)); 648 648 if (!dest) { … … 663 663 /* Reset the cache - better to recalculate than try to convert 664 664 * the values over to the new packet */ 665 trace_clear_cache(dest); 665 trace_clear_cache(dest); 666 666 /* Ooooh nasty memcpys! This is why we want to avoid copying packets 667 667 * as much as possible */ … … 678 678 free(packet->buffer); 679 679 } 680 packet->buf_control=(buf_control_t)'\0'; 680 packet->buf_control=(buf_control_t)'\0'; 681 681 /* A "bad" value to force an assert 682 682 * if this packet is ever reused 683 683 */ 684 684 free(packet); 685 } 685 } 686 686 687 687 /* Read one packet from the trace into buffer. Note that this function will 688 688 * block until a packet is read (or EOF is reached). 689 689 * 690 * @param libtrace 691 * @param packet 690 * @param libtrace the libtrace opaque pointer 691 * @param packet the packet opaque pointer 692 692 * @returns 0 on EOF, negative value on error 693 693 * … … 702 702 return -1; 703 703 } 704 if (!(packet->buf_control==TRACE_CTRL_PACKET || packet->buf_control==TRACE_CTRL_EXTERNAL)) { 704 if (!(packet->buf_control==TRACE_CTRL_PACKET 705 || packet->buf_control==TRACE_CTRL_EXTERNAL)) { 705 706 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid\n"); 706 707 return -1; 707 708 } 708 709 assert(packet); 709 710 /* Store the trace we are reading from into the packet opaque 710 711 /* Store the trace we are reading from into the packet opaque 711 712 * structure */ 712 713 packet->trace = libtrace; … … 739 740 return ~0U; 740 741 } 741 742 742 743 if (filtret == 0) { 743 744 ++libtrace->filtered_packets; … … 763 764 * appropriate capture format header for the format type that the packet is 764 765 * being converted to. This also allows for a packet to be converted into 765 * just about capture format that is supported by libtrace, provided the 766 * just about capture format that is supported by libtrace, provided the 766 767 * format header is present in the buffer. 767 768 * 768 769 * This function is primarily used to convert packets received via the RT 769 770 * protocol back into their original capture format. The RT header encapsulates 770 * the original capture format header, so after removing it the packet must 771 * the original capture format header, so after removing it the packet must 771 772 * have it's header and payload pointers updated and the packet format and type 772 773 * changed, amongst other things. 773 774 * 774 * Intended only for internal use at this point - this function is not 775 * Intended only for internal use at this point - this function is not 775 776 * available through the external libtrace API. 776 777 */ … … 780 781 assert(packet); 781 782 assert(trace); 782 783 783 784 /* XXX Proper error handling?? */ 784 785 if (buffer == NULL) … … 789 790 return -1; 790 791 } 791 792 792 793 packet->trace = trace; 793 794 794 795 /* Clear packet cache */ 795 796 trace_clear_cache(packet); … … 799 800 buffer, rt_type, flags); 800 801 } 801 trace_set_err(trace, TRACE_ERR_UNSUPPORTED, 802 trace_set_err(trace, TRACE_ERR_UNSUPPORTED, 802 803 "This format does not support preparing packets\n"); 803 804 return -1; … … 813 814 DLLEXPORT int trace_write_packet(libtrace_out_t *libtrace, libtrace_packet_t *packet) { 814 815 assert(libtrace); 815 assert(packet); 816 assert(packet); 816 817 /* Verify the packet is valid */ 817 818 if (!libtrace->started) { … … 841 842 * wire lengths to be the "remaining" value. If the packet has 842 843 * been padded to increase the capture length, we don't want 843 * to allow subsequent protocol decoders to consider the 844 * to allow subsequent protocol decoders to consider the 844 845 * padding as part of the packet. 845 846 * … … 851 852 * better off returning an incomplete TCP header in that case. 852 853 */ 853 854 854 855 cap_len = trace_get_capture_length(packet); 855 856 wire_len = trace_get_wire_length(packet); … … 860 861 * massively negative wire lens. We could assert fail here on 861 862 * them, but we could at least try the capture length instead. 862 * 863 * 863 864 * You may still run into problems if you try to write that 864 865 * packet, but at least reading should work OK. … … 876 877 877 878 878 /* Get a pointer to the first byte of the packet payload 879 /* Get a pointer to the first byte of the packet payload 879 880 * 880 881 * DEPRECATED - use trace_get_packet_buffer() instead */ … … 883 884 } 884 885 885 /* Get the current time in DAG time format 886 * @param packet 886 /* Get the current time in DAG time format 887 * @param packet a pointer to a libtrace_packet structure 887 888 * @returns a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds 888 889 * past 1970-01-01, the lower 32bits are partial seconds) 889 */ 890 */ 890 891 DLLEXPORT uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet) { 891 892 if (packet->trace->format->get_erf_timestamp) { … … 913 914 return (uint64_t)0; 914 915 } 915 916 916 } 917 917 … … 922 922 * @author Daniel Lawson 923 923 * @author Perry Lorier 924 */ 924 */ 925 925 DLLEXPORT struct timeval trace_get_timeval(const libtrace_packet_t *packet) { 926 926 struct timeval tv; … … 934 934 tv.tv_sec = ts >> 32; 935 935 tv.tv_usec = ((ts&0xFFFFFFFF)*1000000)>>32; 936 937 938 939 936 if (tv.tv_usec >= 1000000) { 937 tv.tv_usec -= 1000000; 938 tv.tv_sec += 1; 939 } 940 940 } else if (packet->trace->format->get_timespec) { 941 941 struct timespec ts = packet->trace->format->get_timespec(packet); … … 966 966 ts.tv_sec = erfts >> 32; 967 967 ts.tv_nsec = ((erfts&0xFFFFFFFF)*1000000000)>>32; 968 969 970 971 968 if (ts.tv_nsec >= 1000000000) { 969 ts.tv_nsec -= 1000000000; 970 ts.tv_sec += 1; 971 } 972 972 return ts; 973 973 } else if (packet->trace->format->get_timeval) { … … 993 993 994 994 /* Get the current time in floating point seconds 995 * @param packet 995 * @param packet a pointer to a libtrace_packet structure 996 996 * @returns time that this packet was seen in 64bit floating point seconds 997 */ 997 */ 998 998 DLLEXPORT double trace_get_seconds(const libtrace_packet_t *packet) { 999 999 double seconds = 0.0; … … 1022 1022 } 1023 1023 1024 DLLEXPORT size_t trace_get_capture_length(const libtrace_packet_t *packet) 1024 DLLEXPORT size_t trace_get_capture_length(const libtrace_packet_t *packet) 1025 1025 { 1026 1026 /* Cache the capture length */ … … 1029 1029 return ~0U; 1030 1030 /* Cast away constness because this is "just" a cache */ 1031 ((libtrace_packet_t*)packet)->capture_length = 1031 ((libtrace_packet_t*)packet)->capture_length = 1032 1032 packet->trace->format->get_capture_length(packet); 1033 1033 } … … 1037 1037 return packet->capture_length; 1038 1038 } 1039 1039 1040 1040 /* Get the size of the packet as it was seen on the wire. 1041 1041 * @param packet a pointer to a libtrace_packet structure … … 1044 1044 * @note Due to the trace being a header capture, or anonymisation this may 1045 1045 * not be the same as the Capture Len. 1046 */ 1046 */ 1047 1047 DLLEXPORT size_t trace_get_wire_length(const libtrace_packet_t *packet){ 1048 1048 1049 1049 if (packet->wire_length == -1) { 1050 if (!packet->trace->format->get_wire_length) 1050 if (!packet->trace->format->get_wire_length) 1051 1051 return ~0U; 1052 ((libtrace_packet_t *)packet)->wire_length = 1052 ((libtrace_packet_t *)packet)->wire_length = 1053 1053 packet->trace->format->get_wire_length(packet); 1054 1054 } … … 1060 1060 1061 1061 /* Get the length of the capture framing headers. 1062 * @param packet 1062 * @param packet the packet opaque pointer 1063 1063 * @returns the size of the packet as it was on the wire. 1064 * @note this length corresponds to the difference between the size of a 1064 * @note this length corresponds to the difference between the size of a 1065 1065 * captured packet in memory, and the captured length of the packet 1066 */ 1066 */ 1067 1067 DLLEXPORT SIMPLE_FUNCTION 1068 1068 size_t trace_get_framing_length(const libtrace_packet_t *packet) { … … 1075 1075 1076 1076 /* Get the type of the link layer 1077 * @param packet 1077 * @param packet a pointer to a libtrace_packet structure 1078 1078 * @returns libtrace_linktype_t 1079 1079 */ … … 1101 1101 * which in turn is stored inside the new packet object... 1102 1102 */ 1103 DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace, 1103 DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace, 1104 1104 libtrace_packet_t *packet) { 1105 1105 libtrace_eventobj_t event = {TRACE_EVENT_IOWAIT,0,0.0,0}; … … 1113 1113 /* Clear the packet cache */ 1114 1114 trace_clear_cache(packet); 1115 1115 1116 1116 /* Store the trace we are reading from into the packet opaque 1117 1117 * structure */ … … 1120 1120 if (packet->trace->format->trace_event) { 1121 1121 /* Note: incrementing accepted, filtered etc. packet 1122 * counters is handled by the format-specific 1122 * counters is handled by the format-specific 1123 1123 * function so don't increment them here. 1124 1124 */ … … 1147 1147 filter->filter.bf_insns = (struct bpf_insn *) 1148 1148 malloc(sizeof(struct bpf_insn) * bf_len); 1149 1149 1150 1150 memcpy(filter->filter.bf_insns, bf_insns, 1151 1151 bf_len * sizeof(struct bpf_insn)); 1152 1152 1153 1153 filter->filter.bf_len = bf_len; 1154 1154 filter->filterstring = NULL; 1155 1155 filter->jitfilter = NULL; 1156 1156 /* "flag" indicates that the filter member is valid */ 1157 filter->flag = 1; 1158 1157 filter->flag = 1; 1158 1159 1159 return filter; 1160 1160 #endif … … 1186 1186 pcap_freecode(&filter->filter); 1187 1187 #ifdef HAVE_LLVM 1188 if (filter->jitfilter) 1188 if (filter->jitfilter) 1189 1189 destroy_program(filter->jitfilter); 1190 1190 #endif … … 1204 1204 static int trace_bpf_compile(libtrace_filter_t *filter, 1205 1205 const libtrace_packet_t *packet, 1206 void *linkptr, 1206 void *linkptr, 1207 1207 libtrace_linktype_t linktype ) { 1208 1208 #ifdef HAVE_BPF_FILTER … … 1215 1215 return -1; 1216 1216 } 1217 1217 1218 1218 if (filter->filterstring && ! filter->flag) { 1219 1219 pcap_t *pcap = NULL; … … 1234 1234 /* build filter */ 1235 1235 assert(pcap); 1236 if (pcap_compile( pcap, &filter->filter, filter->filterstring, 1236 if (pcap_compile( pcap, &filter->filter, filter->filterstring, 1237 1237 1, 0)) { 1238 1238 trace_set_err(packet->trace,TRACE_ERR_BAD_FILTER, 1239 "Unable to compile the filter \"%s\": %s", 1239 "Unable to compile the filter \"%s\": %s", 1240 1240 filter->filterstring, 1241 1241 pcap_geterr(pcap)); … … 1273 1273 1274 1274 if (linktype == TRACE_TYPE_NONDATA) 1275 return 1; 1275 return 1; 1276 1276 1277 1277 if (libtrace_to_pcap_dlt(linktype)==TRACE_DLT_ERROR) { 1278 1278 1279 1279 /* If we cannot get a suitable DLT for the packet, it may 1280 1280 * be because the packet is encapsulated in a link type that … … 1282 1282 * popping off headers until we either can find a suitable 1283 1283 * link type or we can't do any more sensible decapsulation. */ 1284 1284 1285 1285 /* Copy the packet, as we don't want to trash the one we 1286 1286 * were passed in */ … … 1290 1290 while (libtrace_to_pcap_dlt(linktype) == TRACE_DLT_ERROR) { 1291 1291 if (!demote_packet(packet_copy)) { 1292 trace_set_err(packet->trace, 1292 trace_set_err(packet->trace, 1293 1293 TRACE_ERR_NO_CONVERSION, 1294 1294 "pcap does not support this format"); … … 1302 1302 1303 1303 } 1304 1304 1305 1305 linkptr = trace_get_packet_buffer(packet_copy,NULL,&clen); 1306 1306 if (!linkptr) { … … 1311 1311 } 1312 1312 1313 /* We need to compile the filter now, because before we didn't know 1313 /* We need to compile the filter now, because before we didn't know 1314 1314 * what the link type was 1315 1315 */ … … 1352 1352 * @returns a signed value containing the direction flag, or -1 if this is not supported 1353 1353 */ 1354 DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, 1355 libtrace_direction_t direction) 1354 DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, 1355 libtrace_direction_t direction) 1356 1356 { 1357 1357 assert(packet); … … 1370 1370 * for a special trace. 1371 1371 */ 1372 DLLEXPORT libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet) 1372 DLLEXPORT libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet) 1373 1373 { 1374 1374 assert(packet); … … 1385 1385 #define DYNAMIC(x) ((49152 < (x)) && ((x) < 65535)) 1386 1386 #define SERVER(x) ROOT_SERVER(x) || NONROOT_SERVER(x) 1387 #define CLIENT(x) ROOT_CLIENT(x) || NONROOT_CLIENT(x) 1387 #define CLIENT(x) ROOT_CLIENT(x) || NONROOT_CLIENT(x) 1388 1388 1389 1389 /* Attempt to deduce the 'server' port … … 1393 1393 * @returns a hint as to which port is the server port 1394 1394 */ 1395 DLLEXPORT int8_t trace_get_server_port(UNUSED uint8_t protocol, 1396 uint16_t source, uint16_t dest) 1395 DLLEXPORT int8_t trace_get_server_port(UNUSED uint8_t protocol, 1396 uint16_t source, uint16_t dest) 1397 1397 { 1398 1398 /* … … 1407 1407 * * flip a coin. 1408 1408 */ 1409 1409 1410 1410 /* equal */ 1411 1411 if (source == dest) … … 1453 1453 return USE_SOURCE; 1454 1454 } 1455 1455 1456 1456 /* nonroot client */ 1457 1457 if (NONROOT_CLIENT(source) && NONROOT_CLIENT(dest)) { 1458 if (source < dest) 1458 if (source < dest) 1459 1459 return USE_SOURCE; 1460 1460 return USE_DEST; … … 1476 1476 return USE_SOURCE; 1477 1477 /* 1478 if (SERVER(source) && CLIENT(dest)) 1478 if (SERVER(source) && CLIENT(dest)) 1479 1479 return USE_SOURCE; 1480 1481 if (SERVER(dest) && CLIENT(source)) 1480 1481 if (SERVER(dest) && CLIENT(source)) 1482 1482 return USE_DEST; 1483 if (ROOT_SERVER(source) && !ROOT_SERVER(dest)) 1483 if (ROOT_SERVER(source) && !ROOT_SERVER(dest)) 1484 1484 return USE_SOURCE; 1485 if (ROOT_SERVER(dest) && !ROOT_SERVER(source)) 1485 if (ROOT_SERVER(dest) && !ROOT_SERVER(source)) 1486 1486 return USE_DEST; 1487 1487 */ … … 1489 1489 if (source < dest) { 1490 1490 return USE_SOURCE; 1491 } 1491 } 1492 1492 return USE_DEST; 1493 1493 1494 1494 } 1495 1495 … … 1520 1520 * 1521 1521 * Returns a pointer to the URI data, but updates the format parameter to 1522 * point to a copy of the format component. 1522 * point to a copy of the format component. 1523 1523 */ 1524 1524 1525 1525 DLLEXPORT const char * trace_parse_uri(const char *uri, char **format) { 1526 1526 const char *uridata = 0; 1527 1527 1528 1528 if((uridata = strchr(uri,':')) == NULL) { 1529 1529 /* Badly formed URI - needs a : */ … … 1542 1542 /* Push uridata past the delimiter */ 1543 1543 uridata++; 1544 1544 1545 1545 return uridata; 1546 1546 } 1547 1547 1548 enum base_format_t trace_get_format(libtrace_packet_t *packet) 1548 enum base_format_t trace_get_format(libtrace_packet_t *packet) 1549 1549 { 1550 1550 assert(packet); … … 1552 1552 return packet->trace->format->type; 1553 1553 } 1554 1554 1555 1555 DLLEXPORT libtrace_err_t trace_get_err(libtrace_t *trace) 1556 1556 { … … 1650 1650 } 1651 1651 if (trace->format->seek_seconds) { 1652 double seconds = 1652 double seconds = 1653 1653 (ts>>32) + ((ts & UINT_MAX)*1.0 / UINT_MAX); 1654 1654 return trace->format->seek_seconds(trace,seconds); … … 1674 1674 } 1675 1675 if (trace->format->seek_erf) { 1676 uint64_t timestamp = 1676 uint64_t timestamp = 1677 1677 ((uint64_t)((uint32_t)seconds) << 32) + \ 1678 1678 (uint64_t)(( seconds - (uint32_t)seconds ) * UINT_MAX); … … 1737 1737 1738 1738 1739 /* Creates a libtrace packet from scratch using the contents of the provided 1739 /* Creates a libtrace packet from scratch using the contents of the provided 1740 1740 * buffer as the packet payload. 1741 1741 * 1742 1742 * Unlike trace_prepare_packet(), the buffer should not contain any capture 1743 * format headers; instead this function will add the PCAP header to the 1743 * format headers; instead this function will add the PCAP header to the 1744 1744 * packet record. This also means only PCAP packets can be constructed using 1745 1745 * this function. … … 1763 1763 /* We need a trace to attach the constructed packet to (and it needs 1764 1764 * to be PCAP) */ 1765 if (NULL == deadtrace) 1765 if (NULL == deadtrace) 1766 1766 deadtrace=trace_create_dead("pcapfile"); 1767 1767 … … 1863 1863 1864 1864 /* Now, verify that the format has at least the minimum functionality. 1865 * 1865 * 1866 1866 * This #if can be changed to a 1 to output warnings about inconsistent 1867 1867 * functions being provided by format modules. This generally is very 1868 1868 * noisy, as almost all modules don't implement one or more functions 1869 * for various reasons. This is very useful when checking a new 1869 * for various reasons. This is very useful when checking a new 1870 1870 * format module is sane. 1871 */ 1871 */ 1872 1872 #if 0 1873 1873 if (f->init_input) { … … 1883 1883 REQUIRE(get_framing_length); 1884 1884 REQUIRE(trace_event); 1885 if (!f->get_erf_timestamp 1885 if (!f->get_erf_timestamp 1886 1886 && !f->get_seconds 1887 1887 && !f->get_timeval) {
Note: See TracChangeset
for help on using the changeset viewer.