+static int
+eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
+ const unsigned int numa_node)
+{
+#if defined(RTE_EXEC_ENV_LINUXAPP)
+ void *mac_addrs;
+ 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;
+ }
+
+ mac_addrs = rte_zmalloc_socket(NULL, ETHER_ADDR_LEN, 0, numa_node);
+ if (!mac_addrs) {
+ close(if_fd);
+ return -1;
+ }
+
+ PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
+ eth_dev->data->mac_addrs = mac_addrs;
+ rte_memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
+ ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
+
+ close(if_fd);
+
+ return 0;
+
+#elif defined(RTE_EXEC_ENV_BSDAPP)
+ void *mac_addrs;
+ struct if_msghdr *ifm;
+ struct sockaddr_dl *sdl;
+ int mib[6];
+ size_t len = 0;
+ char *buf;
+
+ mib[0] = CTL_NET;
+ mib[1] = AF_ROUTE;
+ mib[2] = 0;
+ mib[3] = AF_LINK;
+ mib[4] = NET_RT_IFLIST;
+ mib[5] = if_nametoindex(if_name);
+
+ if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
+ return -1;
+
+ if (len == 0)
+ return -1;
+
+ buf = rte_malloc(NULL, len, 0);
+ if (!buf)
+ return -1;
+
+ if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
+ rte_free(buf);
+ return -1;
+ }
+ ifm = (struct if_msghdr *)buf;
+ sdl = (struct sockaddr_dl *)(ifm + 1);
+
+ mac_addrs = rte_zmalloc_socket(NULL, ETHER_ADDR_LEN, 0, numa_node);
+ if (!mac_addrs) {
+ rte_free(buf);
+ return -1;
+ }
+
+ PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
+ eth_dev->data->mac_addrs = mac_addrs;
+ rte_memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
+ LLADDR(sdl), ETHER_ADDR_LEN);
+
+ rte_free(buf);
+
+ return 0;
+#else
+ return -1;
+#endif
+}
+