From d092751ec3e8236e56aedbe73fb9db8d972799cf Mon Sep 17 00:00:00 2001 From: Guang <891528583@qq.com> Date: Sun, 15 Jul 2018 14:32:56 +0800 Subject: [PATCH 1/2] fix cmake and build error --- CMakeLists.txt | 15 +++++++++------ benchmark.c | 27 ++++++++++++++++++++++++++- edge.c | 3 +++ edge_utils.c | 11 +++++++++-- win32/CMakeLists.txt | 7 ++++--- win32/n2n_win32.h | 2 +- 6 files changed, 52 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e23268..6f1d3f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,12 @@ set(N2N_VERSION 2.3.0) set(N2N_OSNAME ${CMAKE_SYSTEM}) # N2n specific params +OPTION(N2N_OPTION_AES "USE AES" ON) + +# Build information +OPTION(BUILD_SHARED_LIBS "BUILD Shared Library" OFF) + + if(NOT DEFINED N2N_OPTION_AES) set(N2N_OPTION_AES ON) endif(NOT DEFINED N2N_OPTION_AES) @@ -17,17 +23,13 @@ find_package(OpenSSL REQUIRED) add_definitions(-DN2N_HAVE_AES) endif(N2N_OPTION_AES) -# Build information -if(NOT DEFINED BUILD_SHARED_LIBS) -set(BUILD_SHARED_LIBS OFF) -endif(NOT DEFINED BUILD_SHARED_LIBS) - if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE None) endif(NOT DEFINED CMAKE_BUILD_TYPE) #set(CMAKE_BUILD_TYPE Debug) #set(CMAKE_BUILD_TYPE Release) +if (DEFINED UNIX) # None set(CMAKE_C_FLAGS "-Wall -Wshadow -Wpointer-arith -Wmissing-declarations -Wnested-externs") set(CMAKE_CXX_FLAGS "-Wall -Wshadow -Wpointer-arith -Wmissing-declarations -Wnested-externs") @@ -37,6 +39,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g") # Release set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") +endif() ## DEBUG FOR CMAKE #message(${N2N_VERSION}) @@ -47,7 +50,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") add_library(n2n n2n.c n2n_keyfile.c - edge_utils.c + edge_utils.c wire.c minilzo.c twofish.c diff --git a/benchmark.c b/benchmark.c index 519386e..30f80e4 100644 --- a/benchmark.c +++ b/benchmark.c @@ -19,12 +19,37 @@ #include "n2n_wire.h" #include "n2n_transforms.h" #include "n2n.h" - +#ifdef __GNUC__ #include +#endif #include #include #include + +#ifdef WIN32 +#include + +static int gettimeofday(struct timeval *tp, void *tzp) +{ + time_t clock; + struct tm tm; + SYSTEMTIME wtm; + GetLocalTime(&wtm); + tm.tm_year = wtm.wYear - 1900; + tm.tm_mon = wtm.wMonth - 1; + tm.tm_mday = wtm.wDay; + tm.tm_hour = wtm.wHour; + tm.tm_min = wtm.wMinute; + tm.tm_sec = wtm.wSecond; + tm.tm_isdst = -1; + clock = mktime(&tm); + tp->tv_sec = clock; + tp->tv_usec = wtm.wMilliseconds * 1000; + return (0); +} +#endif + uint8_t PKT_CONTENT[]={ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, diff --git a/edge.c b/edge.c index 2c09b6e..133d9bd 100644 --- a/edge.c +++ b/edge.c @@ -17,6 +17,9 @@ */ #include "n2n.h" +#ifdef WIN32 +#include +#endif #define N2N_NETMASK_STR_SIZE 16 /* dotted decimal 12 numbers + 3 dots */ #define N2N_MACNAMSIZ 18 /* AA:BB:CC:DD:EE:FF + NULL*/ diff --git a/edge_utils.c b/edge_utils.c index 7c97dda..b6c2d29 100644 --- a/edge_utils.c +++ b/edge_utils.c @@ -17,6 +17,7 @@ */ #include "n2n.h" +#include "lzoconf.h" #ifdef __ANDROID_NDK__ #include "android/edge_android.h" @@ -893,7 +894,7 @@ static void readFromMgmtSocket(n2n_edge_t * eee, int * keep_running) { "Statistics for edge\n"); msg_len += snprintf((char *)(udp_buf+msg_len), (N2N_PKT_BUF_SIZE-msg_len), - "uptime %lu\n", + "uptime %llu\n", time(NULL) - eee->start_time); msg_len += snprintf((char *)(udp_buf+msg_len), (N2N_PKT_BUF_SIZE-msg_len), @@ -920,7 +921,7 @@ static void readFromMgmtSocket(n2n_edge_t * eee, int * keep_running) { (unsigned int)peer_list_size(eee->known_peers)); msg_len += snprintf((char *)(udp_buf+msg_len), (N2N_PKT_BUF_SIZE-msg_len), - "last super:%lu(%ld sec ago) p2p:%lu(%ld sec ago)\n", + "last super:%llu(%lld sec ago) p2p:%llu(%lld sec ago)\n", eee->last_sup, (now-eee->last_sup), eee->last_p2p, (now-eee->last_p2p)); traceEvent(TRACE_DEBUG, "mgmt status sending: %s", udp_buf); @@ -1628,7 +1629,13 @@ const char *random_device_mac(void) mac[i] = ':'; continue; } +#ifdef WIN32 +#define random() rand() +#endif mac[i] = key[random() % sizeof(key)]; +#ifdef WIN32 +#undef random() +#endif } mac[sizeof(mac) - 1] = '\0'; return mac; diff --git a/win32/CMakeLists.txt b/win32/CMakeLists.txt index 0d97194..2e96b18 100644 --- a/win32/CMakeLists.txt +++ b/win32/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(n2n_win32 - win32/getopt1.c - win32/getopt.c - win32/wintap.c) + getopt1.c + getopt.c + wintap.c) +target_link_libraries(n2n_win32 PUBLIC ws2_32.lib) diff --git a/win32/n2n_win32.h b/win32/n2n_win32.h index 713933a..073aebc 100644 --- a/win32/n2n_win32.h +++ b/win32/n2n_win32.h @@ -44,7 +44,7 @@ typedef int ssize_t; typedef unsigned long in_addr_t; - +#undef EAFNOSUPPORT #define EAFNOSUPPORT WSAEAFNOSUPPORT #define MAX(a,b) (a > b ? a : b) #define MIN(a,b) (a < b ? a : b) From 3a7acee037aab8b5e91e441c724406ef9b1e65dd Mon Sep 17 00:00:00 2001 From: Guang <891528583@qq.com> Date: Sun, 15 Jul 2018 14:39:21 +0800 Subject: [PATCH 2/2] fix mingw build error --- benchmark.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark.c b/benchmark.c index 30f80e4..10492a4 100644 --- a/benchmark.c +++ b/benchmark.c @@ -27,7 +27,7 @@ #include -#ifdef WIN32 +#if defined(WIN32) && !defined(__GNUC__) #include static int gettimeofday(struct timeval *tp, void *tzp)