]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
utils: make hex2mem available to all users
authorJamal Hadi Salim <jhs@mojatatu.com>
Sat, 14 Jan 2017 22:04:43 +0000 (17:04 -0500)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 17 Jan 2017 16:45:22 +0000 (08:45 -0800)
hex2mem() api is useful for parsing hexstrings which are then packed in
a stream of chars.

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
include/utils.h
ip/ipl2tp.c
lib/utils.c

index dc1d6b9607dd870f9f5d87ea567115b62017f015..22369e0b4e0374958988a12eb2d5b1af8cb91284 100644 (file)
@@ -118,6 +118,7 @@ int get_be32(__be32 *val, const char *arg, int base);
 int get_be16(__be16 *val, const char *arg, int base);
 int get_addr64(__u64 *ap, const char *cp);
 
+int hex2mem(const char *buf, uint8_t *mem, int count);
 char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen);
 __u8 *hexstring_a2n(const char *str, __u8 *buf, int blen, unsigned int *len);
 #define ADDR64_BUF_SIZE sizeof("xxxx:xxxx:xxxx:xxxx")
index 0f91aebff66088620a7eaf269bf9688cfb67e131..88664c909e11f7f6038eedb8d1691f94f0e33a7b 100644 (file)
@@ -485,31 +485,6 @@ static int get_tunnel(struct l2tp_data *p)
  * Command parser
  *****************************************************************************/
 
-static int hex2mem(const char *buf, uint8_t *mem, int count)
-{
-       int i, j;
-       int c;
-
-       for (i = 0, j = 0; i < count; i++, j += 2) {
-               c = get_hex(buf[j]);
-               if (c < 0)
-                       goto err;
-
-               mem[i] = c << 4;
-
-               c = get_hex(buf[j + 1]);
-               if (c < 0)
-                       goto err;
-
-               mem[i] |= c;
-       }
-
-       return 0;
-
-err:
-       return -1;
-}
-
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
index 83c9d097c60828ff3de1670e14d61b06a9b2bc32..870c4f1b8b41e5d725485f54b9edf2c6b6d33413 100644 (file)
@@ -962,6 +962,31 @@ __u8 *hexstring_a2n(const char *str, __u8 *buf, int blen, unsigned int *len)
        return buf;
 }
 
+int hex2mem(const char *buf, uint8_t *mem, int count)
+{
+       int i, j;
+       int c;
+
+       for (i = 0, j = 0; i < count; i++, j += 2) {
+               c = get_hex(buf[j]);
+               if (c < 0)
+                       goto err;
+
+               mem[i] = c << 4;
+
+               c = get_hex(buf[j + 1]);
+               if (c < 0)
+                       goto err;
+
+               mem[i] |= c;
+       }
+
+       return 0;
+
+err:
+       return -1;
+}
+
 int addr64_n2a(__u64 addr, char *buff, size_t len)
 {
        __u16 *words = (__u16 *)&addr;