Re: [tcpdump-workers] gettimeofday() on Win32
(Blah blah blah wrong from address blah blah blah defeat duplicate message detection blah blah blah blah.) On Dec 3, 2005, at 8:07 AM, Gisle Vanem wrote: The recent (?) -G option requires gettimeofday() which isn't available on Win32. Attached is a patch to util.c which adds this function. It doesn't need gettimeofday(); time() is sufficient - and if that's available on Win32, that's a simpler fix. (Even if it's *not* available, it's simpler, as you don't have to extract the seconds part of the timeval structure, and don't have to fill it in on Win32.) I've checked in a change to make it use time(); we use time() elsewhere, so I assume it's available on Win32. - This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe.
Re: [tcpdump-workers] gettimeofday() on Win32
pls ignore prev. comment -> brain fart - checked in your patch - /hannes Gisle Vanem wrote: The recent (?) -G option requires gettimeofday() which isn't available on Win32. Attached is a patch to util.c which adds this function. --gv --- tcpdump-2005.12.03/util.cThu Jun 16 00:19:38 2005 +++ util.cSat Dec 03 17:01:05 2005 @@ -526,3 +526,44 @@ else printf("\\%03o", ch); } + +#ifdef WIN32 +/* + * Number of micro-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970). + * + * This assumes all Win32 compilers have 64-bit support. + */ +#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) || defined(__WATCOMC__) + #define DELTA_EPOCH_IN_USEC 116444736Ui64 +#else + #define DELTA_EPOCH_IN_USEC 116444736ULL +#endif + +static u_int64_t filetime_to_unix_epoch (const FILETIME *ft) +{ +u_int64_t res = (u_int64_t) ft->dwHighDateTime << 32; + +res |= ft->dwLowDateTime; +res /= 10; /* from 100 nano-sec periods to usec */ +res -= DELTA_EPOCH_IN_USEC; /* from Win epoch to Unix epoch */ +return (res); +} + +int gettimeofday (struct timeval *tv, void *tz _U_) +{ +FILETIME ft; +u_int64_t tim; + +if (!tv) { +errno = EINVAL; +return (-1); +} +GetSystemTimeAsFileTime (&ft); +tim = filetime_to_unix_epoch (&ft); +tv->tv_sec = (long) (tim / 100L); +tv->tv_usec = (long) (tim % 100L); +return (0); +} +#endif - This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe. - This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe. - This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe.
Re: [tcpdump-workers] gettimeofday() on Win32
would'nt it make sense to guard your private gettimeofday() function with #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) || defined(__WATCOMC__) /hannes Gisle Vanem wrote: The recent (?) -G option requires gettimeofday() which isn't available on Win32. Attached is a patch to util.c which adds this function. --gv --- tcpdump-2005.12.03/util.cThu Jun 16 00:19:38 2005 +++ util.cSat Dec 03 17:01:05 2005 @@ -526,3 +526,44 @@ else printf("\\%03o", ch); } + +#ifdef WIN32 +/* + * Number of micro-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970). + * + * This assumes all Win32 compilers have 64-bit support. + */ +#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) || defined(__WATCOMC__) + #define DELTA_EPOCH_IN_USEC 116444736Ui64 +#else + #define DELTA_EPOCH_IN_USEC 116444736ULL +#endif + +static u_int64_t filetime_to_unix_epoch (const FILETIME *ft) +{ +u_int64_t res = (u_int64_t) ft->dwHighDateTime << 32; + +res |= ft->dwLowDateTime; +res /= 10; /* from 100 nano-sec periods to usec */ +res -= DELTA_EPOCH_IN_USEC; /* from Win epoch to Unix epoch */ +return (res); +} + +int gettimeofday (struct timeval *tv, void *tz _U_) +{ +FILETIME ft; +u_int64_t tim; + +if (!tv) { +errno = EINVAL; +return (-1); +} +GetSystemTimeAsFileTime (&ft); +tim = filetime_to_unix_epoch (&ft); +tv->tv_sec = (long) (tim / 100L); +tv->tv_usec = (long) (tim % 100L); +return (0); +} +#endif - This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe. - This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe.
[tcpdump-workers] gettimeofday() on Win32
The recent (?) -G option requires gettimeofday() which isn't available on Win32. Attached is a patch to util.c which adds this function. --gv --- tcpdump-2005.12.03/util.c Thu Jun 16 00:19:38 2005 +++ util.c Sat Dec 03 17:01:05 2005 @@ -526,3 +526,44 @@ else printf("\\%03o", ch); } + +#ifdef WIN32 +/* + * Number of micro-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970). + * + * This assumes all Win32 compilers have 64-bit support. + */ +#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) || defined(__WATCOMC__) + #define DELTA_EPOCH_IN_USEC 116444736Ui64 +#else + #define DELTA_EPOCH_IN_USEC 116444736ULL +#endif + +static u_int64_t filetime_to_unix_epoch (const FILETIME *ft) +{ + u_int64_t res = (u_int64_t) ft->dwHighDateTime << 32; + + res |= ft->dwLowDateTime; + res /= 10; /* from 100 nano-sec periods to usec */ + res -= DELTA_EPOCH_IN_USEC; /* from Win epoch to Unix epoch */ + return (res); +} + +int gettimeofday (struct timeval *tv, void *tz _U_) +{ + FILETIME ft; + u_int64_t tim; + + if (!tv) { + errno = EINVAL; + return (-1); + } + GetSystemTimeAsFileTime (&ft); + tim = filetime_to_unix_epoch (&ft); + tv->tv_sec = (long) (tim / 100L); + tv->tv_usec = (long) (tim % 100L); + return (0); +} +#endif - This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe.