Windows changes

This commit is contained in:
Luca Deri
2022-10-06 11:58:16 +02:00
parent c4fb2a590e
commit e4dcec560e
6 changed files with 31 additions and 6 deletions
+1 -1
View File
@@ -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>
+26 -1
View File
@@ -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;
+1 -1
View File
@@ -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
+1 -1
View File
@@ -1,6 +1,6 @@
#include <stdint.h>
#ifndef WIN32
#if !defined(WIN32) && !defined(_MSC_VER)
#include <unistd.h>
#endif
#include <string.h>
+1 -1
View File
@@ -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 */
+1 -1
View File
@@ -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"