From patchwork Fri Feb 10 11:25:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 726519 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vKXrN35d9z9s6n for ; Fri, 10 Feb 2017 22:33:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mojatatu-com.20150623.gappssmtp.com header.i=@mojatatu-com.20150623.gappssmtp.com header.b="abwnd3vY"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752890AbdBJLdW (ORCPT ); Fri, 10 Feb 2017 06:33:22 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:33007 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752116AbdBJLdT (ORCPT ); Fri, 10 Feb 2017 06:33:19 -0500 Received: by mail-io0-f195.google.com with SMTP id 101so5542110iom.0 for ; Fri, 10 Feb 2017 03:33:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=DhPIdtFPvFYFhhVLADEStg9onX/3iaMjY0QBXaPchmg=; b=abwnd3vYCuc79d6h/e4e+8b9RfbHL4JJM4U3Hw2F7KYCM5FRBg7g35at3tOQakBdne upDa7zoQJXWHs+Zs6GMGBRrkqdL9WLUAiQRKuquYm/9q7Uoauc1Pg6gljoRtYwqg/m3N JG4bzmoD9nJebdb9bEXwc1qFKp7cBvF4pF+ZGmqGWWeeDxP9f2/YnqDO0a2jwPARU1DA UWcWjazv8CQFaXcLejEQUdVvpS0CsuQkl+Zc92i1aVbP2RBOOsGL3IAmMefF3w35NM2l tX3OVnBAfmw3Uf7O4ZHLrVooTjPjG/gtViv/ZEmeKiXRZ3ZfW3mKM9RYphfQqtNbA6Wg x6JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DhPIdtFPvFYFhhVLADEStg9onX/3iaMjY0QBXaPchmg=; b=Rg4F2sUfhZROeD3Pksp2pR0pv9CnTCg28gXkDE9YEviPUAHnW5lHUXSLt9wSUJgkia 9GtKeuvt2ImNlwGX4+6v9nvayVR7uG7nThaUMx8zbh6G6itYNBSRAu95Y64iqRSToi+l x0E60/vUtVNhKPIk4BdXHYGUZxOTeje2tbrjTTOsPIB9vKfDpb/qwMPRAb1CCCZAc0// OA27FHRtVnj0omp1OpxWJl+eF3IjVa5OjBX/Zgf+bDnrSiHp2GNcj23a2XCvGWCigbQu 1l4KOWQACSypuXYA78nDPy7nfHAJgsFkkEYpOMcSJ5jJsR9Kyz5RjjC8eSPelyaHzHbq 8j7A== X-Gm-Message-State: AMke39llh4CJOZb887K8EmmMFa3EywP+rsSFt5sprPCtB0Q8qrQXGC0LG8YWsLJYdBtvfQ== X-Received: by 10.107.38.145 with SMTP id m139mr8069032iom.56.1486725954227; Fri, 10 Feb 2017 03:25:54 -0800 (PST) Received: from localhost.localdomain (23-233-25-245.cpe.pppoe.ca. [23.233.25.245]) by smtp.gmail.com with ESMTPSA id v197sm240967ita.2.2017.02.10.03.25.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 10 Feb 2017 03:25:53 -0800 (PST) From: Jamal Hadi Salim X-Google-Original-From: Jamal Hadi Salim To: stephen@networkplumber.org Cc: netdev@vger.kernel.org, mrv@mojatatu.com, Jamal Hadi Salim Subject: [PATCH v2 iproute2 1/2] utils: make hex2mem available to all users Date: Fri, 10 Feb 2017 06:25:43 -0500 Message-Id: <1486725944-16898-1-git-send-email-jhs@emojatatu.com> X-Mailer: git-send-email 1.9.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jamal Hadi Salim hex2mem() api is useful for parsing hexstrings which are then packed in a stream of chars. Signed-off-by: Jamal Hadi Salim --- 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;