[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20110504081225.267a0833@nehalam>
Date: Wed, 4 May 2011 08:12:25 -0700
From: Stephen Hemminger <shemminger@...tta.com>
To: Alexey Dobriyan <adobriyan@...il.com>
Cc: davem@...emloft.net, netdev@...r.kernel.org
Subject: Re: [PATCH] net: add mac_pton() for parsing MAC address
On Wed, 4 May 2011 09:15:51 +0300
Alexey Dobriyan <adobriyan@...il.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.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists