From 041233dc8b482863fb92b86d0e34a2a755d68c03 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 28 Jun 2023 22:39:27 +0100 Subject: [PATCH] Address more windows compile warnings --- src/edge_utils.c | 8 ++++---- src/n2n.c | 5 ++++- src/sn_utils.c | 2 +- tools/n2n-portfwd.c | 7 +++++++ tools/n2n-route.c | 8 +++++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/edge_utils.c b/src/edge_utils.c index 85ef0db..f256272 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -1140,7 +1140,7 @@ static void sendto_sock (n2n_edge_t *eee, const void * buf, // if the connection is tcp, i.e. not the regular sock... if(eee->conf.connect_tcp) { - setsockopt(eee->sock, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value)); + setsockopt(eee->sock, IPPROTO_TCP, TCP_NODELAY, (void *)&value, sizeof(value)); value = 1; #ifdef LINUX setsockopt(eee->sock, IPPROTO_TCP, TCP_CORK, &value, sizeof(value)); @@ -1159,7 +1159,7 @@ static void sendto_sock (n2n_edge_t *eee, const void * buf, // if the connection is tcp, i.e. not the regular sock... if(eee->conf.connect_tcp) { value = 1; /* value should still be set to 1 */ - setsockopt(eee->sock, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value)); + setsockopt(eee->sock, IPPROTO_TCP, TCP_NODELAY, (void *)&value, sizeof(value)); #ifdef LINUX value = 0; setsockopt(eee->sock, IPPROTO_TCP, TCP_CORK, &value, sizeof(value)); @@ -2791,7 +2791,7 @@ int fetch_and_eventually_process_data (n2n_edge_t *eee, SOCKET sock, #endif ) { // udp - bread = recvfrom(sock, pktbuf, N2N_PKT_BUF_SIZE, 0 /*flags*/, + bread = recvfrom(sock, (void *)pktbuf, N2N_PKT_BUF_SIZE, 0 /*flags*/, sender_sock, &ss_size); if((bread < 0) @@ -2817,7 +2817,7 @@ int fetch_and_eventually_process_data (n2n_edge_t *eee, SOCKET sock, } else { // tcp bread = recvfrom(sock, - pktbuf + *position, *expected - *position, 0 /*flags*/, + (void *)(pktbuf + *position), *expected - *position, 0 /*flags*/, sender_sock, &ss_size); if((bread <= 0) && (errno)) { traceEvent(TRACE_ERROR, "recvfrom() failed %d errno %d (%s)", bread, errno, strerror(errno)); diff --git a/src/n2n.c b/src/n2n.c index 9b8689f..026a120 100644 --- a/src/n2n.c +++ b/src/n2n.c @@ -82,7 +82,10 @@ SOCKET open_socket (int local_port, in_addr_t address, int type /* 0 = UDP, TCP static int traceLevel = 2 /* NORMAL */; -static int useSyslog = 0, syslog_opened = 0; +static int useSyslog = 0; +#ifndef WIN32 +static int syslog_opened = 0; +#endif static FILE *traceFile = NULL; int getTraceLevel () { diff --git a/src/sn_utils.c b/src/sn_utils.c index 88686f7..7f8e806 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -566,7 +566,7 @@ static ssize_t sendto_sock(n2n_sn_t *sss, // if the connection is tcp, i.e. not the regular sock... if((socket_fd >= 0) && (socket_fd != sss->sock)) { value = 1; /* value should still be set to 1 */ - setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value)); + setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, (void *)&value, sizeof(value)); #ifdef LINUX value = 0; setsockopt(socket_fd, IPPROTO_TCP, TCP_CORK, &value, sizeof(value)); diff --git a/tools/n2n-portfwd.c b/tools/n2n-portfwd.c index 89dabcc..1b6a7e9 100644 --- a/tools/n2n-portfwd.c +++ b/tools/n2n-portfwd.c @@ -50,8 +50,10 @@ // REVISIT: may become obsolete #ifdef WIN32 +#ifndef STDIN_FILENO #define STDIN_FILENO _fileno(stdin) #endif +#endif typedef struct n2n_portfwd_conf { @@ -197,6 +199,11 @@ int _kbhit () { return FD_ISSET(STDIN_FILENO, &fds); } +#else +// A dummy definition to avoid compile errors on windows +int _kbhit () { + return 0; +} #endif diff --git a/tools/n2n-route.c b/tools/n2n-route.c index a7d3cdd..aeaa49d 100644 --- a/tools/n2n-route.c +++ b/tools/n2n-route.c @@ -75,8 +75,10 @@ // REVISIT: may become obsolete #ifdef WIN32 +#ifndef STDIN_FILENO #define STDIN_FILENO _fileno(stdin) #endif +#endif typedef struct n2n_route { @@ -496,7 +498,6 @@ void handle_route (n2n_route_t* in_route, int verb) { #elif defined(WIN32) // REVISIT: use 'CreateIpForwardEntry()' and 'DeleteIpForwardEntry()' [iphlpapi.h] - struct in_addr net_addr, gateway; char c_net_addr[32]; char c_gateway[32]; char c_interface[32]; @@ -657,6 +658,11 @@ int _kbhit () { return FD_ISSET(STDIN_FILENO, &fds); } +#else +// A dummy definition to avoid compile errors on windows +int _kbhit () { + return 0; +} #endif