diff options
| author | Alexey Dobriyan <adobriyan@gmail.com> | 2011-05-07 19:00:07 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2011-05-09 15:10:49 -0400 |
| commit | 4940fc889e1e63667a15243028ddcd84d471cd8e (patch) | |
| tree | c52bb193d0ad4f13e0f617748ed1db297261f521 /net/core/netpoll.c | |
| parent | 99f823f98fb981b55c663a3783c3d2293958ece4 (diff) | |
net: add mac_pton() for parsing MAC address
mac_pton() parses MAC address in form XX:XX:XX:XX:XX:XX and only in that form.
mac_pton() doesn't dirty result until it's sure string representation is valid.
mac_pton() doesn't care about characters _after_ last octet,
it's up to caller to deal with it.
mac_pton() diverges from 0/-E return value convention.
Target usage:
if (!mac_pton(str, whatever->mac))
return -EINVAL;
/* ->mac being u8 [ETH_ALEN] is filled at this point. */
/* optionally check str[3 * ETH_ALEN - 1] for termination */
Use mac_pton() in pktgen and netconsole for start.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/netpoll.c')
| -rw-r--r-- | net/core/netpoll.c | 26 |
1 files changed, 1 insertions, 25 deletions
diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 46d9c3a4de2f..2d7d6d473781 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c | |||
| @@ -698,32 +698,8 @@ int netpoll_parse_options(struct netpoll *np, char *opt) | |||
| 698 | 698 | ||
| 699 | if (*cur != 0) { | 699 | if (*cur != 0) { |
| 700 | /* MAC address */ | 700 | /* MAC address */ |
| 701 | if ((delim = strchr(cur, ':')) == NULL) | 701 | if (!mac_pton(cur, np->remote_mac)) |
| 702 | goto parse_failed; | 702 | goto parse_failed; |
| 703 | *delim = 0; | ||
| 704 | np->remote_mac[0] = simple_strtol(cur, NULL, 16); | ||
| 705 | cur = delim + 1; | ||
| 706 | if ((delim = strchr(cur, ':')) == NULL) | ||
| 707 | goto parse_failed; | ||
| 708 | *delim = 0; | ||
| 709 | np->remote_mac[1] = simple_strtol(cur, NULL, 16); | ||
| 710 | cur = delim + 1; | ||
| 711 | if ((delim = strchr(cur, ':')) == NULL) | ||
| 712 | goto parse_failed; | ||
| 713 | *delim = 0; | ||
| 714 | np->remote_mac[2] = simple_strtol(cur, NULL, 16); | ||
| 715 | cur = delim + 1; | ||
| 716 | if ((delim = strchr(cur, ':')) == NULL) | ||
| 717 | goto parse_failed; | ||
| 718 | *delim = 0; | ||
| 719 | np->remote_mac[3] = simple_strtol(cur, NULL, 16); | ||
| 720 | cur = delim + 1; | ||
| 721 | if ((delim = strchr(cur, ':')) == NULL) | ||
| 722 | goto parse_failed; | ||
| 723 | *delim = 0; | ||
| 724 | np->remote_mac[4] = simple_strtol(cur, NULL, 16); | ||
| 725 | cur = delim + 1; | ||
| 726 | np->remote_mac[5] = simple_strtol(cur, NULL, 16); | ||
| 727 | } | 703 | } |
| 728 | 704 | ||
| 729 | netpoll_print_options(np); | 705 | netpoll_print_options(np); |
