Changeset 6ed6c4a for lib


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.

Location:
lib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • lib/format_erf.c

    r4bd8a5b r6ed6c4a  
    4848#  include <share.h>
    4949#  define PATH_MAX _MAX_PATH
    50 #  define snprintf sprintf_s
    5150#else
    5251#  include <netdb.h>
  • 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
  • lib/format_legacy.c

    r4bd8a5b r6ed6c4a  
    4747#  include <io.h>
    4848#  include <share.h>
    49 #  define snprintf sprintf_s
    5049#endif
    5150
  • lib/format_wag.c

    r4746c71 r6ed6c4a  
    114114                return 0;
    115115        }
    116 #endif
    117116        trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,
    118117                        "%s is not a valid char device",
    119118                        libtrace->uridata);
     119#else
     120        trace_set_err(libtrace, TRACE_ERR_UNSUPPORTED,
     121                        "WAG cards are not supported in Windows");
     122#endif
    120123        return -1;
    121124}
     
    187190static int wag_pause_input(libtrace_t *libtrace)
    188191{
     192#ifndef WIN32
    189193        if (ioctl (INPUT.fd, CAPTURE_RADIOON, 0) == -1) {
    190194                trace_set_err(libtrace, errno,
     
    193197        close(INPUT.fd);
    194198        return 0;
     199#endif
     200        trace_set_err(libtrace, TRACE_ERR_UNSUPPORTED,
     201                                "WAG cards are not supported in Windows");
     202        return -1;
    195203}
    196204
    197205static int wag_fin_input(libtrace_t *libtrace) {
     206#ifndef WIN32
    198207        ioctl (INPUT.fd, CAPTURE_RADIOON, 0);
     208#endif
    199209        free(libtrace->format_data);
    200210        return 0;
  • lib/libtrace.h.in

    re1868fb r6ed6c4a  
    5757
    5858#include <sys/types.h>
     59#ifndef WIN32
    5960#include <sys/time.h>
     61#endif
    6062
    6163#ifdef _MSC_VER
  • lib/libtrace_int.h

    r4746c71 r6ed6c4a  
    4242
    4343#ifdef _MSC_VER
     44// warning: deprecated function
    4445#pragma warning(disable:4996)
     46// warning: benign redefinitions of types
     47#pragma warning(disable:4142)
    4548#endif
    4649
     
    371374void *trace_get_payload_from_linux_sll(void *, uint16_t *, uint32_t *);
    372375void *trace_get_payload_from_pos(void *, uint16_t *, uint32_t *);
    373 void *trace_get_payload_from_atm(void *, uint8_t *, uint32_t *);
     376DLLEXPORT void *trace_get_payload_from_atm(void *, uint8_t *, uint32_t *);
    374377
    375378uint64_t byteswap64(uint64_t num);
  • lib/libtraceio.h

    r306f91c r6ed6c4a  
    55#define LIBTRACEIO_H 1
    66#include "config.h"
     7#ifndef WIN32
    78#include <inttypes.h>
     9#include <unistd.h>
     10#endif
    811
    9 #include <unistd.h>
    1012
    1113typedef struct libtrace_io_t libtrace_io_t;
  • lib/trace.c

    re1868fb r6ed6c4a  
    5050#include <sys/stat.h>
    5151#include <sys/types.h>
     52#ifndef WIN32
    5253#include <sys/socket.h>
     54#endif
    5355#include <stdarg.h>
    5456
     
    8284
    8385#include <time.h>
     86#ifdef WIN32
     87#include <sys/timeb.h>
     88#endif
    8489
    8590#include "libtrace.h"
     
    14271432        static libtrace_t *deadtrace=NULL;
    14281433        libtrace_pcapfile_pkt_hdr_t hdr;
     1434#ifdef WIN32
     1435        struct _timeb tstruct;
     1436#else
    14291437        struct timeval tv;
    1430         if (NULL == deadtrace) deadtrace=trace_create_dead("pcapfile");
     1438#endif
     1439
     1440        if (NULL == deadtrace)
     1441                deadtrace=trace_create_dead("pcapfile");
     1442
     1443#ifdef WIN32
     1444        _ftime(&tstruct);
     1445        hdr.ts_sec=tstruct.time;
     1446        hdr.ts_usec=tstruct.millitm * 1000;
     1447#else
    14311448        gettimeofday(&tv,NULL);
    14321449        hdr.ts_sec=tv.tv_sec;
    14331450        hdr.ts_usec=tv.tv_usec;
     1451#endif
     1452
    14341453        hdr.caplen=len;
    14351454        hdr.wirelen=len;
Note: See TracChangeset for help on using the changeset viewer.