[dpdk-dev] [PATCH v3 2/6] net/ether: add rte_eth_unformat_addr

Stephen Hemminger stephen at networkplumber.org
Wed Jun 5 18:31:31 CEST 2019


On Wed, 5 Jun 2019 11:55:21 +0300
Andrew Rybchenko <arybchenko at solarflare.com> wrote:

> On 6/5/19 4:08 AM, Stephen Hemminger wrote:
> > Make a function that coresponds with eth_aton_r which can  
> 
> I guess ether_aton_r
> 
> > be used to convert string to rte_ether_addr.
> >
> > This also allows rte_ethdev to no longer depend on the
> > cmdline library.
> >
> > Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> > ---
> >   lib/librte_net/rte_ether.c         | 47 ++++++++++++++++++++++++++++++
> >   lib/librte_net/rte_ether.h         | 14 +++++++++
> >   lib/librte_net/rte_net_version.map |  1 +
> >   3 files changed, 62 insertions(+)
> >
> > diff --git a/lib/librte_net/rte_ether.c b/lib/librte_net/rte_ether.c
> > index 974fe815b335..acc8a0e938c5 100644
> > --- a/lib/librte_net/rte_ether.c
> > +++ b/lib/librte_net/rte_ether.c
> > @@ -27,3 +27,50 @@ rte_ether_format_addr(char *buf, uint16_t size,
> >   		 eth_addr->addr_bytes[4],
> >   		 eth_addr->addr_bytes[5]);
> >   }
> > +
> > +/*
> > + * Like ether_aton_r but can handle either
> > + * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
> > + */
> > +int
> > +rte_ether_unformat_addr(const char *s, struct rte_ether_addr *ea)
> > +{
> > +	unsigned int o0, o1, o2, o3, o4, o5;
> > +	int n;
> > +
> > +	n = sscanf(s, "%x:%x:%x:%x:%x:%x",
> > +		    &o0, &o1, &o2, &o3, &o4, &o5);  
> 
> Is it intended that the following input will pass?
>   "af:bb:03:65:dc:ddobar" or  "af:bb:03:65:dc:dd foobar"
> 
> I guess yes since ether_aton() accepts it. If so,
> Reviewed-by: Andrew Rybchenko <arybchenko at solarflare.com>

you are right ether_aton has same logic.
doing something more complex is possible but not really needed.


More information about the dev mailing list