public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 1/2] alfred: Use constant to define data type range
Date: Mon, 24 Jul 2017 23:18:51 +0200	[thread overview]
Message-ID: <20170724211852.14907-1-sven@narfation.org> (raw)
In-Reply-To: <13899415.9hl4lahuAs@sven-edge>

The maximum number of data types supported by alfred is limited by the
range of an uint8_t (0-255). alfred checks in the client mode whether data
type parameter is in the supported range by comparing it against
ALFRED_MAX_RESERVED_TYPE as lower bound and the magic number 255 as upper
bound.

Instead of using 255 in multiple places, define a named constant which can
be referenced. This makes it easier to understand these comparisons and to
reference this limit in a consistent way.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 main.c   | 6 ++++--
 packet.h | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c
index 446eecf..ad6d081 100644
--- a/main.c
+++ b/main.c
@@ -213,7 +213,8 @@ static struct globals *alfred_init(int argc, char *argv[])
 		case 'r':
 			globals->clientmode = CLIENT_REQUEST_DATA;
 			i = atoi(optarg);
-			if (i < ALFRED_MAX_RESERVED_TYPE || i > 255) {
+			if (i < ALFRED_MAX_RESERVED_TYPE ||
+			    i >= ALFRED_NUM_TYPES) {
 				fprintf(stderr, "bad data type argument\n");
 				return NULL;
 			}
@@ -223,7 +224,8 @@ static struct globals *alfred_init(int argc, char *argv[])
 		case 's':
 			globals->clientmode = CLIENT_SET_DATA;
 			i = atoi(optarg);
-			if (i < ALFRED_MAX_RESERVED_TYPE || i > 255) {
+			if (i < ALFRED_MAX_RESERVED_TYPE ||
+			    i >= ALFRED_NUM_TYPES) {
 				fprintf(stderr, "bad data type argument\n");
 				return NULL;
 			}
diff --git a/packet.h b/packet.h
index afd3715..425459f 100644
--- a/packet.h
+++ b/packet.h
@@ -177,5 +177,6 @@ struct alfred_status_v0 {
 #define ALFRED_VERSION			0
 #define ALFRED_PORT			0x4242
 #define ALFRED_MAX_RESERVED_TYPE	64
+#define ALFRED_NUM_TYPES		256
 
 #endif
-- 
2.11.0


  reply	other threads:[~2017-07-24 21:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-24 21:18 [B.A.T.M.A.N.] [PATCH 0/2] alfred: Use bitmap to store dataset change events Sven Eckelmann
2017-07-24 21:18 ` Sven Eckelmann [this message]
2017-07-24 21:18 ` [B.A.T.M.A.N.] [PATCH 2/2] " Sven Eckelmann
2017-07-31  8:57 ` [B.A.T.M.A.N.] [PATCH 0/2] " Simon Wunderlich

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=20170724211852.14907-1-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.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