Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2010-2014 Intel Corporation. 3 : : * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org> 4 : : * All rights reserved. 5 : : */ 6 : : 7 : : #include <stdio.h> 8 : : #include <string.h> 9 : : 10 : : #include <eal_export.h> 11 : : #include <rte_string_fns.h> 12 : : #include <rte_ether.h> 13 : : 14 : : #include "cmdline_parse.h" 15 : : #include "cmdline_parse_etheraddr.h" 16 : : 17 : : RTE_EXPORT_SYMBOL(cmdline_token_etheraddr_ops) 18 : : struct cmdline_token_ops cmdline_token_etheraddr_ops = { 19 : : .parse = cmdline_parse_etheraddr, 20 : : .complete_get_nb = NULL, 21 : : .complete_get_elt = NULL, 22 : : .get_help = cmdline_get_help_etheraddr, 23 : : }; 24 : : 25 : : RTE_EXPORT_SYMBOL(cmdline_parse_etheraddr) 26 : : int 27 : 34 : cmdline_parse_etheraddr(__rte_unused cmdline_parse_token_hdr_t *tk, 28 : : const char *buf, void *res, unsigned ressize) 29 : : { 30 : : unsigned int token_len = 0; 31 : : char ether_str[RTE_ETHER_ADDR_FMT_SIZE]; 32 : : struct rte_ether_addr tmp; 33 : : 34 [ + - ]: 34 : if (res && ressize < sizeof(tmp)) 35 : : return -1; 36 : : 37 [ + + + + ]: 34 : if (!buf || ! *buf) 38 : : return -1; 39 : : 40 [ + + ]: 458 : while (!cmdline_isendoftoken(buf[token_len])) 41 : 428 : token_len++; 42 : : 43 : : /* if token doesn't match possible string lengths... */ 44 [ + + ]: 30 : if (token_len >= RTE_ETHER_ADDR_FMT_SIZE) 45 : : return -1; 46 : : 47 : 28 : strlcpy(ether_str, buf, token_len + 1); 48 : : 49 [ + + ]: 28 : if (rte_ether_unformat_addr(ether_str, &tmp) < 0) 50 : : return -1; 51 : : 52 [ + + ]: 14 : if (res) 53 : : memcpy(res, &tmp, sizeof(tmp)); 54 : 14 : return token_len; 55 : : } 56 : : 57 : : RTE_EXPORT_SYMBOL(cmdline_get_help_etheraddr) 58 : : int 59 : 1 : cmdline_get_help_etheraddr(__rte_unused cmdline_parse_token_hdr_t *tk, 60 : : char *dstbuf, unsigned int size) 61 : : { 62 : : int ret; 63 : : 64 [ - + ]: 1 : ret = snprintf(dstbuf, size, "Ethernet address"); 65 [ - + ]: 1 : if (ret < 0) 66 : 0 : return -1; 67 : : return 0; 68 : : }