[sr-dev] git:master:fe68c9ae: nat_traversal: use TIME_T_FMT

Daniel-Constantin Mierla miconda at gmail.com
Wed Nov 3 13:03:45 CET 2021

Module: kamailio
Branch: master
Commit: fe68c9aeb06f114afdc6c0b076b5163e34deeea5
URL: https://github.com/kamailio/kamailio/commit/fe68c9aeb06f114afdc6c0b076b5163e34deeea5

Author: Sebastian Kemper <sebastian_ml at gmx.net>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-11-03T13:03:34+01:00

nat_traversal: use TIME_T_FMT

The size of the time_t destination is unknown as it is depending on the
platform. So we "read into a known-size integer (either int or long
long) and then assign the value to a time_t as a second step" (quote
from [1]).

[1] https://stackoverflow.com/questions/4171478/how-to-read-data-into-a-time-t-variable-using-scanf

Signed-off-by: Sebastian Kemper <sebastian_ml at gmx.net>


Modified: src/modules/nat_traversal/nat_traversal.c


Diff:  https://github.com/kamailio/kamailio/commit/fe68c9aeb06f114afdc6c0b076b5163e34deeea5.diff
Patch: https://github.com/kamailio/kamailio/commit/fe68c9aeb06f114afdc6c0b076b5163e34deeea5.patch


diff --git a/src/modules/nat_traversal/nat_traversal.c b/src/modules/nat_traversal/nat_traversal.c
index 4cfe8d4018..edaa6dfe3d 100644
--- a/src/modules/nat_traversal/nat_traversal.c
+++ b/src/modules/nat_traversal/nat_traversal.c
@@ -1707,6 +1707,7 @@ static void restore_keepalive_state(void)
 	unsigned h;
 	str host;
 	FILE *f;
+	long long ll_1, ll_2;
@@ -1724,7 +1725,9 @@ static void restore_keepalive_state(void)
 	res = fscanf(f, STATE_FILE_HEADER); // skip header
 	while(true) {
-		res = fscanf(f, "%63s %63s %ld %ld", uri, socket, &rtime, &stime);
+		res = fscanf(f, "%63s %63s %" TIME_T_FMT " %" TIME_T_FMT, uri, socket, &ll_1, &ll_2);
+		rtime = ll_1;
+		stime = ll_2;
 		if(res == EOF) {
 				LM_ERR("error while reading keepalive state file: %s\n",

More information about the sr-dev mailing list