Browse Source

Fix cmake compilation errors.

1. CMakeLists.txt added to automatically obtain the revised version number from the git repository.
2. Adjusted some header files to fix Windows platform compilation errors.
3. Eliminate some compilation warnings.
pull/289/head
fengdaolong 4 years ago
parent
commit
f5accc8221
  1. 106
      CMakeLists.txt
  2. 1
      include/edge_utils_win32.h
  3. 6
      include/n2n.h
  4. 9
      src/edge_utils.c
  5. 2
      src/edge_utils_win32.c
  6. 9
      src/n2n.c
  7. 3
      src/sn.c
  8. 2
      win32/wintap.c

106
CMakeLists.txt

@ -1,10 +1,24 @@
project(n2n) project(n2n)
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
include(CheckFunctionExists) include(CheckFunctionExists)
SET(CMAKE_VERBOSE_MAKEFILE ON)
# N2n information # N2n information
set(N2N_VERSION 2.5.1) execute_process(
COMMAND git rev-list --count HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REV
)
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_ID
)
string(REGEX REPLACE "\n$" "" GIT_REV "${GIT_REV}")
string(REGEX REPLACE "\n$" "" GIT_ID "${GIT_ID}")
set(N2N_VERSION "2.7.0.r${GIT_REV}.${GIT_ID}")
set(N2N_OSNAME ${CMAKE_SYSTEM}) set(N2N_OSNAME ${CMAKE_SYSTEM})
MESSAGE(STATUS "Build from git rev: ${N2N_VERSION}")
# N2n specific params # N2n specific params
OPTION(N2N_OPTION_AES "USE AES" ON) OPTION(N2N_OPTION_AES "USE AES" ON)
@ -22,8 +36,11 @@ add_definitions(-DGIT_RELEASE="" -DPACKAGE_VERSION="${N2N_VERSION}" -DPACKAGE_OS
add_definitions(-DN2N_VERSION="${N2N_VERSION}" -DN2N_OSNAME="${N2N_OSNAME}") add_definitions(-DN2N_VERSION="${N2N_VERSION}" -DN2N_OSNAME="${N2N_OSNAME}")
if(N2N_OPTION_AES) if(N2N_OPTION_AES)
find_package(OpenSSL REQUIRED) if(NOT DEFINED WIN32)
add_definitions(-DN2N_HAVE_AES) find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
endif(NOT DEFINED WIN32)
add_definitions(-DN2N_HAVE_AES)
endif(N2N_OPTION_AES) endif(N2N_OPTION_AES)
if(NOT DEFINED CMAKE_BUILD_TYPE) if(NOT DEFINED CMAKE_BUILD_TYPE)
@ -42,7 +59,10 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g")
# Release # Release
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
endif() endif(DEFINED UNIX)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
## DEBUG FOR CMAKE ## DEBUG FOR CMAKE
#message(${N2N_VERSION}) #message(${N2N_VERSION})
@ -51,51 +71,67 @@ endif()
#message(${N2N_OPTION_AES}) #message(${N2N_OPTION_AES})
## DEBUG FOR CMAKE ## DEBUG FOR CMAKE
INCLUDE_DIRECTORIES(.)
INCLUDE_DIRECTORIES(include)
if(DEFINED WIN32)
INCLUDE_DIRECTORIES(win32)
INCLUDE_DIRECTORIES("D:/Program Files/MinGW/opt/include/" "D:/Program Files/MinGW/x86_64-w64-mingw32/include/")
LINK_DIRECTORIES("D:/Program Files/MinGW/opt/lib/" "D:/Program Files/MinGW/x86_64-w64-mingw32/lib/")
endif(DEFINED WIN32)
# Add SHARED to build DLL # Add SHARED to build DLL
add_library(n2n n2n.c #aux_source_directory(./src N2N_DIR_SRCS)
edge_utils.c #add_library(n2n STATIC ${N2N_DIR_SRCS})
sn_utils.c add_library(n2n
wire.c src/n2n.c
minilzo.c src/edge_utils.c
twofish.c src/sn_utils.c
transform_null.c src/wire.c
transform_tf.c src/minilzo.c
transform_aes.c src/twofish.c
transform_cc20.c src/transform_null.c
transform_speck.c src/transform_tf.c
speck.c src/transform_aes.c
random_numbers.c src/transform_cc20.c
pearson.c src/transform_speck.c
header_encryption.c src/speck.c
tuntap_freebsd.c src/random_numbers.c
tuntap_netbsd.c src/pearson.c
tuntap_linux.c src/header_encryption.c
tuntap_osx.c src/tuntap_freebsd.c
src/tuntap_netbsd.c
src/tuntap_linux.c
src/tuntap_osx.c
) )
if(DEFINED WIN32) if(DEFINED WIN32)
add_subdirectory(win32) add_library(edge_utils_win32 src/edge_utils_win32.c)
target_link_libraries(n2n n2n_win32) add_subdirectory(win32)
target_link_libraries(n2n edge_utils_win32 n2n_win32 )
endif(DEFINED WIN32) endif(DEFINED WIN32)
if(N2N_OPTION_AES) if(N2N_OPTION_AES)
target_link_libraries(n2n ${OPENSSL_LIBRARIES}) if(DEFINED WIN32)
include_directories(${OPENSSL_INCLUDE_DIR}) target_link_libraries(n2n crypto)
else()
target_link_libraries(n2n ${OPENSSL_LIBRARIES})
endif(DEFINED WIN32)
endif(N2N_OPTION_AES) endif(N2N_OPTION_AES)
add_executable(edge edge.c) add_executable(edge src/edge.c)
target_link_libraries(edge n2n) target_link_libraries(edge n2n)
add_executable(supernode sn.c) add_executable(supernode src/sn.c)
target_link_libraries(supernode n2n) target_link_libraries(supernode n2n)
add_executable(example_edge_embed_quick_edge_init example_edge_embed_quick_edge_init.c) add_executable(example_edge_embed_quick_edge_init src/example_edge_embed_quick_edge_init.c)
target_link_libraries(example_edge_embed_quick_edge_init n2n) target_link_libraries(example_edge_embed_quick_edge_init n2n)
add_executable(example_edge_embed example_edge_embed.c) add_executable(example_edge_embed src/example_edge_embed.c)
target_link_libraries(example_edge_embed n2n) target_link_libraries(example_edge_embed n2n)
add_executable(example_sn_embed example_sn_embed.c) add_executable(example_sn_embed src/example_sn_embed.c)
target_link_libraries(example_sn_embed n2n) target_link_libraries(example_sn_embed n2n)
if(NOT DEFINED WIN32) if(NOT DEFINED WIN32)
@ -115,8 +151,6 @@ install(TARGETS edge supernode
) )
# Tools # Tools
include_directories(.)
add_executable(n2n-benchmark tools/benchmark.c) add_executable(n2n-benchmark tools/benchmark.c)
target_link_libraries(n2n-benchmark n2n ${OPENSSL_LIBRARIES}) target_link_libraries(n2n-benchmark n2n ${OPENSSL_LIBRARIES})
@ -130,8 +164,8 @@ if(PCAP_LIB)
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE) check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
IF(HAVE_PCAP_IMMEDIATE_MODE) IF(HAVE_PCAP_IMMEDIATE_MODE)
ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE") ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE")
ENDIF() ENDIF(HAVE_PCAP_IMMEDIATE_MODE)
endif() endif(PCAP_LIB)
install(TARGETS n2n-benchmark RUNTIME DESTINATION bin) install(TARGETS n2n-benchmark RUNTIME DESTINATION bin)

1
include/edge_utils_win32.h

@ -19,6 +19,7 @@
#ifdef WIN32 #ifdef WIN32
#include <process.h> #include <process.h>
#include <n2n.h>
/* Multicast peers discovery disabled due to https://github.com/ntop/n2n/issues/65 */ /* Multicast peers discovery disabled due to https://github.com/ntop/n2n/issues/65 */
#define SKIP_MULTICAST_PEERS_DISCOVERY #define SKIP_MULTICAST_PEERS_DISCOVERY

6
include/n2n.h

@ -126,7 +126,6 @@ typedef struct ether_hdr ether_hdr_t;
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/ip.h> #include <netinet/ip.h>
#include <netinet/udp.h> #include <netinet/udp.h>
#include <signal.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
@ -140,12 +139,13 @@ typedef struct ether_hdr ether_hdr_t;
#include <openssl/crypto.h> #include <openssl/crypto.h>
#endif #endif
#include "minilzo.h"
#include "n2n_define.h"
#define closesocket(a) close(a) #define closesocket(a) close(a)
#endif /* #ifndef WIN32 */ #endif /* #ifndef WIN32 */
#include "minilzo.h"
#include "n2n_define.h"
#include <signal.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include "uthash.h" #include "uthash.h"

9
src/edge_utils.c

@ -797,10 +797,10 @@ static void send_query_peer( n2n_edge_t * eee,
traceEvent( TRACE_DEBUG, "send QUERY_PEER to supernode" ); traceEvent( TRACE_DEBUG, "send QUERY_PEER to supernode" );
if(eee->conf.header_encryption == HEADER_ENCRYPTION_ENABLED) if(eee->conf.header_encryption == HEADER_ENCRYPTION_ENABLED){
packet_header_encrypt (pktbuf, idx, eee->conf.header_encryption_ctx, packet_header_encrypt (pktbuf, idx, eee->conf.header_encryption_ctx,
eee->conf.header_iv_ctx, pearson_hash_16 (pktbuf, idx)); eee->conf.header_iv_ctx, pearson_hash_16 (pktbuf, idx));
}
sendto_sock( eee->udp_sock, pktbuf, idx, &(eee->supernode) ); sendto_sock( eee->udp_sock, pktbuf, idx, &(eee->supernode) );
} }
@ -1082,7 +1082,7 @@ static int handle_PACKET(n2n_edge_t * eee,
/* Check if it is a routed packet */ /* Check if it is a routed packet */
if((ntohs(eh->type) == 0x0800) && (eth_size >= ETH_FRAMESIZE + IP4_MIN_SIZE)) { if((ntohs(eh->type) == 0x0800) && (eth_size >= ETH_FRAMESIZE + IP4_MIN_SIZE)) {
uint32_t *dst = (uint32_t*)&eth_payload[ETH_FRAMESIZE + IP4_DSTOFFSET]; uint32_t *dst = (uint32_t*)&eth_payload[ETH_FRAMESIZE + IP4_DSTOFFSET];
u_int8_t *dst_mac = (u_int8_t*)eth_payload; uint8_t *dst_mac = (uint8_t*)eth_payload;
/* Note: all elements of the_ip are in network order */ /* Note: all elements of the_ip are in network order */
if(!memcmp(dst_mac, broadcast_mac, 6)) if(!memcmp(dst_mac, broadcast_mac, 6))
@ -1868,6 +1868,7 @@ int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
#endif #endif
#ifdef WIN32 #ifdef WIN32
#include "edge_utils_win32.h"
struct tunread_arg arg; struct tunread_arg arg;
arg.eee = eee; arg.eee = eee;
arg.keep_running = keep_running; arg.keep_running = keep_running;
@ -2045,7 +2046,7 @@ static int edge_init_sockets(n2n_edge_t *eee, int udp_local_port, int mgmt_port,
/* https://www.tucny.com/Home/dscp-tos */ /* https://www.tucny.com/Home/dscp-tos */
sockopt = tos; sockopt = tos;
if(setsockopt(eee->udp_sock, IPPROTO_IP, IP_TOS, &sockopt, sizeof(sockopt)) == 0) if(setsockopt(eee->udp_sock, IPPROTO_IP, IP_TOS, (char *)&sockopt, sizeof(sockopt)) == 0)
traceEvent(TRACE_NORMAL, "TOS set to 0x%x", tos); traceEvent(TRACE_NORMAL, "TOS set to 0x%x", tos);
else else
traceEvent(TRACE_ERROR, "Could not set TOS 0x%x[%d]: %s", tos, errno, strerror(errno)); traceEvent(TRACE_ERROR, "Could not set TOS 0x%x[%d]: %s", tos, errno, strerror(errno));

2
src/edge_utils_win32.c

@ -26,7 +26,7 @@ static DWORD* tunReadThread(LPVOID lpArg) {
struct tunread_arg *arg = (struct tunread_arg*)lpArg; struct tunread_arg *arg = (struct tunread_arg*)lpArg;
while(*arg->keep_running) while(*arg->keep_running)
readFromTAPSocket(arg->eee); edge_read_from_tap(arg->eee);
return((DWORD*)NULL); return((DWORD*)NULL);
} }

9
src/n2n.c

@ -92,7 +92,7 @@ SOCKET open_socket(int local_port, int bind_any) {
#endif #endif
sockopt = 1; sockopt = 1;
setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt)); setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&sockopt, sizeof(sockopt));
memset(&local_address, 0, sizeof(local_address)); memset(&local_address, 0, sizeof(local_address));
local_address.sin_family = AF_INET; local_address.sin_family = AF_INET;
@ -145,9 +145,7 @@ void traceEvent(int eventTraceLevel, char* file, int line, char * format, ...) {
char theDate[N2N_TRACE_DATESIZE]; char theDate[N2N_TRACE_DATESIZE];
char *extra_msg = ""; char *extra_msg = "";
time_t theTime = time(NULL); time_t theTime = time(NULL);
#ifdef WIN32
int i; int i;
#endif
/* We have two paths - one if we're logging, one if we aren't /* We have two paths - one if we're logging, one if we aren't
* Note that the no-log case is those systems which don't support it(WIN32), * Note that the no-log case is those systems which don't support it(WIN32),
@ -179,7 +177,8 @@ void traceEvent(int eventTraceLevel, char* file, int line, char * format, ...) {
snprintf(out_buf, sizeof(out_buf), "%s%s", extra_msg, buf); snprintf(out_buf, sizeof(out_buf), "%s%s", extra_msg, buf);
syslog(LOG_INFO, "%s", out_buf); syslog(LOG_INFO, "%s", out_buf);
} else { } else {
snprintf(out_buf, sizeof(out_buf), "%s [%s:%d] %s%s", theDate, file, line, extra_msg, buf); for(i=strlen(file)-1; i>0; i--) if(file[i] == '/') { i++; break; };
snprintf(out_buf, sizeof(out_buf), "%s [%s:%d] %s%s", theDate, &file[i], line, extra_msg, buf);
#ifdef __ANDROID_NDK__ #ifdef __ANDROID_NDK__
switch (eventTraceLevel) { switch (eventTraceLevel) {
case 0: // ERROR case 0: // ERROR
@ -316,7 +315,7 @@ void hexdump(const uint8_t * buf, size_t len)
void print_n2n_version() { void print_n2n_version() {
printf("Welcome to n2n v.%s for %s\n" printf("Welcome to n2n v.%s for %s\n"
"Built on %s\n" "Built on %s\n"
"Copyright 2007-19 - ntop.org and contributors\n\n", "Copyright 2007-2020 - ntop.org and contributors\n\n",
GIT_RELEASE, PACKAGE_OSNAME, PACKAGE_BUILDDATE); GIT_RELEASE, PACKAGE_OSNAME, PACKAGE_BUILDDATE);
} }

3
src/sn.c

@ -21,9 +21,6 @@
#include "n2n.h" #include "n2n.h"
#include "header_encryption.h" #include "header_encryption.h"
#ifdef WIN32
#include <signal.h>
#endif
#define N2N_SN_LPORT_DEFAULT 7654 #define N2N_SN_LPORT_DEFAULT 7654
#define N2N_SN_PKTBUF_SIZE 2048 #define N2N_SN_PKTBUF_SIZE 2048

2
win32/wintap.c

@ -2,7 +2,7 @@
(C) 2007-09 - Luca Deri <deri@ntop.org> (C) 2007-09 - Luca Deri <deri@ntop.org>
*/ */
#include "../n2n.h" #include "n2n.h"
#include "n2n_win32.h" #include "n2n_win32.h"
/* ***************************************************** */ /* ***************************************************** */

Loading…
Cancel
Save