diff options
author | Andy Green <andy.green@linaro.org> | 2012-12-12 00:49:26 +0000 |
---|---|---|
committer | Andy Green <andy.green@linaro.org> | 2012-12-12 00:49:26 +0000 |
commit | 35f13701a5c5717c2240df4d2280eef18a961500 (patch) | |
tree | cdaac46dc007af31214846d03f1473ba1e814328 | |
parent | eb5e5d0e4725d5316bebd2299d18a3a429bb79cf (diff) |
net eth add mac string parser
Signed-off-by: Andy Green <andy.green@linaro.org>
-rw-r--r-- | include/linux/etherdevice.h | 2 | ||||
-rw-r--r-- | net/ethernet/eth.c | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index fe5136d8145..dbafc77dcd6 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -45,7 +45,7 @@ extern void eth_header_cache_update(struct hh_cache *hh, extern int eth_mac_addr(struct net_device *dev, void *p); extern int eth_change_mtu(struct net_device *dev, int new_mtu); extern int eth_validate_addr(struct net_device *dev); - +extern int eth_scan_mac(const char *mac_string, unsigned char *addr); extern struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs, diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index bf10a311cf1..9ab2110ddc2 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -394,3 +394,22 @@ ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len) return (ssize_t)l; } EXPORT_SYMBOL(sysfs_format_mac); + +int eth_scan_mac(const char *mac_string, unsigned char *addr) +{ + int o[ETH_ALEN]; + int n = sscanf(mac_string, "%x:%x:%x:%x:%x:%x", + &o[0], &o[1], &o[2], &o[3], &o[4], &o[5]); + + if (n < 0) + return n; + if (n != ETH_ALEN) + return -EINVAL; + + for (n = 0; n < ETH_ALEN; n++) + *addr++ = o[n]; + + return 0; +} +EXPORT_SYMBOL_GPL(eth_scan_mac); + |