netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elise Lennion <elise.lennion@gmail.com>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] datatype: Display pre-defined inet_service values in decimal base
Date: Sat, 10 Dec 2016 21:59:36 -0200	[thread overview]
Message-ID: <20161210235936.GA4967@lennorien.com> (raw)

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>
---
 include/datatype.h | 18 +++++++++++++++++-
 src/datatype.c     |  7 +++++--
 src/services.c     |  3 ++-
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/include/datatype.h b/include/datatype.h
index a7db1df..cf76fcf 100644
--- a/include/datatype.h
+++ b/include/datatype.h
@@ -176,12 +176,28 @@ struct symbolic_constant {
 #define SYMBOL_LIST_END	(struct symbolic_constant) { }
 
 /**
+ * enum base
+ *
+ * @BASE_HEXADECIMAL:	hexadecimal
+ * @BASE_DECIMAL:	decimal
+ * @BASE_OCTAL:		octal
+ * @BASE_BINARY:	binary
+ */
+enum base {
+	BASE_HEXADECIMAL,
+	BASE_DECIMAL,
+	BASE_OCTAL,
+	BASE_BINARY,
+};
+
+/**
  * 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[];
 };
 
diff --git a/src/datatype.c b/src/datatype.c
index 5600efc..ec0b120 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -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);
 	}
 }
 
diff --git a/src/services.c b/src/services.c
index 0ba195e..83c2672 100644
--- a/src/services.c
+++ b/src/services.c
@@ -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)),
-- 
2.7.4


             reply	other threads:[~2016-12-10 23:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-10 23:59 Elise Lennion [this message]
2016-12-11 19:36 ` [PATCH nft] datatype: Display pre-defined inet_service values in decimal base Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161210235936.GA4967@lennorien.com \
    --to=elise.lennion@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).