summaryrefslogtreecommitdiffstats
path: root/src/datatype.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2015-06-05 17:12:47 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2015-06-05 17:30:35 +0200
commit5567bfd777182646a3dc7d5a2422a244481fa794 (patch)
treede15fde6ea7fd1794deeca234519915f76828a2a /src/datatype.c
parenta5afe525d01796bc17f1c97d01e374fe4fa21e00 (diff)
datatype: default to display bitmask in hexadecimal
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>
Diffstat (limited to 'src/datatype.c')
-rw-r--r--src/datatype.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/datatype.c b/src/datatype.c
index f93337b1..82a77537 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -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);
}