1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
14 #include <sys/types.h>
16 #include <rte_string_fns.h>
17 #include <rte_ether.h>
19 #include "cmdline_parse.h"
20 #include "cmdline_parse_etheraddr.h"
22 struct cmdline_token_ops cmdline_token_etheraddr_ops = {
23 .parse = cmdline_parse_etheraddr,
24 .complete_get_nb = NULL,
25 .complete_get_elt = NULL,
26 .get_help = cmdline_get_help_etheraddr,
30 cmdline_parse_etheraddr(__rte_unused cmdline_parse_token_hdr_t *tk,
31 const char *buf, void *res, unsigned ressize)
33 unsigned int token_len = 0;
34 char ether_str[RTE_ETHER_ADDR_FMT_SIZE];
35 struct rte_ether_addr tmp;
37 if (res && ressize < sizeof(tmp))
43 while (!cmdline_isendoftoken(buf[token_len]))
46 /* if token doesn't match possible string lengths... */
47 if (token_len >= RTE_ETHER_ADDR_FMT_SIZE)
50 strlcpy(ether_str, buf, token_len + 1);
52 if (rte_ether_unformat_addr(ether_str, &tmp) < 0)
56 memcpy(res, &tmp, sizeof(tmp));
61 cmdline_get_help_etheraddr(__rte_unused cmdline_parse_token_hdr_t *tk,
62 char *dstbuf, unsigned int size)
66 ret = snprintf(dstbuf, size, "Ethernet address");