Changeset 1aa4bf7
- Timestamp:
- 04/03/09 14:22:52 (12 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:
- 327b1df
- Parents:
- af0918a
- Location:
- lib
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_atmhdr.c
r91b72d3 r1aa4bf7 143 143 atmhdr_get_erf_timestamp, /* get_erf_timestamp */ 144 144 NULL, /* get_timeval */ 145 NULL, /* get_timespec */ 145 146 NULL, /* get_seconds */ 146 147 NULL, /* seek_erf */ -
lib/format_bpf.c
red3820e r1aa4bf7 459 459 NULL, /* get_erf_timestamp */ 460 460 bpf_get_timeval, /* get_timeval */ 461 NULL, /* get_timespec */ 461 462 NULL, /* get_seconds */ 462 463 NULL, /* seek_erf */ -
lib/format_dag24.c
r91b72d3 r1aa4bf7 442 442 erf_get_erf_timestamp, /* get_erf_timestamp */ 443 443 NULL, /* get_timeval */ 444 NULL, /* get_timespec */ 444 445 NULL, /* get_seconds */ 445 446 NULL, /* seek_erf */ -
lib/format_dag25.c
r5865c72 r1aa4bf7 973 973 NULL, /* get_timeval */ 974 974 NULL, /* get_seconds */ 975 NULL, /* get_timespec */ 975 976 NULL, /* seek_erf */ 976 977 NULL, /* seek_timeval */ -
lib/format_duck.c
r91b72d3 r1aa4bf7 321 321 NULL, /* get_erf_timestamp */ 322 322 NULL, /* get_timeval */ 323 NULL, /* get_timespec */ 323 324 NULL, /* get_seconds */ 324 325 NULL, /* seek_erf */ -
lib/format_erf.c
r91b72d3 r1aa4bf7 760 760 erf_get_erf_timestamp, /* get_erf_timestamp */ 761 761 NULL, /* get_timeval */ 762 NULL, /* get_timespec */ 762 763 NULL, /* get_seconds */ 763 764 erf_seek_erf, /* seek_erf */ -
lib/format_legacy.c
r91b72d3 r1aa4bf7 110 110 char *tz; 111 111 time_t ret; 112 static char envbuf[256];113 112 114 113 if(sscanf(s, "%4u%2u%2u-%2u%2u%2u", &tm.tm_year, &tm.tm_mon, … … 480 479 legacy_get_erf_timestamp, /* get_erf_timestamp */ 481 480 NULL, /* get_timeval */ 481 NULL, /* get_timespec */ 482 482 NULL, /* get_seconds */ 483 483 NULL, /* seek_erf */ … … 522 522 legacy_get_erf_timestamp, /* get_erf_timestamp */ 523 523 NULL, /* get_timeval */ 524 NULL, /* get_timespec */ 524 525 NULL, /* get_seconds */ 525 526 NULL, /* seek_erf */ … … 564 565 legacy_get_erf_timestamp, /* get_erf_timestamp */ 565 566 NULL, /* get_timeval */ 567 NULL, /* get_timespec */ 566 568 NULL, /* get_seconds */ 567 569 NULL, /* seek_erf */ … … 606 608 NULL, /* get_erf_timestamp */ 607 609 legacynzix_get_timeval, /* get_timeval */ 610 NULL, /* get_timespec */ 608 611 NULL, /* get_seconds */ 609 612 NULL, /* seek_erf */ -
lib/format_linux.c
r013de36e r1aa4bf7 64 64 }; 65 65 66 typedef enum { TS_NONE, TS_TIMEVAL, TS_TIMESPEC } timestamptype_t; 67 66 68 struct libtrace_format_data_t { 67 69 int fd; 68 70 int snaplen; 69 71 int promisc; 72 timestamptype_t timestamptype; 70 73 libtrace_filter_t *filter; 71 74 struct tpacket_stats stats; … … 73 76 }; 74 77 78 75 79 struct libtrace_linuxnative_header { 76 struct timeval ts; 80 struct timeval tv; 81 struct timespec ts; 82 timestamptype_t timestamptype; 77 83 int wirelen; 78 84 int caplen; … … 89 95 static int linuxnative_probe_filename(const char *filename) 90 96 { 91 int sock;92 93 97 /* Is this an interface? */ 94 98 return (if_nametoindex(filename) != 0); … … 177 181 } 178 182 } 179 183 #ifdef SO_TIMESTAMPNS 184 if (setsockopt(FORMAT(libtrace->format_data)->fd, 185 SOL_SOCKET, 186 SO_TIMESTAMPNS, 187 &one, 188 (socklen_t)sizeof(one))!=-1) { 189 FORMAT(libtrace->format_data)->timestamptype = TS_TIMESPEC; 190 } 191 else 192 /* DANGER: This is a dangling else to only do the next setsockopt() if we fail the first! */ 193 #endif 180 194 if (setsockopt(FORMAT(libtrace->format_data)->fd, 181 195 SOL_SOCKET, 182 196 SO_TIMESTAMP, 183 197 &one, 184 (socklen_t)sizeof(one))==-1) { 185 perror("setsockopt(SO_TIMESTAMP)"); 186 } 198 (socklen_t)sizeof(one))!=-1) { 199 FORMAT(libtrace->format_data)->timestamptype = TS_TIMEVAL; 200 } 201 else 202 FORMAT(libtrace->format_data)->timestamptype = TS_NONE; 187 203 188 204 /* Push BPF filter into the kernel. At this stage we can safely assume … … 436 452 && cmsg->cmsg_type == SO_TIMESTAMP 437 453 && cmsg->cmsg_len <= CMSG_LEN(sizeof(struct timeval))) { 454 memcpy(&hdr->tv, CMSG_DATA(cmsg), 455 sizeof(struct timeval)); 456 hdr->timestamptype = TS_TIMEVAL; 457 break; 458 } 459 #ifdef SO_TIMESTAMPNS 460 else if (cmsg->cmsg_level == SOL_SOCKET 461 && cmsg->cmsg_type == SO_TIMESTAMPNS 462 && cmsg->cmsg_len <= CMSG_LEN(sizeof(struct timespec))) { 438 463 memcpy(&hdr->ts, CMSG_DATA(cmsg), 439 464 sizeof(struct timeval)); 465 hdr->timestamptype = TS_TIMESPEC; 440 466 break; 441 467 } 442 } 443 444 if (cmsg == NULL && ioctl(FORMAT(libtrace->format_data)->fd, 445 SIOCGSTAMP,&hdr->ts)==-1) 446 perror("ioctl(SIOCGSTAMP)"); 468 #endif 469 } 470 471 /* Did we not get given a timestamp? */ 472 if (cmsg == NULL) { 473 if (ioctl(FORMAT(libtrace->format_data)->fd, 474 SIOCGSTAMP,&hdr->tv)==0) { 475 hdr->timestamptype = TS_TIMEVAL; 476 } 477 else { 478 hdr->timestamptype = TS_NONE; 479 } 480 } 447 481 448 482 if (linuxnative_prepare_packet(libtrace, packet, packet->buffer, … … 521 555 } 522 556 557 static struct timespec linuxnative_get_timespec(const libtrace_packet_t *packet) 558 { 559 struct libtrace_linuxnative_header *hdr = 560 (struct libtrace_linuxnative_header*) packet->buffer; 561 /* We have to upconvert from timeval to timespec */ 562 if (hdr->timestamptype == TS_TIMEVAL) { 563 struct timespec ts; 564 ts.tv_sec = hdr->tv.tv_sec; 565 ts.tv_nsec = hdr->tv.tv_usec*1000; 566 return ts; 567 } 568 else 569 return hdr->ts; 570 } 571 523 572 static struct timeval linuxnative_get_timeval(const libtrace_packet_t *packet) 524 573 { 525 return ((struct libtrace_linuxnative_header*)(packet->buffer))->ts; 574 struct libtrace_linuxnative_header *hdr = 575 (struct libtrace_linuxnative_header*) packet->buffer; 576 /* We have to downconvert from timespec to timeval */ 577 if (hdr->timestamptype == TS_TIMESPEC) { 578 struct timeval tv; 579 tv.tv_sec = hdr->ts.tv_sec; 580 tv.tv_usec = hdr->ts.tv_nsec/1000; 581 return tv; 582 } 583 else 584 return hdr->tv; 526 585 } 527 586 … … 643 702 NULL, /* get_erf_timestamp */ 644 703 linuxnative_get_timeval, /* get_timeval */ 704 linuxnative_get_timespec, /* get_timespec */ 645 705 NULL, /* get_seconds */ 646 706 NULL, /* seek_erf */ -
lib/format_pcap.c
r91b72d3 r1aa4bf7 678 678 pcap_get_timeval, /* get_timeval */ 679 679 NULL, /* get_seconds */ 680 NULL, /* get_timespec */ 680 681 NULL, /* seek_erf */ 681 682 NULL, /* seek_timeval */ … … 720 721 pcap_get_timeval, /* get_timeval */ 721 722 NULL, /* get_seconds */ 723 NULL, /* get_timespec */ 722 724 NULL, /* seek_erf */ 723 725 NULL, /* seek_timeval */ -
lib/format_pcapfile.c
r91b72d3 r1aa4bf7 612 612 NULL, /* get_erf_timestamp */ 613 613 pcapfile_get_timeval, /* get_timeval */ 614 NULL, /* get_timespec */ 614 615 NULL, /* get_seconds */ 615 616 NULL, /* seek_erf */ -
lib/format_rt.c
r91b72d3 r1aa4bf7 732 732 NULL, /* get_erf_timestamp */ 733 733 NULL, /* get_timeval */ 734 NULL, /* get_timespec */ 734 735 NULL, /* get_seconds */ 735 736 NULL, /* seek_erf */ -
lib/format_tsh.c
r91b72d3 r1aa4bf7 236 236 NULL, /* get_erf_timestamp */ 237 237 tsh_get_timeval, /* get_timeval */ 238 NULL, /* get_timespec */ 238 239 NULL, /* get_seconds */ 239 240 NULL, /* seek_erf */ … … 283 284 NULL, /* get_erf_timestamp */ 284 285 tsh_get_timeval, /* get_timeval */ 286 NULL, /* get_timespec */ 285 287 NULL, /* get_seconds */ 286 288 NULL, /* seek_erf */ -
lib/libtrace.h.in
raf0918a r1aa4bf7 1557 1557 struct timeval trace_get_timeval(const libtrace_packet_t *packet); 1558 1558 1559 /** Get the current time in struct timespec 1560 * @param packet the packet opaque pointer 1561 * 1562 * @return time that this packet was seen in a struct timespec 1563 */ 1564 DLLEXPORT SIMPLE_FUNCTION 1565 struct timespec trace_get_timespec(const libtrace_packet_t *packet); 1566 1559 1567 /** Get the current time in floating point seconds 1560 1568 * @param packet the packet opaque pointer -
lib/libtrace_int.h
r91b72d3 r1aa4bf7 341 341 */ 342 342 struct timeval (*get_timeval)(const libtrace_packet_t *packet); 343 /** return the timespec of this packet. 344 * @return the timespec 345 * This field may be NULL in the structure, and libtrace will 346 * synthesise the result from get_erf_timestamp or get_seconds if they 347 * exist. AT least one of get_erf_timestamp, get_timeval or 348 * get_seconds must be implemented. 349 */ 350 struct timespec (*get_timespec)(const libtrace_packet_t *packet); 343 351 /** return the timestamp of this packet. 344 352 * @return the floating point seconds since 1970-01-01 00:00:00 -
lib/trace.c
r91b72d3 r1aa4bf7 902 902 */ 903 903 DLLEXPORT uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet) { 904 uint64_t timestamp = 0;905 double seconds = 0.0;906 struct timeval ts;907 908 904 if (packet->trace->format->get_erf_timestamp) { 909 905 /* timestamp -> timestamp */ 910 timestamp = packet->trace->format->get_erf_timestamp(packet); 906 return packet->trace->format->get_erf_timestamp(packet); 907 } else if (packet->trace->format->get_timespec) { 908 /* timespec -> timestamp */ 909 struct timespec ts; 910 ts = packet->trace->format->get_timespec(packet); 911 return ((((uint64_t)ts.tv_sec) << 32) + 912 (((uint64_t)ts.tv_nsec << 32)/1000000000)); 911 913 } else if (packet->trace->format->get_timeval) { 912 914 /* timeval -> timestamp */ 913 ts = packet->trace->format->get_timeval(packet); 914 timestamp = ((((uint64_t)ts.tv_sec) << 32) + 915 (((uint64_t)ts.tv_usec << 32)/1000000)); 915 struct timeval tv; 916 tv = packet->trace->format->get_timeval(packet); 917 return ((((uint64_t)tv.tv_sec) << 32) + 918 (((uint64_t)tv.tv_usec << 32)/1000000)); 916 919 } else if (packet->trace->format->get_seconds) { 917 920 /* seconds -> timestamp */ 918 seconds = packet->trace->format->get_seconds(packet);919 timestamp =(((uint64_t)seconds)<<32)921 double seconds = packet->trace->format->get_seconds(packet); 922 return (((uint64_t)seconds)<<32) 920 923 + (uint64_t)((seconds-(uint64_t)seconds)*UINT_MAX); 924 } 925 else { 926 return (uint64_t)0; 927 } 921 928 922 }923 return timestamp;924 929 } 925 930 … … 934 939 struct timeval tv; 935 940 uint64_t ts = 0; 936 double seconds = 0.0;937 941 if (packet->trace->format->get_timeval) { 938 942 /* timeval -> timeval */ … … 953 957 tv.tv_sec += 1; 954 958 } 959 } else if (packet->trace->format->get_timespec) { 960 struct timespec ts = packet->trace->format->get_timespec(packet); 961 tv.tv_sec = ts.tv_sec; 962 tv.tv_usec = ts.tv_nsec/1000; 955 963 } else if (packet->trace->format->get_seconds) { 956 964 /* seconds -> timeval */ 957 seconds = packet->trace->format->get_seconds(packet);965 double seconds = packet->trace->format->get_seconds(packet); 958 966 tv.tv_sec = (uint32_t)seconds; 959 967 tv.tv_usec = (uint32_t)(((seconds - tv.tv_sec) * 1000000)/UINT_MAX); … … 966 974 return tv; 967 975 } 976 977 DLLEXPORT struct timespec trace_get_timespec(const libtrace_packet_t *packet) { 978 struct timespec ts; 979 980 if (packet->trace->format->get_timespec) { 981 return packet->trace->format->get_timespec(packet); 982 } else if (packet->trace->format->get_erf_timestamp) { 983 /* timestamp -> timeval */ 984 uint64_t erfts = packet->trace->format->get_erf_timestamp(packet); 985 #if __BYTE_ORDER == __BIG_ENDIAN 986 ts.tv_sec = erfts & 0xFFFFFFFF; 987 #elif __BYTE_ORDER == __LITTLE_ENDIAN 988 ts.tv_sec = erfts >> 32; 989 #else 990 #error "What on earth are you running this on?" 991 #endif 992 ts.tv_nsec = ((erfts&0xFFFFFFFF)*1000000000)>>32; 993 if (ts.tv_nsec >= 1000000000) { 994 ts.tv_nsec -= 1000000000; 995 ts.tv_sec += 1; 996 } 997 return ts; 998 } else if (packet->trace->format->get_timeval) { 999 /* timeval -> timespec */ 1000 struct timeval tv = packet->trace->format->get_timeval(packet); 1001 ts.tv_sec = tv.tv_sec; 1002 ts.tv_nsec = tv.tv_usec*1000; 1003 return ts; 1004 } else if (packet->trace->format->get_seconds) { 1005 /* seconds -> timespec */ 1006 double seconds = packet->trace->format->get_seconds(packet); 1007 ts.tv_sec = (uint32_t)seconds; 1008 ts.tv_nsec = (long)(((seconds - ts.tv_sec) * 1000000000)/UINT_MAX); 1009 return ts; 1010 } 1011 else { 1012 ts.tv_sec=-1; 1013 ts.tv_nsec=-1; 1014 return ts; 1015 } 1016 } 1017 968 1018 969 1019 /* Get the current time in floating point seconds … … 974 1024 DLLEXPORT double trace_get_seconds(const libtrace_packet_t *packet) { 975 1025 double seconds = 0.0; 976 uint64_t ts = 0;977 struct timeval tv;978 1026 979 1027 if (packet->trace->format->get_seconds) { … … 982 1030 } else if (packet->trace->format->get_erf_timestamp) { 983 1031 /* timestamp -> seconds */ 1032 uint64_t ts = 0; 984 1033 ts = packet->trace->format->get_erf_timestamp(packet); 985 1034 seconds = (ts>>32) + ((ts & UINT_MAX)*1.0 / UINT_MAX); 1035 } else if (packet->trace->format->get_timespec) { 1036 /* timespec -> seconds */ 1037 struct timespec ts; 1038 ts = packet->trace->format->get_timespec(packet); 1039 seconds = ts.tv_sec + ((ts.tv_nsec * 1.0) / 1000000000); 986 1040 } else if (packet->trace->format->get_timeval) { 987 1041 /* timeval -> seconds */ 1042 struct timeval tv; 988 1043 tv = packet->trace->format->get_timeval(packet); 989 1044 seconds = tv.tv_sec + ((tv.tv_usec * 1.0) / 1000000);
Note: See TracChangeset
for help on using the changeset viewer.