[PATCH 1/2] mac_pton: support MAC addresses with other delimiters

From: Michael Pratt
Date: Mon Oct 02 2023 - 19:40:27 EST


From: Michael Pratt <mcpratt@xxxxx>

Some network hardware vendors may do something unique
when storing the MAC address into hardware in ASCII,
like using hyphens as the delimiter.

Allow parsing of MAC addresses with a non-standard
delimiter (punctuation other than a colon).

e.g. aa-bb-cc-dd-ee-ff

Signed-off-by: Michael Pratt <mcpratt@xxxxx>
---
lib/net_utils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/net_utils.c b/lib/net_utils.c
index 42bb0473fb22..ecb7625e1dec 100644
--- a/lib/net_utils.c
+++ b/lib/net_utils.c
@@ -18,7 +18,7 @@ bool mac_pton(const char *s, u8 *mac)
for (i = 0; i < ETH_ALEN; i++) {
if (!isxdigit(s[i * 3]) || !isxdigit(s[i * 3 + 1]))
return false;
- if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
+ if (i != ETH_ALEN - 1 && !ispunct(s[i * 3 + 2]))
return false;
}
for (i = 0; i < ETH_ALEN; i++) {
--
2.30.2