Ignore:
Timestamp:
01/17/07 16:51:08 (15 years ago)
Author:
Brendon Jones <brendonj@…>
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:
d5a27e8
Parents:
8d504c1
Message:

Windows portability fixes.

Windows doesn't have a gettimeofday function, provided an alternate
path that uses _ftime with _timeb structs. This only provides
millisecond resolution rather than microsecond.

Added a few checks to make sure headers that aren't present in
Windows don't get included.

Added new files to the Visual Studio project/solution.

Modified the windows config file to include a few more #defines that
were needed to make pcap support build properly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_helper.c

    r4bd8a5b r6ed6c4a  
    4848#  include <io.h>
    4949#  include <share.h>
    50 define snprintf sprintf_s
     50include <sys/timeb.h>
    5151
    5252struct libtrace_eventobj_t trace_event_device(struct libtrace_t *trace, struct libtrace_packet_t *packet) {
     
    9494        double ts;
    9595        double now;
     96#ifdef WIN32
     97        struct __timeb64 tstruct;
     98#else
    9699        struct timeval stv;
     100#endif
    97101
    98102        if (!trace->event.packet) {
     
    113117
    114118        ts=trace_get_seconds(trace->event.packet);
     119
     120        /* Get the adjusted current time */
     121#ifdef WIN32
     122        _ftime64(&tstruct);
     123        now = tstruct.time +
     124                ((double)tstruct.millitm / 1000.0);
     125#else
     126        gettimeofday(&stv, NULL);
     127        now = stv.tv_sec +
     128                ((double)stv.tv_usec / 1000000.0);
     129#endif
     130
    115131        if (fabs(trace->event.tdelta)<1e-9) {
    116                 /* Get the adjusted current time */
    117                 gettimeofday(&stv, NULL);
    118                 now = stv.tv_sec +
    119                         ((double)stv.tv_usec / 1000000.0);
    120132                /* adjust for trace delta */
    121133                now -= trace->event.tdelta;
     
    132144                }
    133145        } else {
    134                 gettimeofday(&stv, NULL);
    135146                /* work out the difference between the
    136147                 * start of trace replay, and the first
    137148                 * packet in the trace
    138149                 */
    139                 trace->event.tdelta = stv.tv_sec +
    140                         ((double)stv.tv_usec / 1000000.0);
    141                 trace->event.tdelta -= ts;
     150                trace->event.tdelta = now - ts;
    142151        }
    143152
Note: See TracChangeset for help on using the changeset viewer.