numam-dpdk/drivers/net/pcap/pcap_osdep_linux.c
Dmitry Kozlyuk 436c089a52 net/pcap: move OS-dependent code to separate files
PCAP PMD queries interface information differently for Linux and
FreeBSD, OS-specific code is guarded by #ifdef. This PMD also depends on
POSIX bits, namely gettimeofday() and NAME_MAX.

Move OS-dependent code to separate files.
Replace POSIX bits with DPDK equivalents.
Rename rte_eth_pcap.c to pcap_ethdev.c, like it is in most other PMDs.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
2021-04-21 23:48:31 +02:00

43 lines
801 B
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2010-2016 Intel Corporation.
* Copyright(c) 2014 6WIND S.A.
* All rights reserved.
*/
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>
#include <rte_memcpy.h>
#include <rte_string_fns.h>
#include "pcap_osdep.h"
int
osdep_iface_index_get(const char *name)
{
return if_nametoindex(name);
}
int
osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
{
struct ifreq ifr;
int if_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (if_fd == -1)
return -1;
rte_strscpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name));
if (ioctl(if_fd, SIOCGIFHWADDR, &ifr)) {
close(if_fd);
return -1;
}
rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
close(if_fd);
return 0;
}