diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_includes.h | 2 | ||||
-rw-r--r-- | src/lib/ndpi_classify.c | 27 | ||||
-rw-r--r-- | src/lib/third_party/src/ahocorasick.c | 2 | ||||
-rw-r--r-- | src/lib/third_party/src/gcrypt_light.c | 2 | ||||
-rw-r--r-- | src/lib/third_party/src/ndpi_patricia.c | 2 | ||||
-rw-r--r-- | src/lib/third_party/src/strptime.c | 2 |
6 files changed, 31 insertions, 6 deletions
diff --git a/src/include/ndpi_includes.h b/src/include/ndpi_includes.h index 64cbb48d6..27580a45e 100644 --- a/src/include/ndpi_includes.h +++ b/src/include/ndpi_includes.h @@ -34,7 +34,7 @@ #include <limits.h> #include <stdbool.h> -#ifdef WIN32 +#if defined(WIN32) || defined(_MSC_VER) #include "ndpi_win32.h" #else #include <sys/types.h> diff --git a/src/lib/ndpi_classify.c b/src/lib/ndpi_classify.c index 5c4fb2119..91769edee 100644 --- a/src/lib/ndpi_classify.c +++ b/src/lib/ndpi_classify.c @@ -680,6 +680,31 @@ ndpi_timeval_to_microseconds(pkt_timeval ts) return usec + sec * 1000 * 1000;; } +/* **************************************** */ + +#if defined(WIN32) || defined(_MSC_VER) +int gettimeofday(struct timeval* tp, struct timezone* tzp) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) + // until 00:00:00 January 1, 1970 + static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + time = ((uint64_t)file_time.dwLowDateTime); + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long)((time - EPOCH) / 10000000L); + tp->tv_usec = (long)(system_time.wMilliseconds * 1000); + return 0; +} +#endif + void ndpi_log_timestamp(char *log_ts, uint32_t log_ts_len) { @@ -690,7 +715,7 @@ ndpi_log_timestamp(char *log_ts, uint32_t log_ts_len) gettimeofday(&tv, NULL); nowtime = tv.tv_sec; -#ifdef WIN32 +#if defined(WIN32) || defined(_MSC_VER) /* localtime() on Windows is thread-safe */ struct tm * nowtm_r_ptr = localtime(&nowtime); nowtm_r = *nowtm_r_ptr; diff --git a/src/lib/third_party/src/ahocorasick.c b/src/lib/third_party/src/ahocorasick.c index 6f542ed77..71b414558 100644 --- a/src/lib/third_party/src/ahocorasick.c +++ b/src/lib/third_party/src/ahocorasick.c @@ -24,7 +24,7 @@ #include <stdlib.h> #include <string.h> #include <ctype.h> -#ifndef WIN32 +#if !defined(WIN32) && !defined(_MSC_VER) #include <unistd.h> #else #define __SIZEOF_LONG__ 4 diff --git a/src/lib/third_party/src/gcrypt_light.c b/src/lib/third_party/src/gcrypt_light.c index 8ad142576..9f3665698 100644 --- a/src/lib/third_party/src/gcrypt_light.c +++ b/src/lib/third_party/src/gcrypt_light.c @@ -1,6 +1,6 @@ #include <stdint.h> -#ifndef WIN32 +#if !defined(WIN32) && !defined(_MSC_VER) #include <unistd.h> #endif #include <string.h> diff --git a/src/lib/third_party/src/ndpi_patricia.c b/src/lib/third_party/src/ndpi_patricia.c index 3da6836a5..b4cc76964 100644 --- a/src/lib/third_party/src/ndpi_patricia.c +++ b/src/lib/third_party/src/ndpi_patricia.c @@ -48,7 +48,7 @@ #include <stdlib.h> /* free, atol, calloc */ #include <string.h> /* memcpy, strchr, strlen */ #include <sys/types.h> /* BSD: for inet_addr */ -#ifndef WIN32 +#if !defined(WIN32) && !defined(_MSC_VER) #include <sys/socket.h> /* BSD, Linux: for inet_addr */ #include <netinet/in.h> /* BSD, Linux: for inet_addr */ #include <arpa/inet.h> /* BSD, Linux, Solaris: for inet_addr */ diff --git a/src/lib/third_party/src/strptime.c b/src/lib/third_party/src/strptime.c index 42cc13cf2..e1c740456 100644 --- a/src/lib/third_party/src/strptime.c +++ b/src/lib/third_party/src/strptime.c @@ -35,7 +35,7 @@ This file is used to implement the strptime API call that is missing on Windows */ -#ifdef WIN32 +#if defined(WIN32) || defined(_MSC_VER) #include "ndpi_main.h" |