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 <rte_string_fns.h> 11 : : #include <rte_ether.h> 12 : : 13 : : #include "cmdline_parse.h" 14 : : #include "cmdline_parse_etheraddr.h" 15 : : 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, 21 : : }; 22 : : 23 : : int 24 : 34 : cmdline_parse_etheraddr(__rte_unused cmdline_parse_token_hdr_t *tk, 25 : : const char *buf, void *res, unsigned ressize) 26 : : { 27 : : unsigned int token_len = 0; 28 : : char ether_str[RTE_ETHER_ADDR_FMT_SIZE]; 29 : : struct rte_ether_addr tmp; 30 : : 31 [ + - ]: 34 : if (res && ressize < sizeof(tmp)) 32 : : return -1; 33 : : 34 [ + + + + ]: 34 : if (!buf || ! *buf) 35 : : return -1; 36 : : 37 [ + + ]: 458 : while (!cmdline_isendoftoken(buf[token_len])) 38 : 428 : token_len++; 39 : : 40 : : /* if token doesn't match possible string lengths... */ 41 [ + + ]: 30 : if (token_len >= RTE_ETHER_ADDR_FMT_SIZE) 42 : : return -1; 43 : : 44 : 28 : strlcpy(ether_str, buf, token_len + 1); 45 : : 46 [ + + ]: 28 : if (rte_ether_unformat_addr(ether_str, &tmp) < 0) 47 : : return -1; 48 : : 49 [ + + ]: 14 : if (res) 50 : : memcpy(res, &tmp, sizeof(tmp)); 51 : 14 : return token_len; 52 : : } 53 : : 54 : : int 55 : 1 : cmdline_get_help_etheraddr(__rte_unused cmdline_parse_token_hdr_t *tk, 56 : : char *dstbuf, unsigned int size) 57 : : { 58 : : int ret; 59 : : 60 [ - + ]: 1 : ret = snprintf(dstbuf, size, "Ethernet address"); 61 [ - + ]: 1 : if (ret < 0) 62 : 0 : return -1; 63 : : return 0; 64 : : }