Browse Source

Merge pull request #26 from GuangCplusplus/master

bug fix for windows
pull/36/head
Luca Deri 6 years ago
committed by GitHub
parent
commit
e6e383e751
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      CMakeLists.txt
  2. 27
      benchmark.c
  3. 3
      edge.c
  4. 11
      edge_utils.c
  5. 7
      win32/CMakeLists.txt
  6. 2
      win32/n2n_win32.h

13
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})

27
benchmark.c

@ -19,12 +19,37 @@
#include "n2n_wire.h"
#include "n2n_transforms.h"
#include "n2n.h"
#ifdef __GNUC__
#include <sys/time.h>
#endif
#include <time.h>
#include <string.h>
#include <stdio.h>
#if defined(WIN32) && !defined(__GNUC__)
#include <windows.h>
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,

3
edge.c

@ -17,6 +17,9 @@
*/
#include "n2n.h"
#ifdef WIN32
#include <sys/stat.h>
#endif
#define N2N_NETMASK_STR_SIZE 16 /* dotted decimal 12 numbers + 3 dots */
#define N2N_MACNAMSIZ 18 /* AA:BB:CC:DD:EE:FF + NULL*/

11
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);
@ -1629,7 +1630,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;

7
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)

2
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)

Loading…
Cancel
Save