Fix tomato_load() leaseduration

fixes #192
This commit is contained in:
Thomas Bernard 2016-03-04 19:33:18 +01:00
parent 6bd49eb215
commit 6532b02cab
1 changed files with 4 additions and 2 deletions

View File

@ -182,14 +182,14 @@ tomato_load(void)
current_time = time(NULL); current_time = time(NULL);
s[sizeof(s) - 1] = 0; s[sizeof(s) - 1] = 0;
while (fgets(s, sizeof(s) - 1, f)) { while (fgets(s, sizeof(s) - 1, f)) {
if (sscanf(s, "%3s %hu %31s %hu [%*s] %u", proto, &eport, iaddr, &iport, &timestamp) >= 4) if (sscanf(s, "%3s %hu %31s %hu [%*[^]]] %u", proto, &eport, iaddr, &iport, &timestamp) >= 4) {
{ {
if (((a = strchr(s, '[')) != NULL) && ((b = strrchr(a, ']')) != NULL)) if (((a = strchr(s, '[')) != NULL) && ((b = strrchr(a, ']')) != NULL))
{ {
if (timestamp > 0) if (timestamp > 0)
{ {
if (timestamp > current_time) if (timestamp > current_time)
leaseduration = current_time - timestamp; leaseduration = timestamp - current_time;
else else
continue; continue;
} }
@ -199,6 +199,8 @@ tomato_load(void)
} }
*b = 0; *b = 0;
rhost = NULL; rhost = NULL;
syslog(LOG_DEBUG, "Read redirection [%s] from file: %s port %hu to %s port %hu, timestamp: %u (%u)",
a + 1, proto, eport, iaddr, iport, timestamp, leaseduration);
upnp_redirect(rhost, eport, iaddr, iport, proto, a + 1, leaseduration); upnp_redirect(rhost, eport, iaddr, iport, proto, a + 1, leaseduration);
} }
} }