mirror of
https://github.com/ntop/n2n.git
synced 2026-10-19 16:16:12 +00:00
Simplify build system by using standard macro
Most environments have predefined macros that identify the environment
to the source code. If we use these macros instead of defining our own
then there is one less parameter difference to keep track of with
different builds
cf:
http://web.archive.org/web/20191012035921/http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
https://sourceforge.net/p/predef/wiki/OperatingSystems/
This commit is contained in:
+3
-3
@@ -58,7 +58,7 @@ static void help() {
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
BOOL WINAPI term_handler(DWORD sig)
|
||||
#else
|
||||
static void term_handler(int sig)
|
||||
@@ -75,7 +75,7 @@ static void term_handler(int sig)
|
||||
}
|
||||
|
||||
running = 0;
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
return(TRUE);
|
||||
#endif
|
||||
}
|
||||
@@ -349,7 +349,7 @@ int main(int argc, char* argv[]) {
|
||||
return(5);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
SetConsoleCtrlHandler(term_handler, TRUE);
|
||||
#else
|
||||
signal(SIGTERM, term_handler);
|
||||
|
||||
+7
-7
@@ -33,7 +33,7 @@
|
||||
#include "n2n_port_mapping.h" // for n2n_del_port_mapping, n2n_set_port_map...
|
||||
#include "random_numbers.h" // for n2n_rand, n2n_seed, n2n_srand
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <winsock.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
@@ -49,7 +49,7 @@
|
||||
#define INFO_INTERVAL 5
|
||||
|
||||
// REVISIT: may become obsolete
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO _fileno(stdin)
|
||||
#endif
|
||||
@@ -75,13 +75,13 @@ void set_term_handler(const void *handler) {
|
||||
signal(SIGTERM, handler);
|
||||
signal(SIGINT, handler);
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
SetConsoleCtrlHandler(handler, TRUE);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
BOOL WINAPI term_handler (DWORD sig) {
|
||||
#else
|
||||
static void term_handler (int sig) {
|
||||
@@ -98,7 +98,7 @@ static void term_handler (int sig) {
|
||||
}
|
||||
|
||||
keep_running = false;
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
@@ -113,7 +113,7 @@ SOCKET connect_to_management_port (n2n_portfwd_conf_t *ppp) {
|
||||
SOCKET ret;
|
||||
struct sockaddr_in sock_addr;
|
||||
|
||||
#if defined(WIN32)
|
||||
#ifdef _WIN32
|
||||
// Windows requires a call to WSAStartup() before it can work with sockets
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
@@ -184,7 +184,7 @@ int get_port_from_json (uint16_t *port, json_object_t *json, char *key, int tag,
|
||||
// PLATFORM-DEPENDANT CODE
|
||||
|
||||
|
||||
#if !defined(WIN32)
|
||||
#ifndef _WIN32
|
||||
// taken from https://web.archive.org/web/20170407122137/http://cc.byexamples.com/2007/04/08/non-blocking-user-input-in-loop-without-ncurses/
|
||||
int _kbhit () {
|
||||
|
||||
|
||||
+14
-14
@@ -38,7 +38,7 @@
|
||||
#include <linux/rtnetlink.h> // for RTA_DATA, rtmsg, RTA_GATEWAY, RTA_NEXT
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <winsock.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
@@ -51,7 +51,7 @@
|
||||
#include <sys/socket.h> // for send, socket, AF_INET, recv, connect
|
||||
#endif
|
||||
|
||||
#if defined (__linux__) || defined(WIN32) /* currently, Linux and Windows only */
|
||||
#if defined (__linux__) || defined(_WIN32) /* currently, Linux and Windows only */
|
||||
|
||||
|
||||
#define WITH_ADDRESS 1
|
||||
@@ -74,7 +74,7 @@
|
||||
#define AUTO_DETECT 1
|
||||
|
||||
// REVISIT: may become obsolete
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO _fileno(stdin)
|
||||
#endif
|
||||
@@ -117,7 +117,7 @@ int is_privileged (void) {
|
||||
|
||||
return euid == 0;
|
||||
|
||||
#elif defined(WIN32)
|
||||
#elif defined(_WIN32)
|
||||
// taken from https://stackoverflow.com/a/10553065
|
||||
int result;
|
||||
DWORD rc;
|
||||
@@ -148,13 +148,13 @@ void set_term_handler(const void *handler) {
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGTERM, handler);
|
||||
signal(SIGINT, handler);
|
||||
#elif defined(WIN32)
|
||||
#elif defined(_WIN32)
|
||||
SetConsoleCtrlHandler(handler, TRUE);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if !defined(WIN32)
|
||||
#ifndef _WIN32
|
||||
static void term_handler (int sig) {
|
||||
#else
|
||||
BOOL WINAPI term_handler (DWORD sig) {
|
||||
@@ -171,7 +171,7 @@ BOOL WINAPI term_handler (DWORD sig) {
|
||||
}
|
||||
|
||||
keep_running = false;
|
||||
#if defined(WIN32)
|
||||
#ifdef _WIN32
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
@@ -317,7 +317,7 @@ find_default_gateway_end:
|
||||
closesocket(sock);
|
||||
return ret;
|
||||
|
||||
#elif defined(WIN32)
|
||||
#elif defined(_WIN32)
|
||||
// taken from (and modified)
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-createipforwardentry
|
||||
|
||||
@@ -376,7 +376,7 @@ find_default_gateway_end:
|
||||
// PLATFORM-DEPENDANT CODE
|
||||
|
||||
|
||||
#if defined(WIN32)
|
||||
#ifdef _WIN32
|
||||
DWORD get_interface_index (struct in_addr addr) {
|
||||
// taken from (and modified)
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-createipforwardentry
|
||||
@@ -496,7 +496,7 @@ void handle_route (n2n_route_t* in_route, int verb) {
|
||||
|
||||
closesocket(sock);
|
||||
|
||||
#elif defined(WIN32)
|
||||
#elif defined(_WIN32)
|
||||
// REVISIT: use 'CreateIpForwardEntry()' and 'DeleteIpForwardEntry()' [iphlpapi.h]
|
||||
char c_net_addr[32];
|
||||
char c_gateway[32];
|
||||
@@ -573,7 +573,7 @@ SOCKET connect_to_management_port (n2n_route_conf_t *rrr) {
|
||||
SOCKET ret;
|
||||
struct sockaddr_in sock_addr;
|
||||
|
||||
#if defined(WIN32)
|
||||
#ifdef _WIN32
|
||||
// Windows requires a call to WSAStartup() before it can work with sockets
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
@@ -643,7 +643,7 @@ int get_addr_from_json (struct in_addr *addr, json_object_t *json, char *key, in
|
||||
// PLATFORM-DEPENDANT CODE
|
||||
|
||||
|
||||
#if !defined(WIN32)
|
||||
#ifndef _WIN32
|
||||
// taken from https://web.archive.org/web/20170407122137/http://cc.byexamples.com/2007/04/08/non-blocking-user-input-in-loop-without-ncurses/
|
||||
int _kbhit () {
|
||||
|
||||
@@ -1088,7 +1088,7 @@ end_route_tool:
|
||||
}
|
||||
|
||||
|
||||
#else /* if defined(__linux__) || defined(WIN32) -- currently, Linux and Windows only */
|
||||
#else /* if defined(__linux__) || defined(_WIN32) -- currently, Linux and Windows only */
|
||||
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
@@ -1100,4 +1100,4 @@ int main (int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
|
||||
#endif /* if defined (__linux__) || defined(WIN32) -- currently, Linux and Windows only */
|
||||
#endif /* if defined (__linux__) || defined(_WIN32) -- currently, Linux and Windows only */
|
||||
|
||||
Reference in New Issue
Block a user