summaryrefslogtreecommitdiffstats
path: root/ripngd
diff options
context:
space:
mode:
authorMark Stapp <mjs@voltanet.io>2020-03-05 20:06:46 +0100
committerMark Stapp <mjs@voltanet.io>2020-03-09 16:12:32 +0100
commitd0636ead31ccfc9f6c27d02617d5965e3111d4ad (patch)
treef1c383042125411fc44acd65febdf43ce1f1de17 /ripngd
parentMerge pull request #5919 from qlyoung/fix-vrrp-mvl-uaf (diff)
downloadfrr-d0636ead31ccfc9f6c27d02617d5965e3111d4ad.tar.xz
frr-d0636ead31ccfc9f6c27d02617d5965e3111d4ad.zip
lib, *: add a common time interval formatting api
Add a common api that formats a time interval into a string with different output for short and longer intervals. We do this in several places, for cli/ui output. Signed-off-by: Mark Stapp <mjs@voltanet.io>
Diffstat (limited to 'ripngd')
-rw-r--r--ripngd/ripng_peer.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/ripngd/ripng_peer.c b/ripngd/ripng_peer.c
index c038bfccf..e6ff58dd0 100644
--- a/ripngd/ripng_peer.c
+++ b/ripngd/ripng_peer.c
@@ -141,7 +141,6 @@ void ripng_peer_bad_packet(struct ripng *ripng, struct sockaddr_in6 *from)
static char *ripng_peer_uptime(struct ripng_peer *peer, char *buf, size_t len)
{
time_t uptime;
- struct tm tm;
/* If there is no connection has been done before print `never'. */
if (peer->uptime == 0) {
@@ -152,17 +151,9 @@ static char *ripng_peer_uptime(struct ripng_peer *peer, char *buf, size_t len)
/* Get current time. */
uptime = time(NULL);
uptime -= peer->uptime;
- gmtime_r(&uptime, &tm);
-
- if (uptime < ONE_DAY_SECOND)
- snprintf(buf, len, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
- tm.tm_sec);
- else if (uptime < ONE_WEEK_SECOND)
- snprintf(buf, len, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
- tm.tm_min);
- else
- snprintf(buf, len, "%02dw%dd%02dh", tm.tm_yday / 7,
- tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
+
+ frrtime_to_interval(uptime, buf, len);
+
return buf;
}