naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0175-utils-provide-get_hex-to-read-a-hex-digit-from-a-cha.patch

049c96
From 1880eb1a9cd934736ed4b41b247664760bc7b69c Mon Sep 17 00:00:00 2001
049c96
From: Davide Caratti <dcaratti@redhat.com>
049c96
Date: Wed, 6 Jul 2016 18:41:35 +0200
049c96
Subject: [PATCH] utils: provide get_hex to read a hex digit from a char
049c96
049c96
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1300765
049c96
Upstream Status: iproute2.git commit 609640f5f0fe
049c96
049c96
Conflicts: context conflict due to missing code cleanup (lack of upstream
049c96
commit 892e21248cfd)
049c96
049c96
commit 609640f5f0feda8099b04452297d81dd1a8a1777
049c96
Author: Sabrina Dubroca <sd@queasysnail.net>
049c96
Date:   Fri Jun 3 16:45:47 2016 +0200
049c96
049c96
    utils: provide get_hex to read a hex digit from a char
049c96
049c96
    Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
049c96
    Acked-by: Phil Sutter <phil@nwl.cc>
049c96
049c96
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
049c96
---
049c96
 include/utils.h |  1 +
049c96
 ip/ipl2tp.c     | 15 ++-------------
049c96
 lib/ipx_pton.c  | 18 +++---------------
049c96
 lib/utils.c     | 12 ++++++++++++
049c96
 4 files changed, 18 insertions(+), 28 deletions(-)
049c96
049c96
diff --git a/include/utils.h b/include/utils.h
049c96
index 4fd48b6..fad82dc 100644
049c96
--- a/include/utils.h
049c96
+++ b/include/utils.h
049c96
@@ -84,6 +84,7 @@ extern int get_addr(inet_prefix *dst, const char *arg, int family);
049c96
 extern int get_prefix(inet_prefix *dst, char *arg, int family);
049c96
 extern int mask2bits(__u32 netmask);
049c96
 
049c96
+int get_hex(char c);
049c96
 extern int get_integer(int *val, const char *arg, int base);
049c96
 extern int get_unsigned(unsigned *val, const char *arg, int base);
049c96
 extern int get_time_rtt(unsigned *val, const char *arg, int *raw);
049c96
diff --git a/ip/ipl2tp.c b/ip/ipl2tp.c
049c96
index 92e15c5..d2c8979 100644
049c96
--- a/ip/ipl2tp.c
049c96
+++ b/ip/ipl2tp.c
049c96
@@ -424,30 +424,19 @@ static int get_tunnel(struct l2tp_data *p)
049c96
  * Command parser
049c96
  *****************************************************************************/
049c96
 
049c96
-static int hex(char ch)
049c96
-{
049c96
-	if ((ch >= 'a') && (ch <= 'f'))
049c96
-		return ch - 'a' + 10;
049c96
-	if ((ch >= '0') && (ch <= '9'))
049c96
-		return ch - '0';
049c96
-	if ((ch >= 'A') && (ch <= 'F'))
049c96
-		return ch - 'A' + 10;
049c96
-	return -1;
049c96
-}
049c96
-
049c96
 static int hex2mem(const char *buf, uint8_t *mem, int count)
049c96
 {
049c96
 	int i, j;
049c96
 	int c;
049c96
 
049c96
 	for (i = 0, j = 0; i < count; i++, j += 2) {
049c96
-		c = hex(buf[j]);
049c96
+		c = get_hex(buf[j]);
049c96
 		if (c < 0)
049c96
 			goto err;
049c96
 
049c96
 		mem[i] = c << 4;
049c96
 
049c96
-		c = hex(buf[j + 1]);
049c96
+		c = get_hex(buf[j + 1]);
049c96
 		if (c < 0)
049c96
 			goto err;
049c96
 
049c96
diff --git a/lib/ipx_pton.c b/lib/ipx_pton.c
049c96
index 3dca271..071a775 100644
049c96
--- a/lib/ipx_pton.c
049c96
+++ b/lib/ipx_pton.c
049c96
@@ -6,18 +6,6 @@
049c96
 
049c96
 #include "utils.h"
049c96
 
049c96
-static u_int32_t hexget(char c)
049c96
-{
049c96
-	if (c >= 'A' && c <= 'F')
049c96
-		return c - 'A' + 10;
049c96
-	if (c >= 'a' && c <= 'f')
049c96
-		return c - 'a' + 10;
049c96
-	if (c >= '0' && c <= '9')
049c96
-		return c - '0';
049c96
-
049c96
-	return 0xf0;
049c96
-}
049c96
-
049c96
 static int ipx_getnet(u_int32_t *net, const char *str)
049c96
 {
049c96
 	int i;
049c96
@@ -25,7 +13,7 @@ static int ipx_getnet(u_int32_t *net, const char *str)
049c96
 
049c96
 	for(i = 0; *str && (i < 8); i++) {
049c96
 
049c96
-		if ((tmp = hexget(*str)) & 0xf0) {
049c96
+		if ((tmp = get_hex(*str)) == -1) {
049c96
 			if (*str == '.')
049c96
 				return 0;
049c96
 			else
049c96
@@ -49,11 +37,11 @@ static int ipx_getnode(u_int8_t *node, const char *str)
049c96
 	u_int32_t tmp;
049c96
 
049c96
 	for(i = 0; i < 6; i++) {
049c96
-		if ((tmp = hexget(*str++)) & 0xf0)
049c96
+		if ((tmp = get_hex(*str++)) == -1)
049c96
 			return -1;
049c96
 		node[i] = (u_int8_t)tmp;
049c96
 		node[i] <<= 4;
049c96
-		if ((tmp = hexget(*str++)) & 0xf0)
049c96
+		if ((tmp = get_hex(*str++)) == -1)
049c96
 			return -1;
049c96
 		node[i] |= (u_int8_t)tmp;
049c96
 		if (*str == ':')
049c96
diff --git a/lib/utils.c b/lib/utils.c
049c96
index 687c188..dedadff 100644
049c96
--- a/lib/utils.c
049c96
+++ b/lib/utils.c
049c96
@@ -35,6 +35,18 @@
049c96
 
049c96
 int timestamp_short = 0;
049c96
 
049c96
+int get_hex(char c)
049c96
+{
049c96
+	if (c >= 'A' && c <= 'F')
049c96
+		return c - 'A' + 10;
049c96
+	if (c >= 'a' && c <= 'f')
049c96
+		return c - 'a' + 10;
049c96
+	if (c >= '0' && c <= '9')
049c96
+		return c - '0';
049c96
+
049c96
+	return -1;
049c96
+}
049c96
+
049c96
 int get_integer(int *val, const char *arg, int base)
049c96
 {
049c96
 	long res;
049c96
-- 
049c96
1.8.3.1
049c96