2018-01-29 13:11:20 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2010-2014 Intel Corporation.
|
2012-09-04 12:54:00 +00:00
|
|
|
* Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <rte_string_fns.h>
|
2019-07-05 17:16:20 +00:00
|
|
|
#include <rte_ether.h>
|
2012-09-04 12:54:00 +00:00
|
|
|
|
|
|
|
#include "cmdline_parse.h"
|
|
|
|
#include "cmdline_parse_etheraddr.h"
|
|
|
|
|
|
|
|
struct cmdline_token_ops cmdline_token_etheraddr_ops = {
|
|
|
|
.parse = cmdline_parse_etheraddr,
|
|
|
|
.complete_get_nb = NULL,
|
|
|
|
.complete_get_elt = NULL,
|
|
|
|
.get_help = cmdline_get_help_etheraddr,
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2020-02-09 15:54:54 +00:00
|
|
|
cmdline_parse_etheraddr(__rte_unused cmdline_parse_token_hdr_t *tk,
|
2014-12-05 14:19:07 +00:00
|
|
|
const char *buf, void *res, unsigned ressize)
|
2012-09-04 12:54:00 +00:00
|
|
|
{
|
|
|
|
unsigned int token_len = 0;
|
2019-07-05 17:16:20 +00:00
|
|
|
char ether_str[RTE_ETHER_ADDR_FMT_SIZE];
|
|
|
|
struct rte_ether_addr tmp;
|
2012-09-04 12:54:00 +00:00
|
|
|
|
2019-07-05 17:16:20 +00:00
|
|
|
if (res && ressize < sizeof(tmp))
|
2014-12-05 14:19:07 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-12-19 23:00:00 +00:00
|
|
|
if (!buf || ! *buf)
|
2012-09-04 12:54:00 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (!cmdline_isendoftoken(buf[token_len]))
|
|
|
|
token_len++;
|
|
|
|
|
2012-12-19 23:00:00 +00:00
|
|
|
/* if token doesn't match possible string lengths... */
|
2019-07-05 17:16:20 +00:00
|
|
|
if (token_len >= RTE_ETHER_ADDR_FMT_SIZE)
|
2012-09-04 12:54:00 +00:00
|
|
|
return -1;
|
|
|
|
|
2018-03-12 11:33:00 +00:00
|
|
|
strlcpy(ether_str, buf, token_len + 1);
|
2012-09-04 12:54:00 +00:00
|
|
|
|
2019-07-05 17:16:20 +00:00
|
|
|
if (rte_ether_unformat_addr(ether_str, &tmp) < 0)
|
2012-09-04 12:54:00 +00:00
|
|
|
return -1;
|
2019-07-05 17:16:20 +00:00
|
|
|
|
2012-12-19 23:00:00 +00:00
|
|
|
if (res)
|
2019-07-05 17:16:20 +00:00
|
|
|
memcpy(res, &tmp, sizeof(tmp));
|
2012-09-04 12:54:00 +00:00
|
|
|
return token_len;
|
|
|
|
}
|
|
|
|
|
2012-12-19 23:00:00 +00:00
|
|
|
int
|
2020-02-09 15:54:54 +00:00
|
|
|
cmdline_get_help_etheraddr(__rte_unused cmdline_parse_token_hdr_t *tk,
|
2012-09-04 12:54:00 +00:00
|
|
|
char *dstbuf, unsigned int size)
|
|
|
|
{
|
2012-12-19 23:00:00 +00:00
|
|
|
int ret;
|
|
|
|
|
2014-06-24 18:15:28 +00:00
|
|
|
ret = snprintf(dstbuf, size, "Ethernet address");
|
2012-12-19 23:00:00 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
2012-09-04 12:54:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|