]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: Display pre-defined inet_service values in decimal base
authorElise Lennion <elise.lennion@gmail.com>
Sat, 10 Dec 2016 23:59:36 +0000 (21:59 -0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 11 Dec 2016 19:32:35 +0000 (20:32 +0100)
because the convention is to represent ports in base 10.

gcc-workaround is no longer needed and was removed.

Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/datatype.h
src/datatype.c
src/services.c

index a7db1df4c070f7e97c97b9b1bebc3bef09f13574..9f127f2954e3585d42fa1be9c9864cff74e5195a 100644 (file)
@@ -175,13 +175,25 @@ struct symbolic_constant {
 #define SYMBOL(id, v)  { .identifier = (id), .value = (v) }
 #define SYMBOL_LIST_END        (struct symbolic_constant) { }
 
+/**
+ * enum base - indicate how to display symbol table values
+ *
+ * @BASE_HEXADECIMAL:  hexadecimal
+ * @BASE_DECIMAL:      decimal
+ */
+enum base {
+       BASE_HEXADECIMAL,
+       BASE_DECIMAL,
+};
+
 /**
  * struct symbol_table - type construction from symbolic values
  *
+ * @base:      base of symbols representation
  * @symbols:   the symbols
  */
 struct symbol_table {
-       int                             gcc_workaround;
+       enum base                       base;
        struct symbolic_constant        symbols[];
 };
 
index 5600efcc2cd0085ed8e28669f3b92faa8ec02e67..ec0b12013677dab60687db7811aa41597e5f7026 100644 (file)
@@ -204,8 +204,11 @@ void symbol_table_print(const struct symbol_table *tbl,
                if (byteorder == BYTEORDER_BIG_ENDIAN)
                        switch_byteorder(&value, len);
 
-               printf("\t%-30s\t0x%.*" PRIx64 "\n",
-                      s->identifier, 2 * len, value);
+               if (tbl->base == BASE_DECIMAL)
+                       printf("\t%-30s\t%20lu\n", s->identifier, value);
+               else
+                       printf("\t%-30s\t0x%.*" PRIx64 "\n",
+                              s->identifier, 2 * len, value);
        }
 }
 
index 0ba195e9ccc2537cf8c0aeef2528ea0c7198148d..83c2672317bca9ddc4e54b818426468dd36f6d6c 100644 (file)
@@ -2,7 +2,8 @@
 #include <datatype.h>
 
 const struct symbol_table inet_service_tbl = {
-       .symbols =      {
+       .base           = BASE_DECIMAL,
+       .symbols        = {
                SYMBOL("tcpmux",                __constant_htons(1)),
                SYMBOL("echo",                  __constant_htons(7)),
                SYMBOL("discard",               __constant_htons(9)),