From: Hauke Mehrtens Date: Wed, 24 Aug 2011 11:20:37 +0000 (+0200) Subject: compat: add mac_pton() X-Git-Tag: compat-2011-09-28~9 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=fbf40660143b4612aa16623793fc3520dd0a5d7c;p=~emulex%2Ftmp%2Fcompat%2F.git compat: add mac_pton() Signed-off-by: Hauke Mehrtens --- diff --git a/compat/Makefile b/compat/Makefile index e2a6add..8e3739c 100644 --- a/compat/Makefile +++ b/compat/Makefile @@ -33,4 +33,5 @@ compat-$(CONFIG_COMPAT_KERNEL_2_6_38) += compat-2.6.38.o compat-$(CONFIG_COMPAT_KERNEL_2_6_39) += \ compat-2.6.39.o \ kstrtox.o +compat-$(CONFIG_COMPAT_KERNEL_3_0) += compat-3.0.o diff --git a/compat/compat-3.0.c b/compat/compat-3.0.c new file mode 100644 index 0000000..312eea0 --- /dev/null +++ b/compat/compat-3.0.c @@ -0,0 +1,37 @@ +/* + * Copyright 2011 Hauke Mehrtens + * Copyright 2011 Alexey Dobriyan + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Compatibility file for Linux wireless for kernels 3.0. + */ + +#include +#include + +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 dirty result unless string is valid MAC. */ + 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 (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]); + } + return 1; +} +EXPORT_SYMBOL(mac_pton); diff --git a/include/linux/compat-3.0.h b/include/linux/compat-3.0.h index 667ea38..7954ddb 100644 --- a/include/linux/compat-3.0.h +++ b/include/linux/compat-3.0.h @@ -46,6 +46,8 @@ struct bcma_device_id { #define BCMA_ANY_CLASS 0xFF #endif /* BCMA_CORE */ +int mac_pton(const char *s, u8 *mac); + #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)) */ #endif /* LINUX_3_0_COMPAT_H */