X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fupnp.c;h=eb68998bc26395b2b8ccb8562a733e1d380b7efb;hb=09dda64ce99668c918fada04b9ad6bf9cd2ab104;hp=3e902100150103b5690707e3aed50233ed616b93;hpb=f6e87ab476a0faf8b124ecaaa27f967d825e6457;p=tinc diff --git a/src/upnp.c b/src/upnp.c index 3e902100..eb68998b 100644 --- a/src/upnp.c +++ b/src/upnp.c @@ -1,6 +1,6 @@ /* upnp.c -- UPnP-IGD client - Copyright (C) 2015 Guus Sliepen , + Copyright (C) 2015-2022 Guus Sliepen , 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 @@ -17,7 +17,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "upnp.h" +#include "system.h" #include @@ -25,12 +25,12 @@ #include "miniupnpc/upnpcommands.h" #include "miniupnpc/upnperrors.h" -#include "system.h" #include "logger.h" #include "names.h" #include "net.h" #include "netutl.h" #include "utils.h" +#include "upnp.h" static bool upnp_tcp; static bool upnp_udp; @@ -61,7 +61,7 @@ static struct UPNPDev *upnp_discover(int delay, int *error) { #else -#if MINIUPNPC_API_VERSION > 15 +#if MINIUPNPC_API_VERSION > 17 #warning "The version of libminiupnpc you're building against seems to be too recent. Expect trouble." #endif @@ -105,7 +105,7 @@ static void upnp_add_mapping(struct UPNPUrls *urls, struct IGDdatas *data, const free(port); } -static void upnp_refresh() { +static void upnp_refresh(void) { logger(DEBUG_PROTOCOL, LOG_INFO, "[upnp] Discovering IGD devices"); int error; @@ -148,6 +148,8 @@ static void upnp_refresh() { } static void *upnp_thread(void *data) { + (void)data; + while(true) { time_t start = time(NULL); upnp_refresh(); @@ -157,7 +159,9 @@ static void *upnp_thread(void *data) { time_t now = time(NULL); if(now < refresh_time) { - sleep(refresh_time - now); + nanosleep(&(struct timespec) { + refresh_time - now, 0 + }, NULL); } } @@ -171,8 +175,8 @@ void upnp_init(bool tcp, bool udp) { upnp_tcp = tcp; upnp_udp = 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); pthread_t thread; int error = pthread_create(&thread, NULL, upnp_thread, NULL);