From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by dpdk.org (Postfix) with ESMTP id DD2438E70 for ; Mon, 19 Oct 2015 15:50:38 +0200 (CEST) Received: by wijp11 with SMTP id p11so7137858wij.0 for ; Mon, 19 Oct 2015 06:50:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type; bh=yfu9cTq8hlFmQK8PWE0hblggJAHwKTwTgpQWY1zIqkY=; b=NBydd90nESRFfWZBYJKeCWCc7nf3npR5+kYqGj39qcb/f6mS9Yv6tTYysbEGDPYpjz 5/mPbzSNMR5vXYXMBJx54WYCrFo74JqpX6AiBxMq2pYsEdbXADtCcJ7CpxwMOx7VIuHj t3UQRenuQ9Q+uEBNJKXmaNK6eUsH8LpB7uG90fj1LS8/cKUUXfj3h1jve7VwdjyidAKZ 9pmjnJNd5Y4Xy11muM/MLhyjWsg3QMPUGe+KIzXIWNiW41VZ0CRLtG+7Q2TdvazpmfxD luuw6Vp/KbopsNGgvdt3NrHr0WlScJsfSEL4MhWVnbT+uDnJZdB7y77E9hDZNdBtCEB6 DBuA== X-Gm-Message-State: ALoCoQm5VnDRA5JhBBB/M/UjNtyW9pVrpvrm54R+5aknHXd+6CNRutFCTiP7m8LOzeV5WjTEombM X-Received: by 10.194.52.106 with SMTP id s10mr31995979wjo.35.1445262638712; Mon, 19 Oct 2015 06:50:38 -0700 (PDT) Received: from xps13.localnet (136-92-190-109.dsl.ovh.fr. [109.190.92.136]) by smtp.gmail.com with ESMTPSA id fp4sm7763252wib.24.2015.10.19.06.50.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2015 06:50:36 -0700 (PDT) From: Thomas Monjalon To: Jasvinder Singh Date: Mon, 19 Oct 2015 15:49:32 +0200 Message-ID: <2304122.ekIElQmNCJ@xps13> Organization: 6WIND User-Agent: KMail/4.14.10 (Linux/4.1.6-1-ARCH; KDE/4.14.11; x86_64; ; ) In-Reply-To: <1444744652-573-7-git-send-email-jasvinder.singh@intel.com> References: <1444744652-573-1-git-send-email-jasvinder.singh@intel.com> <1444744652-573-7-git-send-email-jasvinder.singh@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH v2 6/8] example/ip_pipeline: add parse_hex_string for internal use X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2015 13:50:39 -0000 2015-10-13 14:57, Jasvinder Singh: > From: Fan Zhang > +static uint32_t > +get_hex_val(char c) > +{ > + switch (c) { > + case '0': > + case '1': > + case '2': > + case '3': > + case '4': > + case '5': > + case '6': > + case '7': > + case '8': > + case '9': > + return c - '0'; > + case 'A': > + case 'B': > + case 'C': > + case 'D': > + case 'E': > + case 'F': > + return c - 'A' + 10; > + case 'a': > + case 'b': > + case 'c': > + case 'd': > + case 'e': > + case 'f': > + return c - 'a' + 10; > + default: > + return 0; > + } > +} > + > +int > +parse_hex_string(char *src, uint8_t *dst, uint32_t *size) > +{ > + char *c; > + uint32_t len, i; > + > + /* Check input parameters */ > + if ((src == NULL) || > + (dst == NULL) || > + (size == NULL) || > + (*size == 0)) > + return -1; > + > + len = strlen(src); > + if (((len & 3) != 0) || > + (len > (*size) * 2)) > + return -1; > + *size = len / 2; > + > + for (c = src; *c != 0; c++) { > + if ((((*c) >= '0') && ((*c) <= '9')) || > + (((*c) >= 'A') && ((*c) <= 'F')) || > + (((*c) >= 'a') && ((*c) <= 'f'))) > + continue; > + > + return -1; > + } > + > + /* Convert chars to bytes */ > + for (i = 0; i < *size; i++) > + dst[i] = get_hex_val(src[2 * i]) * 16 + > + get_hex_val(src[2 * i + 1]); > + > + return 0; > +} Why not use strtol()?