]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: default to display bitmask in hexadecimal
authorPablo Neira Ayuso <pablo@netfilter.org>
Fri, 5 Jun 2015 15:12:47 +0000 (17:12 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 5 Jun 2015 15:30:35 +0000 (17:30 +0200)
Instead of a plain integer.

This updates integer_type_print() to look up some basefmt in the change of
datatype, the first we find will be used to format the output.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/datatype.c

index f93337b135a486f9622b4200ed556379a7a1d785..82a775379bc5277c385d2373b9c2fc34c575eafd 100644 (file)
@@ -260,15 +260,22 @@ const struct datatype bitmask_type = {
        .type           = TYPE_BITMASK,
        .name           = "bitmask",
        .desc           = "bitmask",
+       .basefmt        = "0x%Zx",
        .basetype       = &integer_type,
 };
 
 static void integer_type_print(const struct expr *expr)
 {
+       const struct datatype *dtype = expr->dtype;
        const char *fmt = "%Zu";
 
-       if (expr->dtype->basefmt != NULL)
-               fmt = expr->dtype->basefmt;
+       do {
+               if (dtype->basefmt != NULL) {
+                       fmt = dtype->basefmt;
+                       break;
+               }
+       } while ((dtype = dtype->basetype));
+
        gmp_printf(fmt, expr->value);
 }