[PATCH v17 06/23] net/pcap: avoid using rte_malloc and rte_memcpy

Stephen Hemminger
2026-02-20T05:49:23Z

No need to use rte_malloc or rte_memcpy in the short
code to get MAC address.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/pcap/pcap_ethdev.c | 3 ++-
drivers/net/pcap/pcap_osdep_freebsd.c | 12 +++++-------
drivers/net/pcap/pcap_osdep_linux.c | 6 +++---
3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index fbd1021c39..806451dc99 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -6,6 +6,7 @@

#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include <inttypes.h>
#include <errno.h>
@@ -1288,7 +1289,7 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
return -1;

PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
- rte_memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
+ memcpy(mac_addrs, mac.addr_bytes, RTE_ETHER_ADDR_LEN);
eth_dev->data->mac_addrs = mac_addrs;
return 0;
}
diff --git a/drivers/net/pcap/pcap_osdep_freebsd.c b/drivers/net/pcap/pcap_osdep_freebsd.c
index 20556b3e92..0185665f0b 100644
--- a/drivers/net/pcap/pcap_osdep_freebsd.c
+++ b/drivers/net/pcap/pcap_osdep_freebsd.c
@@ -4,13 +4,11 @@
* All rights reserved.
*/

+#include <string.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <sys/sysctl.h>

-#include <rte_malloc.h>
-#include <rte_memcpy.h>
-
#include "pcap_osdep.h"

int
@@ -41,19 +39,19 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
if (len == 0)
return -1;

- buf = rte_malloc(NULL, len, 0);
+ buf = malloc(len);
if (!buf)
return -1;

if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
- rte_free(buf);
+ free(buf);
return -1;
}
ifm = (struct if_msghdr *)buf;
sdl = (struct sockaddr_dl *)(ifm + 1);

- rte_memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);
+ memcpy(mac->addr_bytes, LLADDR(sdl), RTE_ETHER_ADDR_LEN);

- rte_free(buf);
+ free(buf);
return 0;
}
diff --git a/drivers/net/pcap/pcap_osdep_linux.c b/drivers/net/pcap/pcap_osdep_linux.c
index 97033f57c5..df976417cb 100644
--- a/drivers/net/pcap/pcap_osdep_linux.c
+++ b/drivers/net/pcap/pcap_osdep_linux.c
@@ -4,12 +4,12 @@
* All rights reserved.
*/

+#include <string.h>
+#include <unistd.h>
#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"
@@ -35,7 +35,7 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
return -1;
}

- rte_memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
+ memcpy(mac->addr_bytes, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);

close(if_fd);
return 0;
--
2.51.0