Correct close() function when building with MSVC
[tinc] / src / net_setup.c
index d2adc13..60fc692 100644 (file)
@@ -28,6 +28,7 @@
 #include "connection.h"
 #include "compression.h"
 #include "control.h"
+#include "crypto.h"
 #include "device.h"
 #include "digest.h"
 #include "ecdsa.h"
@@ -142,7 +143,7 @@ static timeout_t keyexpire_timeout;
 static void keyexpire_handler(void *data) {
        regenerate_key();
        timeout_set(data, &(struct timeval) {
-               keylifetime, rand() % 100000
+               keylifetime, jitter()
        });
 }
 #endif
@@ -605,7 +606,7 @@ static bool add_listen_address(char *address, bool bindto) {
                int udp_fd = setup_vpn_in_socket((sockaddr_t *) aip->ai_addr);
 
                if(udp_fd < 0) {
-                       close(tcp_fd);
+                       closesocket(tcp_fd);
                        continue;
                }
 
@@ -834,7 +835,7 @@ static bool setup_myself(void) {
        free(cipher);
 
        timeout_add(&keyexpire_timeout, keyexpire_handler, &keyexpire_timeout, &(struct timeval) {
-               keylifetime, rand() % 100000
+               keylifetime, jitter()
        });
 
        /* Check if we want to use message authentication codes... */
@@ -1179,8 +1180,8 @@ void close_network_connections(void) {
        for(int i = 0; i < listen_sockets; i++) {
                io_del(&listen_socket[i].tcp);
                io_del(&listen_socket[i].udp);
-               close(listen_socket[i].tcp.fd);
-               close(listen_socket[i].udp.fd);
+               closesocket(listen_socket[i].tcp.fd);
+               closesocket(listen_socket[i].udp.fd);
        }
 
        exit_requests();