Fix warnings when compiling for Windows.
[tinc] / src / net_packet.c
index 6b40f2a..5a85642 100644 (file)
@@ -1,7 +1,7 @@
 /*
     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>
 
@@ -314,13 +314,6 @@ static bool try_mac(node_t *n, const vpn_packet_t *inpkt) {
 }
 
 static bool receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
-       vpn_packet_t pkt1, pkt2;
-       vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 };
-       int nextpkt = 0;
-       size_t outlen;
-       pkt1.offset = DEFAULT_PACKET_OFFSET;
-       pkt2.offset = DEFAULT_PACKET_OFFSET;
-
        if(n->status.sptps) {
                if(!n->sptps.state) {
                        if(!n->status.waitingforkey) {
@@ -356,6 +349,12 @@ static bool receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
 #ifdef DISABLE_LEGACY
        return false;
 #else
+       vpn_packet_t pkt1, pkt2;
+       vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 };
+       int nextpkt = 0;
+       size_t outlen;
+       pkt1.offset = DEFAULT_PACKET_OFFSET;
+       pkt2.offset = DEFAULT_PACKET_OFFSET;
 
        if(!n->status.validkey_in) {
                logger(DEBUG_TRAFFIC, LOG_DEBUG, "Got packet from %s (%s) but he hasn't got our key yet", n->name, n->hostname);
@@ -699,18 +698,6 @@ static void choose_local_address(const node_t *n, const sockaddr_t **sa, int *so
 }
 
 static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
-       vpn_packet_t pkt1, pkt2;
-       vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 };
-       vpn_packet_t *inpkt = origpkt;
-       int nextpkt = 0;
-       vpn_packet_t *outpkt;
-       int origlen = origpkt->len;
-       size_t outlen;
-       int origpriority = origpkt->priority;
-
-       pkt1.offset = DEFAULT_PACKET_OFFSET;
-       pkt2.offset = DEFAULT_PACKET_OFFSET;
-
        if(!n->status.reachable) {
                logger(DEBUG_TRAFFIC, LOG_INFO, "Trying to send UDP packet to unreachable node %s (%s)", n->name, n->hostname);
                return;
@@ -724,6 +711,18 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
 #ifdef DISABLE_LEGACY
        return;
 #else
+       vpn_packet_t pkt1, pkt2;
+       vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 };
+       vpn_packet_t *inpkt = origpkt;
+       int nextpkt = 0;
+       vpn_packet_t *outpkt;
+       int origlen = origpkt->len;
+       size_t outlen;
+       int origpriority = origpkt->priority;
+
+       pkt1.offset = DEFAULT_PACKET_OFFSET;
+       pkt2.offset = DEFAULT_PACKET_OFFSET;
+
        /* Make sure we have a valid key */
 
        if(!n->status.validkey) {
@@ -1229,9 +1228,8 @@ static length_t choose_initial_maxmtu(node_t *n) {
        return mtu;
 
 #else
-
+       (void)n;
        return MTU;
-
 #endif
 }
 
@@ -1776,13 +1774,13 @@ void handle_incoming_vpn_data(void *data, int flags) {
 
 #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);
 
-       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));
                }