1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
10 #include <rte_string_fns.h>
11 #include <rte_ether.h>
13 #include "cmdline_parse.h"
14 #include "cmdline_parse_etheraddr.h"
16 struct cmdline_token_ops cmdline_token_etheraddr_ops = {
17 .parse = cmdline_parse_etheraddr,
18 .complete_get_nb = NULL,
19 .complete_get_elt = NULL,
20 .get_help = cmdline_get_help_etheraddr,
24 cmdline_parse_etheraddr(__rte_unused cmdline_parse_token_hdr_t *tk,
25 const char *buf, void *res, unsigned ressize)
27 unsigned int token_len = 0;
28 char ether_str[RTE_ETHER_ADDR_FMT_SIZE];
29 struct rte_ether_addr tmp;
31 if (res && ressize < sizeof(tmp))
37 while (!cmdline_isendoftoken(buf[token_len]))
40 /* if token doesn't match possible string lengths... */
41 if (token_len >= RTE_ETHER_ADDR_FMT_SIZE)
44 strlcpy(ether_str, buf, token_len + 1);
46 if (rte_ether_unformat_addr(ether_str, &tmp) < 0)
50 memcpy(res, &tmp, sizeof(tmp));
55 cmdline_get_help_etheraddr(__rte_unused cmdline_parse_token_hdr_t *tk,
56 char *dstbuf, unsigned int size)
60 ret = snprintf(dstbuf, size, "Ethernet address");