mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-25 11:05:15 +00:00
Added windows gettimeofday function and timeval macros
This commit is contained in:
parent
c48822dfbe
commit
33525e5086
@ -25,6 +25,7 @@ typedef unsigned int in_addr_t;
|
|||||||
#include <windns.h>
|
#include <windns.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include <iphlpapi.h>
|
#include <iphlpapi.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
/* Missing from the mingw headers */
|
/* Missing from the mingw headers */
|
||||||
#ifndef DNS_TYPE_SRV
|
#ifndef DNS_TYPE_SRV
|
||||||
@ -91,6 +92,84 @@ struct ip
|
|||||||
struct in_addr ip_src, ip_dst; /* source and dest address */
|
struct in_addr ip_src, ip_dst; /* source and dest address */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* windows gettimeofday from https://gist.github.com/ugovaretto/5875385 */
|
||||||
|
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
|
||||||
|
#define DELTA_EPOCH_IN_MICROSECS 116444736000000000Ui64
|
||||||
|
#else
|
||||||
|
#define DELTA_EPOCH_IN_MICROSECS 116444736000000000ULL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Convenience macros for operations on timevals.
|
||||||
|
NOTE: `timercmp' does not work for >= or <=. */
|
||||||
|
#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
|
||||||
|
#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
|
||||||
|
#define timercmp(a, b, CMP) \
|
||||||
|
(((a)->tv_sec == (b)->tv_sec) ? \
|
||||||
|
((a)->tv_usec CMP (b)->tv_usec) : \
|
||||||
|
((a)->tv_sec CMP (b)->tv_sec))
|
||||||
|
#define timeradd(a, b, result) \
|
||||||
|
do { \
|
||||||
|
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
|
||||||
|
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
|
||||||
|
if ((result)->tv_usec >= 1000000) \
|
||||||
|
{ \
|
||||||
|
++(result)->tv_sec; \
|
||||||
|
(result)->tv_usec -= 1000000; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#define timersub(a, b, result) \
|
||||||
|
do { \
|
||||||
|
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
||||||
|
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
||||||
|
if ((result)->tv_usec < 0) { \
|
||||||
|
--(result)->tv_sec; \
|
||||||
|
(result)->tv_usec += 1000000; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
struct timezone
|
||||||
|
{
|
||||||
|
int tz_minuteswest; /* minutes W of Greenwich */
|
||||||
|
int tz_dsttime; /* type of dst correction */
|
||||||
|
};
|
||||||
|
|
||||||
|
inline int
|
||||||
|
gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||||
|
{
|
||||||
|
FILETIME ft;
|
||||||
|
unsigned __int64 tmpres = 0;
|
||||||
|
static int tzflag = 0;
|
||||||
|
|
||||||
|
if (NULL != tv)
|
||||||
|
{
|
||||||
|
GetSystemTimeAsFileTime(&ft);
|
||||||
|
|
||||||
|
tmpres |= ft.dwHighDateTime;
|
||||||
|
tmpres <<= 32;
|
||||||
|
tmpres |= ft.dwLowDateTime;
|
||||||
|
|
||||||
|
/* convert into microseconds */
|
||||||
|
tmpres /= 10;
|
||||||
|
/* converting file time to unix epoch */
|
||||||
|
tmpres -= DELTA_EPOCH_IN_MICROSECS;
|
||||||
|
tv->tv_sec = (long) (tmpres / 1000000UL);
|
||||||
|
tv->tv_usec = (long) (tmpres % 1000000UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL != tz)
|
||||||
|
{
|
||||||
|
if (!tzflag)
|
||||||
|
{
|
||||||
|
_tzset();
|
||||||
|
tzflag++;
|
||||||
|
}
|
||||||
|
tz->tz_minuteswest = _timezone / 60;
|
||||||
|
tz->tz_dsttime = _daylight;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
DWORD WINAPI tun_reader(LPVOID arg);
|
DWORD WINAPI tun_reader(LPVOID arg);
|
||||||
struct tun_data {
|
struct tun_data {
|
||||||
HANDLE tun;
|
HANDLE tun;
|
||||||
|
Loading…
Reference in New Issue
Block a user