diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2021-11-02 14:07:04 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2021-11-03 12:48:19 +0100 |
commit | 6ad2058da66affc105d325e45ff82fd5b5cac41e (patch) | |
tree | 75818a002b868664c01ebaf39ae4a3370643c727 /src/datatype.c | |
parent | 8f3048954d40da8240cf5ff07b84d5c2e66f9066 (diff) |
datatype: add xinteger_type alias to print in hexadecimal
Add an alias of the integer type to print raw payload expressions in
hexadecimal.
Update tests/py.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/datatype.c')
-rw-r--r-- | src/datatype.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/datatype.c b/src/datatype.c index b849f708..a06c3996 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -410,6 +410,22 @@ const struct datatype integer_type = { .parse = integer_type_parse, }; +static void xinteger_type_print(const struct expr *expr, struct output_ctx *octx) +{ + nft_gmp_print(octx, "0x%Zx", expr->value); +} + +/* Alias of integer_type to print raw payload expressions in hexadecimal. */ +const struct datatype xinteger_type = { + .type = TYPE_INTEGER, + .name = "integer", + .desc = "integer", + .basetype = &integer_type, + .print = xinteger_type_print, + .json = integer_type_json, + .parse = integer_type_parse, +}; + static void string_type_print(const struct expr *expr, struct output_ctx *octx) { unsigned int len = div_round_up(expr->len, BITS_PER_BYTE); |