Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2010-2016 Intel Corporation. 3 : : * Copyright(c) 2014 6WIND S.A. 4 : : * All rights reserved. 5 : : */ 6 : : 7 : : #include <net/if.h> 8 : : #include <sys/ioctl.h> 9 : : #include <sys/socket.h> 10 : : #include <unistd.h> 11 : : 12 : : #include <rte_memcpy.h> 13 : : #include <rte_string_fns.h> 14 : : 15 : : #include "pcap_osdep.h" 16 : : 17 : : int 18 : 0 : osdep_iface_index_get(const char *name) 19 : : { 20 : 0 : return if_nametoindex(name); 21 : : } 22 : : 23 : : int 24 : 0 : osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac) 25 : : { 26 : : struct ifreq ifr; 27 : 0 : int if_fd = socket(AF_INET, SOCK_DGRAM, 0); 28 : : 29 [ # # ]: 0 : if (if_fd == -1) 30 : : return -1; 31 : : 32 : 0 : rte_strscpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name)); 33 [ # # ]: 0 : if (ioctl(if_fd, SIOCGIFHWADDR, &ifr)) { 34 : 0 : close(if_fd); 35 : 0 : return -1; 36 : : } 37 : : 38 : : rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN); 39 : : 40 : 0 : close(if_fd); 41 : 0 : return 0; 42 : : }