From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 39C9CA00E6 for ; Thu, 16 May 2019 09:28:15 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E02A94D27; Thu, 16 May 2019 09:28:13 +0200 (CEST) Received: from mail-vs1-f65.google.com (mail-vs1-f65.google.com [209.85.217.65]) by dpdk.org (Postfix) with ESMTP id CCDD4397D for ; Thu, 16 May 2019 09:28:11 +0200 (CEST) Received: by mail-vs1-f65.google.com with SMTP id e2so1634206vsc.13 for ; Thu, 16 May 2019 00:28:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nxrDmh8cNN+DBZgovnmkbB5LJ2o10bGbQGsd8E2j0TQ=; b=R8injxNXXzqGWXk/AVocvtmetW2MLWLc3YnldbP4exng7749Xw+ueXotGDARbX9y+B QgGkjetmb50SfnJYwaaX/09FI0vt/gt59pNAf0DR+cEKfjzqajN7e7QjMgj0hdZrso5j E5IWluWrc82+uy5REBxVWYN+jCFv9P+PpH3nR90NFVmpX+zXZBvzxOqUhFTljCWa6obJ HEXYDQQtgnZcrx7yA46GeiOPwVrFpNoZsToM5qz753c9KgL+myBDiTDXAoB54sSOYhNO 6jKC3pqCAxfq0kAMeTFEv8HEtuucG8GVdoNGXYuojnZmIAkarr5/faabfA2V/YCo5Cci S0ZQ== X-Gm-Message-State: APjAAAX9r7KneTjaKmokIRYo8MUPhNMZYLcu2g6nn5/Tz7+sKEyRsevm G9pVhnwdqZhBUQAcS54q6wqqv8kJ16YbdtCga1gDeA== X-Google-Smtp-Source: APXvYqy3hRlSECH6v8LaaLtBnIpTONPwpKIeqRFLTXjElaTukSkEV6FA1seNcnGm4j+MoRQmI8D9U0Da7TvL5OEObX4= X-Received: by 2002:a67:d615:: with SMTP id n21mr7692247vsj.39.1557991691217; Thu, 16 May 2019 00:28:11 -0700 (PDT) MIME-Version: 1.0 References: <20190515221952.21959-1-stephen@networkplumber.org> <20190515221952.21959-3-stephen@networkplumber.org> In-Reply-To: <20190515221952.21959-3-stephen@networkplumber.org> From: David Marchand Date: Thu, 16 May 2019 09:28:00 +0200 Message-ID: To: Stephen Hemminger Cc: dev Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] [RFC 2/4] net/ether: add eth_unformat_addr X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190516072800.O0Dxh1zL9daz7pNyXPFb9bTeDfS5FRhfmOAGYAMTz_A@z> On Thu, May 16, 2019 at 12:20 AM Stephen Hemminger < stephen@networkplumber.org> wrote: > Make a function that coresponds with eth_aton_r which can > nit: corresponds be used to convert string to ether_addr. > > This also allows rte_ethdev to no longer depend on the > cmdline library. > > Signed-off-by: Stephen Hemminger > --- > lib/librte_net/rte_ether.c | 12 ++++++++++++ > lib/librte_net/rte_ether.h | 14 ++++++++++++++ > lib/librte_net/rte_net_version.map | 1 + > 3 files changed, 27 insertions(+) > > diff --git a/lib/librte_net/rte_ether.c b/lib/librte_net/rte_ether.c > index d4b41f122a16..ca7c841db197 100644 > --- a/lib/librte_net/rte_ether.c > +++ b/lib/librte_net/rte_ether.c > @@ -27,3 +27,15 @@ ether_format_addr(char *buf, uint16_t size, > eth_addr->addr_bytes[4], > eth_addr->addr_bytes[5]); > } > + > +int __rte_experimental > You don't need the experimental tag in the .c. +ether_unformat_addr(const char *str, struct ether_addr *eth_addr) > +{ > + return (sscanf(str, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", > + ð_addr->addr_bytes[0], > + ð_addr->addr_bytes[1], > + ð_addr->addr_bytes[2], > + ð_addr->addr_bytes[3], > + ð_addr->addr_bytes[4], > + ð_addr->addr_bytes[5]) == 6) ? 0 : -1; > +} > Using scanf this way, you won't detect trailing characters And I am not sure this format would detect something like: 00:11:22:33:44:555 diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h > index 46d40412763c..b94e64b2195e 100644 > --- a/lib/librte_net/rte_ether.h > +++ b/lib/librte_net/rte_ether.h > @@ -248,6 +248,20 @@ void > ether_format_addr(char *buf, uint16_t size, > const struct ether_addr *eth_addr); > > +/** > + * Convert string with Ethernet address to an ether_addr. > + * > + * @param str > + * A pointer to buffer contains the formatted MAC address. > + * @param eth_addr > + * A pointer to a ether_addr structure. > + * @return > + * 0 if successful > + * -1 and sets rte_errno if invalid string > + */ > +int __rte_experimental > +ether_unformat_addr(const char *str, struct ether_addr *eth_addr); > + > /** > * Ethernet header: Contains the destination address, source address > * and frame type. > diff --git a/lib/librte_net/rte_net_version.map > b/lib/librte_net/rte_net_version.map > index 49d34093781c..bbf14ff1cdfa 100644 > --- a/lib/librte_net/rte_net_version.map > +++ b/lib/librte_net/rte_net_version.map > @@ -26,4 +26,5 @@ EXPERIMENTAL { > > rte_net_make_rarp_packet; > rte_net_skip_ip6_ext; > + eth_unformat_addr; > Ditto previous patch, can we prefix this with rte_ ? -- David Marchand