summaryrefslogtreecommitdiffstats
path: root/src/datatype.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2024-01-25 17:31:45 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2024-02-07 13:37:00 +0100
commit072c83e9a18399249fbc4343f7d0b5b04c29e6fb (patch)
treeaa52c24079d655de0ee8036d1fa0abfbbeb93614 /src/datatype.c
parent6847a7ce0fc99a63a812de6cdbbf568ad9ca6f69 (diff)
datatype: display 0s time datatype
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/datatype.c')
-rw-r--r--src/datatype.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/datatype.c b/src/datatype.c
index 099e7580..3205b214 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -1090,6 +1090,7 @@ const struct datatype icmpx_code_type = {
void time_print(uint64_t ms, struct output_ctx *octx)
{
uint64_t days, hours, minutes, seconds;
+ bool printed = false;
if (nft_output_seconds(octx)) {
nft_print(octx, "%" PRIu64 "s", ms / 1000);
@@ -1108,16 +1109,29 @@ void time_print(uint64_t ms, struct output_ctx *octx)
seconds = ms / 1000;
ms %= 1000;
- if (days > 0)
+ if (days > 0) {
nft_print(octx, "%" PRIu64 "d", days);
- if (hours > 0)
+ printed = true;
+ }
+ if (hours > 0) {
nft_print(octx, "%" PRIu64 "h", hours);
- if (minutes > 0)
+ printed = true;
+ }
+ if (minutes > 0) {
nft_print(octx, "%" PRIu64 "m", minutes);
- if (seconds > 0)
+ printed = true;
+ }
+ if (seconds > 0) {
nft_print(octx, "%" PRIu64 "s", seconds);
- if (ms > 0)
+ printed = true;
+ }
+ if (ms > 0) {
nft_print(octx, "%" PRIu64 "ms", ms);
+ printed = true;
+ }
+
+ if (!printed)
+ nft_print(octx, "0s");
}
enum {