* [PATCH iproute2 1/1] utils: make hex2mem available to all users
@ 2017-01-14 22:04 Jamal Hadi Salim
2017-01-14 22:09 ` Jamal Hadi Salim
2017-01-17 16:47 ` Stephen Hemminger
0 siblings, 2 replies; 4+ messages in thread
From: Jamal Hadi Salim @ 2017-01-14 22:04 UTC (permalink / raw)
To: tephen; +Cc: netdev, Jamal Hadi Salim
From: Jamal Hadi Salim <jhs@mojatatu.com>
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 | 1 +
ip/ipl2tp.c | 25 -------------------------
lib/utils.c | 25 +++++++++++++++++++++++++
3 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/include/utils.h b/include/utils.h
index dc1d6b9..22369e0 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -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")
diff --git a/ip/ipl2tp.c b/ip/ipl2tp.c
index 0f91aeb..88664c9 100644
--- a/ip/ipl2tp.c
+++ b/ip/ipl2tp.c
@@ -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)
diff --git a/lib/utils.c b/lib/utils.c
index 83c9d09..870c4f1 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -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;
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH iproute2 1/1] utils: make hex2mem available to all users
2017-01-14 22:04 [PATCH iproute2 1/1] utils: make hex2mem available to all users Jamal Hadi Salim
@ 2017-01-14 22:09 ` Jamal Hadi Salim
2017-01-16 17:51 ` Stephen Hemminger
2017-01-17 16:47 ` Stephen Hemminger
1 sibling, 1 reply; 4+ messages in thread
From: Jamal Hadi Salim @ 2017-01-14 22:09 UTC (permalink / raw)
To: stephen; +Cc: netdev
Sorry, messed up Stephen's address. Resending..
cheers,
jamal
On 17-01-14 05:04 PM, Jamal Hadi Salim wrote:
> From: Jamal Hadi Salim <jhs@mojatatu.com>
>
> 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 | 1 +
> ip/ipl2tp.c | 25 -------------------------
> lib/utils.c | 25 +++++++++++++++++++++++++
> 3 files changed, 26 insertions(+), 25 deletions(-)
>
> diff --git a/include/utils.h b/include/utils.h
> index dc1d6b9..22369e0 100644
> --- a/include/utils.h
> +++ b/include/utils.h
> @@ -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")
> diff --git a/ip/ipl2tp.c b/ip/ipl2tp.c
> index 0f91aeb..88664c9 100644
> --- a/ip/ipl2tp.c
> +++ b/ip/ipl2tp.c
> @@ -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)
> diff --git a/lib/utils.c b/lib/utils.c
> index 83c9d09..870c4f1 100644
> --- a/lib/utils.c
> +++ b/lib/utils.c
> @@ -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;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH iproute2 1/1] utils: make hex2mem available to all users
2017-01-14 22:09 ` Jamal Hadi Salim
@ 2017-01-16 17:51 ` Stephen Hemminger
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2017-01-16 17:51 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: netdev
On Sat, 14 Jan 2017 17:09:58 -0500
Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> Sorry, messed up Stephen's address. Resending..
>
> cheers,
> jamal
No problem. I get almost all patches only from patchwork anyway.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH iproute2 1/1] utils: make hex2mem available to all users
2017-01-14 22:04 [PATCH iproute2 1/1] utils: make hex2mem available to all users Jamal Hadi Salim
2017-01-14 22:09 ` Jamal Hadi Salim
@ 2017-01-17 16:47 ` Stephen Hemminger
1 sibling, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2017-01-17 16:47 UTC (permalink / raw)
To: Jamal Hadi Salim; +Cc: stephen, netdev
On Sat, 14 Jan 2017 17:04:43 -0500
Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> From: Jamal Hadi Salim <jhs@mojatatu.com>
>
> 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>
Both applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-01-17 16:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-14 22:04 [PATCH iproute2 1/1] utils: make hex2mem available to all users Jamal Hadi Salim
2017-01-14 22:09 ` Jamal Hadi Salim
2017-01-16 17:51 ` Stephen Hemminger
2017-01-17 16:47 ` Stephen Hemminger
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.