Fix warnings when compiling for Windows.
authorGuus Sliepen <guus@tinc-vpn.org>
Sun, 21 Oct 2018 14:23:45 +0000 (16:23 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 21 Oct 2018 14:23:45 +0000 (16:23 +0200)
13 files changed:
src/dropin.c
src/event.c
src/ifconfig.c
src/meta.c
src/mingw/device.c
src/names.c
src/net_packet.c
src/net_socket.c
src/process.c
src/route.c
src/script.c
src/tincd.c
src/upnp.c

index 74e5676..0cde7a0 100644 (file)
@@ -1,7 +1,7 @@
 /*
     dropin.c -- a set of drop-in replacements for libc functions
     Copyright (C) 2000-2005 Ivo Timmermans,
 /*
     dropin.c -- a set of drop-in replacements for libc functions
     Copyright (C) 2000-2005 Ivo Timmermans,
-                  2000-2016 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2018 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -82,6 +82,8 @@ int daemon(int nochdir, int noclose) {
 
        return 0;
 #else
 
        return 0;
 #else
+       (void)nochdir;
+       (void)noclose;
        return -1;
 #endif
 }
        return -1;
 #endif
 }
@@ -144,6 +146,7 @@ int gettimeofday(struct timeval *tv, void *tz) {
 
 #ifndef HAVE_NANOSLEEP
 int nanosleep(const struct timespec *req, struct timespec *rem) {
 
 #ifndef HAVE_NANOSLEEP
 int nanosleep(const struct timespec *req, struct timespec *rem) {
+       (void)rem;
        struct timeval tv = {req->tv_sec, req->tv_nsec / 1000};
        return select(0, NULL, NULL, NULL, &tv);
 }
        struct timeval tv = {req->tv_sec, req->tv_nsec / 1000};
        return select(0, NULL, NULL, NULL, &tv);
 }
index 47adb18..1283edd 100644 (file)
@@ -1,6 +1,6 @@
 /*
     event.c -- I/O, timeout and signal event handling
 /*
     event.c -- I/O, timeout and signal event handling
-    Copyright (C) 2012-2013 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2012-2018 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -378,7 +378,7 @@ bool event_loop(void) {
        while(running) {
                struct timeval diff;
                struct timeval *tv = get_time_remaining(&diff);
        while(running) {
                struct timeval diff;
                struct timeval *tv = get_time_remaining(&diff);
-               DWORD timeout_ms = tv ? (tv->tv_sec * 1000 + tv->tv_usec / 1000 + 1) : WSA_INFINITE;
+               DWORD timeout_ms = tv ? (DWORD)(tv->tv_sec * 1000 + tv->tv_usec / 1000 + 1) : WSA_INFINITE;
 
                if(!event_count) {
                        Sleep(timeout_ms);
 
                if(!event_count) {
                        Sleep(timeout_ms);
@@ -435,12 +435,12 @@ bool event_loop(void) {
                                break;
                        }
 
                                break;
                        }
 
-                       if(result < WSA_WAIT_EVENT_0 || result >= WSA_WAIT_EVENT_0 + event_count - event_offset) {
+                       if(result >= event_count - event_offset) {
                                return(false);
                        }
 
                        /* Look up io in the map by index. */
                                return(false);
                        }
 
                        /* Look up io in the map by index. */
-                       event_index = result - WSA_WAIT_EVENT_0 + event_offset;
+                       event_index = result - event_offset;
                        io_t *io = io_map[event_index];
 
                        if(io->fd == -1) {
                        io_t *io = io_map[event_index];
 
                        if(io->fd == -1) {
index 76092a7..742d2eb 100644 (file)
@@ -1,6 +1,6 @@
 /*
     ifconfig.c -- Generate platform specific interface configuration commands
 /*
     ifconfig.c -- Generate platform specific interface configuration commands
-    Copyright (C) 2016-2017 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2016-2018 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -71,10 +71,12 @@ void ifconfig_dhcp(FILE *out) {
 }
 
 void ifconfig_dhcp6(FILE *out) {
 }
 
 void ifconfig_dhcp6(FILE *out) {
+       (void)out;
        fprintf(stderr, "DHCPv6 requested, but not supported by tinc on this platform\n");
 }
 
 void ifconfig_slaac(FILE *out) {
        fprintf(stderr, "DHCPv6 requested, but not supported by tinc on this platform\n");
 }
 
 void ifconfig_slaac(FILE *out) {
+       (void)out;
        // It's the default?
 }
 
        // It's the default?
 }
 
index 0089ac8..4282a4e 100644 (file)
@@ -1,6 +1,6 @@
 /*
     meta.c -- handle the meta communication
 /*
     meta.c -- handle the meta communication
-    Copyright (C) 2000-2014 Guus Sliepen <guus@tinc-vpn.org>,
+    Copyright (C) 2000-2018 Guus Sliepen <guus@tinc-vpn.org>,
                   2000-2005 Ivo Timmermans
                   2006      Scott Lamb <slamb@slamb.org>
 
                   2000-2005 Ivo Timmermans
                   2006      Scott Lamb <slamb@slamb.org>
 
@@ -31,7 +31,9 @@
 #include "xalloc.h"
 
 #ifndef MIN
 #include "xalloc.h"
 
 #ifndef MIN
-#define MIN(x, y) (((x)<(y))?(x):(y))
+static ssize_t MIN(ssize_t x, ssize_t y) {
+       return x < y ? x : y;
+}
 #endif
 
 bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t length) {
 #endif
 
 bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t length) {
index 183641b..bf8ae13 100644 (file)
@@ -1,7 +1,7 @@
 /*
     device.c -- Interaction with Windows tap driver in a MinGW environment
     Copyright (C) 2002-2005 Ivo Timmermans,
 /*
     device.c -- Interaction with Windows tap driver in a MinGW environment
     Copyright (C) 2002-2005 Ivo Timmermans,
-                  2002-2014 Guus Sliepen <guus@tinc-vpn.org>
+                  2002-2018 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -71,6 +71,9 @@ static void device_issue_read() {
 }
 
 static void device_handle_read(void *data, int flags) {
 }
 
 static void device_handle_read(void *data, int flags) {
+       (void)data;
+       (void)flags;
+
        DWORD len;
 
        if(!GetOverlappedResult(device_handle, &device_read_overlapped, &len, FALSE)) {
        DWORD len;
 
        if(!GetOverlappedResult(device_handle, &device_read_overlapped, &len, FALSE)) {
@@ -300,6 +303,7 @@ static void close_device(void) {
 }
 
 static bool read_packet(vpn_packet_t *packet) {
 }
 
 static bool read_packet(vpn_packet_t *packet) {
+       (void)packet;
        return false;
 }
 
        return false;
 }
 
index 6db364e..603b536 100644 (file)
@@ -1,7 +1,7 @@
 /*
     names.c -- generate commonly used (file)names
     Copyright (C) 1998-2005 Ivo Timmermans
 /*
     names.c -- generate commonly used (file)names
     Copyright (C) 1998-2005 Ivo Timmermans
-                  2000-2017 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2018 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -93,6 +93,7 @@ void make_names(bool daemon) {
        }
 
 #ifdef HAVE_MINGW
        }
 
 #ifdef HAVE_MINGW
+       (void)daemon;
 
        if(!logfilename) {
                xasprintf(&logfilename, "%s" SLASH "log", confbase);
 
        if(!logfilename) {
                xasprintf(&logfilename, "%s" SLASH "log", confbase);
index d589228..5a85642 100644 (file)
@@ -1,7 +1,7 @@
 /*
     net_packet.c -- Handles in- and outgoing VPN packets
     Copyright (C) 1998-2005 Ivo Timmermans,
 /*
     net_packet.c -- Handles in- and outgoing VPN packets
     Copyright (C) 1998-2005 Ivo Timmermans,
-                  2000-2017 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2018 Guus Sliepen <guus@tinc-vpn.org>
                   2010      Timothy Redaelli <timothy@redaelli.eu>
                   2010      Brandon Black <blblack@gmail.com>
 
                   2010      Timothy Redaelli <timothy@redaelli.eu>
                   2010      Brandon Black <blblack@gmail.com>
 
@@ -1228,9 +1228,8 @@ static length_t choose_initial_maxmtu(node_t *n) {
        return mtu;
 
 #else
        return mtu;
 
 #else
-
+       (void)n;
        return MTU;
        return MTU;
-
 #endif
 }
 
 #endif
 }
 
@@ -1775,13 +1774,13 @@ void handle_incoming_vpn_data(void *data, int flags) {
 
 #else
        vpn_packet_t pkt;
 
 #else
        vpn_packet_t pkt;
-       sockaddr_t addr = {};
+       sockaddr_t addr = {0};
        socklen_t addrlen = sizeof(addr);
 
        pkt.offset = 0;
        int len = recvfrom(ls->udp.fd, (void *)DATA(&pkt), MAXSIZE, 0, &addr.sa, &addrlen);
 
        socklen_t addrlen = sizeof(addr);
 
        pkt.offset = 0;
        int len = recvfrom(ls->udp.fd, (void *)DATA(&pkt), MAXSIZE, 0, &addr.sa, &addrlen);
 
-       if(len <= 0 || len > MAXSIZE) {
+       if(len <= 0 || (size_t)len > MAXSIZE) {
                if(!sockwouldblock(sockerrno)) {
                        logger(DEBUG_ALWAYS, LOG_ERR, "Receiving packet failed: %s", sockstrerror(sockerrno));
                }
                if(!sockwouldblock(sockerrno)) {
                        logger(DEBUG_ALWAYS, LOG_ERR, "Receiving packet failed: %s", sockstrerror(sockerrno));
                }
index dcf8372..a696127 100644 (file)
@@ -1,7 +1,7 @@
 /*
     net_socket.c -- Handle various kinds of sockets.
     Copyright (C) 1998-2005 Ivo Timmermans,
 /*
     net_socket.c -- Handle various kinds of sockets.
     Copyright (C) 1998-2005 Ivo Timmermans,
-                  2000-2017 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2018 Guus Sliepen <guus@tinc-vpn.org>
                   2006      Scott Lamb <slamb@slamb.org>
                   2009      Florian Forster <octo@verplant.org>
 
                   2006      Scott Lamb <slamb@slamb.org>
                   2009      Florian Forster <octo@verplant.org>
 
@@ -122,6 +122,7 @@ static bool bind_to_interface(int sd) {
        }
 
 #else /* if !defined(SOL_SOCKET) || !defined(SO_BINDTODEVICE) */
        }
 
 #else /* if !defined(SOL_SOCKET) || !defined(SO_BINDTODEVICE) */
+       (void)sd;
        logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "BindToInterface");
 #endif
 
        logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "BindToInterface");
 #endif
 
@@ -387,7 +388,7 @@ void finish_connecting(connection_t *c) {
        send_id(c);
 }
 
        send_id(c);
 }
 
-static void do_outgoing_pipe(connection_t *c, char *command) {
+static void do_outgoing_pipe(connection_t *c, const char *command) {
 #ifndef HAVE_MINGW
        int fd[2];
 
 #ifndef HAVE_MINGW
        int fd[2];
 
@@ -435,6 +436,8 @@ static void do_outgoing_pipe(connection_t *c, char *command) {
 
        exit(result);
 #else
 
        exit(result);
 #else
+       (void)c;
+       (void)command;
        logger(DEBUG_ALWAYS, LOG_ERR, "Proxy type exec not supported on this platform!");
        return;
 #endif
        logger(DEBUG_ALWAYS, LOG_ERR, "Proxy type exec not supported on this platform!");
        return;
 #endif
index c6cb536..b6d4e12 100644 (file)
@@ -1,7 +1,7 @@
 /*
     process.c -- process management functions
     Copyright (C) 1999-2005 Ivo Timmermans,
 /*
     process.c -- process management functions
     Copyright (C) 1999-2005 Ivo Timmermans,
-                  2000-2013 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2018 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -115,7 +115,11 @@ static bool install_service(void) {
 
 io_t stop_io;
 
 
 io_t stop_io;
 
-DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) {
+DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID data, LPVOID context) {
+       (void)type;
+       (void)data;
+       (void)context;
+
        switch(request) {
        case SERVICE_CONTROL_INTERROGATE:
                SetServiceStatus(statushandle, &status);
        switch(request) {
        case SERVICE_CONTROL_INTERROGATE:
                SetServiceStatus(statushandle, &status);
index 461ba14..fc08f5f 100644 (file)
@@ -1,7 +1,7 @@
 /*
     route.c -- routing
     Copyright (C) 2000-2005 Ivo Timmermans,
 /*
     route.c -- routing
     Copyright (C) 2000-2005 Ivo Timmermans,
-                  2000-2013 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2018 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -165,7 +165,7 @@ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, length_
                                addr.sin_family = AF_INET;
                                socklen_t addrlen = sizeof(addr);
 
                                addr.sin_family = AF_INET;
                                socklen_t addrlen = sizeof(addr);
 
-                               if(!getsockname(sockfd, (struct sockaddr *) &addr, &addrlen) && addrlen <= sizeof(addr)) {
+                               if(!getsockname(sockfd, (struct sockaddr *) &addr, &addrlen) && (size_t)addrlen <= sizeof(addr)) {
                                        ip_dst = addr.sin_addr;
                                }
                        }
                                        ip_dst = addr.sin_addr;
                                }
                        }
@@ -270,7 +270,7 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, length_
                                addr.sin6_family = AF_INET6;
                                socklen_t addrlen = sizeof(addr);
 
                                addr.sin6_family = AF_INET6;
                                socklen_t addrlen = sizeof(addr);
 
-                               if(!getsockname(sockfd, (struct sockaddr *) &addr, &addrlen) && addrlen <= sizeof(addr)) {
+                               if(!getsockname(sockfd, (struct sockaddr *) &addr, &addrlen) && (size_t)addrlen <= sizeof(addr)) {
                                        pseudo.ip6_src = addr.sin6_addr;
                                }
                        }
                                        pseudo.ip6_src = addr.sin6_addr;
                                }
                        }
index 81216a3..e465ab7 100644 (file)
@@ -1,7 +1,7 @@
 /*
     script.c -- call an external script
     Copyright (C) 1999-2005 Ivo Timmermans,
 /*
     script.c -- call an external script
     Copyright (C) 1999-2005 Ivo Timmermans,
-                  2000-2017 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2018 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -50,7 +50,7 @@ static void unputenv(const char *p) {
 #else
        // We must keep what we putenv() around in memory.
        // To do this without memory leaks, keep things in a list and reuse if possible.
 #else
        // We must keep what we putenv() around in memory.
        // To do this without memory leaks, keep things in a list and reuse if possible.
-       static list_t list = {};
+       static list_t list = {0};
 
        for list_each(char, data, &list) {
                if(!strcmp(data, var)) {
 
        for list_each(char, data, &list) {
                if(!strcmp(data, var)) {
@@ -142,7 +142,12 @@ bool execute_script(const char *name, environment_t *env) {
 #ifdef HAVE_MINGW
 
        if(!*scriptextension) {
 #ifdef HAVE_MINGW
 
        if(!*scriptextension) {
-               const char *pathext = getenv("PATHEXT") ? : ".COM;.EXE;.BAT;.CMD";
+               const char *pathext = getenv("PATHEXT");
+
+               if(!pathext) {
+                       pathext = ".COM;.EXE;.BAT;.CMD";
+               }
+
                size_t pathlen = strlen(pathext);
                size_t scriptlen = strlen(scriptname);
                char fullname[scriptlen + pathlen + 1];
                size_t pathlen = strlen(pathext);
                size_t scriptlen = strlen(scriptname);
                char fullname[scriptlen + pathlen + 1];
index dbf6bc8..1e111a2 100644 (file)
@@ -344,10 +344,15 @@ static bool drop_privs(void) {
 # define setpriority(level) !SetPriorityClass(GetCurrentProcess(), (level))
 
 static void stop_handler(void *data, int flags) {
 # define setpriority(level) !SetPriorityClass(GetCurrentProcess(), (level))
 
 static void stop_handler(void *data, int flags) {
+       (void)data;
+       (void)flags;
+
        event_exit();
 }
 
 static BOOL WINAPI console_ctrl_handler(DWORD type) {
        event_exit();
 }
 
 static BOOL WINAPI console_ctrl_handler(DWORD type) {
+       (void)type;
+
        logger(DEBUG_ALWAYS, LOG_NOTICE, "Got console shutdown request");
 
        if(WSASetEvent(stop_io.event) == FALSE) {
        logger(DEBUG_ALWAYS, LOG_NOTICE, "Got console shutdown request");
 
        if(WSASetEvent(stop_io.event) == FALSE) {
@@ -481,6 +486,8 @@ int main(int argc, char **argv) {
 }
 
 int main2(int argc, char **argv) {
 }
 
 int main2(int argc, char **argv) {
+       (void)argc;
+       (void)argv;
 #endif
        char *priority = NULL;
 
 #endif
        char *priority = NULL;
 
index 5e41d1b..553630e 100644 (file)
@@ -1,6 +1,6 @@
 /*
     upnp.c -- UPnP-IGD client
 /*
     upnp.c -- UPnP-IGD client
-    Copyright (C) 2015 Guus Sliepen <guus@tinc-vpn.org>,
+    Copyright (C) 2015-2018 Guus Sliepen <guus@tinc-vpn.org>,
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -19,7 +19,9 @@
 
 #include "upnp.h"
 
 
 #include "upnp.h"
 
+#ifndef HAVE_MINGW
 #include <pthread.h>
 #include <pthread.h>
+#endif
 
 #include "miniupnpc/miniupnpc.h"
 #include "miniupnpc/upnpcommands.h"
 
 #include "miniupnpc/miniupnpc.h"
 #include "miniupnpc/upnpcommands.h"
@@ -159,7 +161,9 @@ static void *upnp_thread(void *data) {
                time_t now = time(NULL);
 
                if(now < refresh_time) {
                time_t now = time(NULL);
 
                if(now < refresh_time) {
-                       sleep(refresh_time - now);
+                       nanosleep(&(struct timespec) {
+                               refresh_time - now, 0
+                       }, NULL);
                }
        }
 
                }
        }
 
@@ -176,10 +180,20 @@ void upnp_init(bool tcp, bool udp) {
        get_config_int(lookup_config(config_tree, "UPnPDiscoverWait"), &upnp_discover_wait);
        get_config_int(lookup_config(config_tree, "UPnPRefreshPeriod"), &upnp_refresh_period);
 
        get_config_int(lookup_config(config_tree, "UPnPDiscoverWait"), &upnp_discover_wait);
        get_config_int(lookup_config(config_tree, "UPnPRefreshPeriod"), &upnp_refresh_period);
 
+#ifdef HAVE_MINGW
+       HANDLE handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)upnp_thread, NULL, 0, NULL);
+
+       if(!handle) {
+               logger(DEBUG_ALWAYS, LOG_ERR, "Unable to start UPnP-IGD client thread");
+       }
+
+#else
        pthread_t thread;
        int error = pthread_create(&thread, NULL, upnp_thread, NULL);
 
        if(error) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Unable to start UPnP-IGD client thread: [%d] %s", error, strerror(error));
        }
        pthread_t thread;
        int error = pthread_create(&thread, NULL, upnp_thread, NULL);
 
        if(error) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Unable to start UPnP-IGD client thread: [%d] %s", error, strerror(error));
        }
+
+#endif
 }
 }