From: Stephen Hemminger <shemminger@vyatta.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: Re: [PATCH] net: add mac_pton() for parsing MAC address
Date: Wed, 4 May 2011 08:12:25 -0700 [thread overview]
Message-ID: <20110504081225.267a0833@nehalam> (raw)
In-Reply-To: <20110504061551.GA12297@p183>
On Wed, 4 May 2011 09:15:51 +0300
Alexey Dobriyan <adobriyan@gmail.com> wrote:
> +int mac_pton(const char *s, u8 *mac)
> +{
> + int i;
> +
> + /* XX:XX:XX:XX:XX:XX */
> + if (strlen(s) < 3 * ETH_ALEN - 1)
> + return 0;
> +
> + /* Don't half dirty result. */
Shouldn't this be "Don't allow dirty result."?
> + for (i = 0; i < ETH_ALEN; i++) {
> + if (!strchr("0123456789abcdefABCDEF", s[i * 3]))
> + return 0;
> + if (!strchr("0123456789abcdefABCDEF", s[i * 3 + 1]))
> + return 0;
if (!isxdigit(s[i*3]) || !isxdigit(s[i*3+1]))
return 0;
> + if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
> + return 0;
> + }
> + for (i = 0; i < ETH_ALEN; i++) {
> + mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
hex2bin(&mac[i], &s[i*3], 1);
> + }
> + return 1;
> +}
> +EXPORT_SYMBOL(mac_pton);
Also don't need two loops, okay to parse partial result.
next prev parent reply other threads:[~2011-05-04 15:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-04 6:15 [PATCH] net: add mac_pton() for parsing MAC address Alexey Dobriyan
2011-05-04 15:12 ` Stephen Hemminger [this message]
2011-05-04 17:39 ` Alexey Dobriyan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110504081225.267a0833@nehalam \
--to=shemminger@vyatta.com \
--cc=adobriyan@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).