From 6ad2058da66affc105d325e45ff82fd5b5cac41e Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Tue, 2 Nov 2021 14:07:04 +0100 Subject: 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 --- src/datatype.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/datatype.c') 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); -- cgit v1.2.3