[PATCH 4/4] net: implement ethaddr_string_cmp()
Sascha Hauer
s.hauer at pengutronix.de
Wed Nov 27 23:52:18 PST 2024
On Thu, Nov 28, 2024 at 08:43:12AM +0100, Ahmad Fatoum wrote:
> On 28.11.24 08:36, Sascha Hauer wrote:
> > On Tue, Nov 26, 2024 at 04:17:44PM +0100, Ahmad Fatoum wrote:
> >> We keep ethernet addresses either in binary or in text form at a couple
> >> of places, e.g. device tree, device parameters, struct net_device,
> >> ... etc. We have memcmp() and strcmp() respectively to compare each, add
> >> one more function to compare a text string with binary. This will be
> >> used in a follow up commit.
> >>
> >> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> >> ---
> >> include/net.h | 2 ++
> >> net/lib.c | 17 +++++++++++++++++
> >> 2 files changed, 19 insertions(+)
> >>
> >> diff --git a/include/net.h b/include/net.h
> >> index d9b7953a3c33..dbc45b806a51 100644
> >> --- a/include/net.h
> >> +++ b/include/net.h
> >> @@ -366,6 +366,8 @@ IPaddr_t getenv_ip(const char *name);
> >> int setenv_ip(const char *name, IPaddr_t ip);
> >>
> >> int string_to_ethaddr(const char *str, u8 enetaddr[6]);
> >> +void ethaddr_to_string(const u8 enetaddr[6], char *str);
> >> +int ethaddr_string_cmp(const u8 enetaddr_a[6], const char *str_b);
> >>
> >> #ifdef CONFIG_NET_RESOLV
> >> int resolv(const char *host, IPaddr_t *ip);
> >> diff --git a/net/lib.c b/net/lib.c
> >> index dc6e138f392c..59bd4c280caf 100644
> >> --- a/net/lib.c
> >> +++ b/net/lib.c
> >> @@ -37,6 +37,23 @@ int string_to_ethaddr(const char *str, u8 enetaddr[ETH_ALEN])
> >> return 0;
> >> }
> >>
> >> +void ethaddr_to_string(const u8 enetaddr[ETH_ALEN], char *str)
> >> +{
> >> + sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
> >> + enetaddr[0], enetaddr[1], enetaddr[2], enetaddr[3],
> >> + enetaddr[4], enetaddr[5]);
> >> +}
> >
> > Do you reintroduce this function on purpose or due to rebasing
> > conflicts? A MAC address can now be printed with "%pM".
>
> I wanted to avoid the CONFIG_PRINTF_HEXSTR dependency.
CONFIG_PRINTF_HEXSTR is for printing hexdumps using printf.
MAC address printing is compiled in unconditionally (and must be,
because the ethernet code is using it).
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list