datatype: Display pre-defined inet_service values in host byte order
PATCH 1/1 datatype: Display pre-defined inet_service values in host byte order
nft describe displays, to the user, which values are available for a selector, then the values should be in host byte order.
Reported-by Pablo Neira Ayuso <[email protected]>
Fixes ccc5da470e76 ("datatype: Replace getnameinfo() by internal lookup table")
Signed-off-by Elise Lennion <[email protected]>
--- include/datatype.h | 3 ++- src/datatype.c | 14 +++++++++++--- src/expression.c | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-)
include/datatype.h +2 -1
@@ -191,7 +191,8 @@ extern struct error_record *symbolic_constant_parse(const struct expr *sym,extern void symbolic_constant_print (const struct symbol_table *tbl,const struct expr *expr,bool quotes);extern void symbol_table_print (const struct symbol_table *tbl, -const struct datatype *dtype); +const struct datatype *dtype, +enum byteorder byteorder);extern struct symbol_table *rt_symbol_table_init (const char *filename);extern void rt_symbol_table_free (struct symbol_table *tbl);
src/datatype.c +11 -3
@@ -181,14 +181,22 @@ void symbolic_constant_print(const struct symbol_table *tbl, }void symbol_table_print (const struct symbol_table *tbl, -const struct datatype *dtype) +const struct datatype *dtype, +enum byteorder byteorder) {const struct symbolic_constant *s;unsigned int size =2 * dtype->size /BITS_PER_BYTE ; +long unsigned int value; + +for (s = tbl->symbols; s->identifier !=NULL ; s++) { +if (byteorder ==BYTEORDER_BIG_ENDIAN ) + value =__constant_ntohs (s->value); +else + value = s->value; -for (s = tbl->symbols; s->identifier !=NULL ; s++)printf ("\t%-30s\t0x%.*" PRIx64"\n" , - s->identifier, size, s->value); + s->identifier, size, value); + } }static void invalid_type_print (const struct expr *expr)
src/expression.c +2 -1
@@ -115,7 +115,8 @@ void expr_describe(const struct expr *expr)if (expr->dtype->sym_tbl !=NULL ) {printf ("\npre-defined symbolic constants:\n" ); -symbol_table_print (expr->dtype->sym_tbl, expr->dtype); +symbol_table_print (expr->dtype->sym_tbl, expr->dtype, + expr->byteorder); } }
Signature · 1 line
2.7.4
Pablo Neira Ayuso
maintainerQuoted 35 lines · Elise Lennion
nft describe displays, to the user, which values are available for a selector, then the values should be in host byte order.
Reported-by Pablo Neira Ayuso <[email protected]>Fixes ccc5da470e76 ("datatype: Replace getnameinfo() by internal lookup table")Signed-off-by Elise Lennion <[email protected]>--- include/datatype.h | 3 ++- src/datatype.c | 14 +++++++++++--- src/expression.c | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-)include/datatype.h +2
-1@@ -191,7 +191,8 @@ extern struct error_record *symbolic_constant_parse(const struct expr *sym,extern void symbolic_constant_print (const struct symbol_table *tbl,const struct expr *expr,bool quotes);extern void symbol_table_print (const struct symbol_table *tbl, -const struct datatype *dtype); +const struct datatype *dtype, +enum byteorder byteorder);extern struct symbol_table *rt_symbol_table_init (const char *filename);extern void rt_symbol_table_free (struct symbol_table *tbl);src/datatype.c +0
-1@@ -181,14 +181,22 @@ void symbolic_constant_print(const struct symbol_table *tbl, } void symbol_table_print(const struct symbol_table *tbl, -const struct datatype *dtype)
src/datatype.c void symbolic_constant_print(const struct symbol_table *tbl, · line 193
Quoted 10 lines
src/datatype.c +7
-0+const struct datatype *dtype, + enum byteorder byteorder) { const struct symbolic_constant *s;unsigned int size =2 * dtype->size /BITS_PER_BYTE ; +long unsigned int value; + +for (s = tbl->symbols; s->identifier !=NULL ; s++) { +if (byteorder ==BYTEORDER_BIG_ENDIAN ) + value =__constant_ntohs (s->value);
Is this going to work for other cases other than 16-bit?
You can probably add a function that, based on the datatype, performs the byteswapping based on the integer length.
Thanks.