diff mbox

[ODP/PATCH,v5] API support for querying mac address

Message ID 1412590979-32584-1-git-send-email-bala.manoharan@linaro.org
State New
Headers show

Commit Message

Balasubramanian Manoharan Oct. 6, 2014, 10:22 a.m. UTC
This patch provides API support for querying mac address using odp_pktio_t handle.
This patch incorporates the changes after the removal of netmap from linux generic repo.

Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>
---
 example/ipsec/odp_ipsec.c                          |  9 ++++++--
 platform/linux-generic/include/api/odp_packet_io.h | 17 +++++++++++++++
 platform/linux-generic/odp_packet_io.c             | 24 ++++++++++++++++++++++
 platform/linux-generic/odp_packet_socket.c         | 14 +++++++++----
 4 files changed, 58 insertions(+), 6 deletions(-)

Comments

Anders Roxell Oct. 6, 2014, 1:14 p.m. UTC | #1
On 2014-10-06 15:52, Balasubramanian Manoharan wrote:
> This patch provides API support for querying mac address using odp_pktio_t handle.
> This patch incorporates the changes after the removal of netmap from linux generic repo.
> 
> Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>
> ---
>  example/ipsec/odp_ipsec.c                          |  9 ++++++--
>  platform/linux-generic/include/api/odp_packet_io.h | 17 +++++++++++++++
>  platform/linux-generic/odp_packet_io.c             | 24 ++++++++++++++++++++++
>  platform/linux-generic/odp_packet_socket.c         | 14 +++++++++----
>  4 files changed, 58 insertions(+), 6 deletions(-)
> 
> diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
> index ec6c87a..9a46a0c 100644
> --- a/example/ipsec/odp_ipsec.c
> +++ b/example/ipsec/odp_ipsec.c
> @@ -549,7 +549,8 @@ void initialize_intf(char *intf)
>  	char inq_name[ODP_QUEUE_NAME_LEN];
>  	odp_queue_param_t qparam;
>  	int ret;
> -	uint8_t src_mac[ODPH_ETHADDR_LEN];
> +	uint8_t src_mac[ODP_MAC_ADDR_MAX_LENGTH];
> +	size_t mac_addr_size;
>  	char src_mac_str[MAX_STRING];
>  
>  	/*
> @@ -587,8 +588,12 @@ void initialize_intf(char *intf)
>  	/* Read the source MAC address for this interface */
>  #if USE_MAC_ADDR_HACK
>  	ret = query_mac_address(intf, src_mac);
> +	(void)mac_addr_size;
>  #else
> -	ret = odp_pktio_get_mac_addr(pktio, src_mac);
> +	ret = odp_pktio_get_mac_addr(pktio, src_mac, &mac_addr_size);
> +	if (mac_addr_size != ODPH_ETHADDR_LEN) {
> +		ODP_ABORT("Ethernet mac address length not supported");
> +	}
>  #endif
>  	if (ret) {
>  		ODP_ERR("Error: failed during MAC address get for %s\n", intf);
> diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h
> index 29fd105..2086316 100644
> --- a/platform/linux-generic/include/api/odp_packet_io.h
> +++ b/platform/linux-generic/include/api/odp_packet_io.h
> @@ -125,6 +125,23 @@ void odp_pktio_set_input(odp_packet_t pkt, odp_pktio_t id);
>   */
>  odp_pktio_t odp_pktio_get_input(odp_packet_t pkt);
>  
> +/**
> + * Defines the maximum length of mac address supported by this platform
> + */
> +#define ODP_MAC_ADDR_MAX_LENGTH	ETH_ALEN
> +
> +/**
> + * Get mac address of the interface
> + *
> + * @param id		ODP packet IO handle
> + * @param mac_addr	Storage for Mac address of the packet IO interface
> + *			Storage provided by the caller should be equal
> + *			to ODP_MAC_ADDR_MAX_LENGTH (filled by function)
> + * @param addr_size	Size of the Mac address (filled by function)
> + * @return  0 on success or -1 on error
> +**/
> +int odp_pktio_get_mac_addr(odp_pktio_t id, unsigned char *mac_addr,
> +			   size_t *addr_size);
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
> index 0c30f0f..c982ec8 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -476,3 +476,27 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num)
>  
>  	return nbr;
>  }
> +int odp_pktio_get_mac_addr(odp_pktio_t id, unsigned char *mac_addr,
> +			   size_t *addr_size)
> +{
> +	pktio_entry_t *pktio_entry = get_entry(id);
> +	if (!pktio_entry) {
> +		ODP_ERR("Invalid odp_pktio_t value\n");
> +		return -1;
> +	}
> +	switch (pktio_entry->s.type) {
> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
> +		memcpy(mac_addr, pktio_entry->s.pkt_sock.if_mac, ETH_ALEN);
> +		break;
> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
> +		memcpy(mac_addr, pktio_entry->s.pkt_sock_mmap.if_mac, ETH_ALEN);
> +		break;
> +	default:
> +		ODP_ERR("Invalid pktio type: %02x\n",
> +			pktio_entry->s.type);
> +		return ODP_PKTIO_INVALID;
> +	}
> +	*addr_size = ETH_ALEN;
> +	return 0;

In odp_packet_socket.h you say that we should return 0 on success and -1
on error.

However, I'm confused with the 3 return statements above in this
function.

I thought ODP_PKTIO_INVALID was an error (-1), however, I looked at it
and it is defined to 0 and that looks wrong?

Can we have defines for success or error in here?


> +}
> diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c
> index 006d7bd..840987b 100644
> --- a/platform/linux-generic/odp_packet_socket.c
> +++ b/platform/linux-generic/odp_packet_socket.c
> @@ -89,6 +89,8 @@ typedef struct {
>  
>  static raw_socket_t raw_sockets[MAX_RAW_SOCKETS_NETDEVS];
>  static odp_spinlock_t raw_sockets_lock;
> +static int socket_store_hw_addr(int sockfd, unsigned char *if_mac,
> +			      const char *netdev);
>  
>  /** Eth buffer start offset from u32-aligned address to make sure the following
>   * header (e.g. IP) starts at a 32-bit aligned address.
> @@ -206,6 +208,10 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock, const char *netdev,
>  	sockfd = find_raw_fd(netdev);
>  	if (sockfd) {
>  		pkt_sock->sockfd = sockfd;
> +		if (socket_store_hw_addr(sockfd, pkt_sock->if_mac, netdev)) {
> +			perror("setup_pkt_sock() - socket_store_hw_addr()");

Use ODP_ERR instead of perror.


Cheers,
Anders

> +			goto error;
> +		}
>  		odp_spinlock_unlock(&raw_sockets_lock);
>  		return sockfd;
>  	}
> @@ -778,7 +784,7 @@ static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, const char *netdev)
>  	return 0;
>  }
>  
> -static int mmap_store_hw_addr(pkt_sock_mmap_t *const pkt_sock,
> +static int socket_store_hw_addr(int sockfd, unsigned char *if_mac,
>  			      const char *netdev)
>  {
>  	struct ifreq ethreq;
> @@ -787,13 +793,13 @@ static int mmap_store_hw_addr(pkt_sock_mmap_t *const pkt_sock,
>  	/* get MAC address */
>  	memset(&ethreq, 0, sizeof(ethreq));
>  	strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
> -	ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, &ethreq);
> +	ret = ioctl(sockfd, SIOCGIFHWADDR, &ethreq);
>  	if (ret != 0) {
>  		perror("store_hw_addr() - ioctl(SIOCGIFHWADDR)");
>  		return -1;
>  	}
>  
> -	ethaddr_copy(pkt_sock->if_mac,
> +	ethaddr_copy(if_mac,
>  		     (unsigned char *)ethreq.ifr_ifru.ifru_hwaddr.sa_data);
>  
>  	return 0;
> @@ -848,7 +854,7 @@ int setup_pkt_sock_mmap(pkt_sock_mmap_t *const pkt_sock, const char *netdev,
>  	if (ret != 0)
>  		return -1;
>  
> -	ret = mmap_store_hw_addr(pkt_sock, netdev);
> +	ret = socket_store_hw_addr(pkt_sock->sockfd, pkt_sock->if_mac, netdev);
>  	if (ret != 0)
>  		return -1;
>  
> -- 
> 2.0.1.472.g6f92e5f
> 
> 
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
Balasubramanian Manoharan Oct. 6, 2014, 3:40 p.m. UTC | #2
Hi,

Pls see my comments inline.
Regards,
Bala
On 6 October 2014 18:44, Anders Roxell <anders.roxell@linaro.org> wrote:

> On 2014-10-06 15:52, Balasubramanian Manoharan wrote:
> > This patch provides API support for querying mac address using
> odp_pktio_t handle.
> > This patch incorporates the changes after the removal of netmap from
> linux generic repo.
> >
> > Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>
> > ---
> >  example/ipsec/odp_ipsec.c                          |  9 ++++++--
> >  platform/linux-generic/include/api/odp_packet_io.h | 17 +++++++++++++++
> >  platform/linux-generic/odp_packet_io.c             | 24
> ++++++++++++++++++++++
> >  platform/linux-generic/odp_packet_socket.c         | 14 +++++++++----
> >  4 files changed, 58 insertions(+), 6 deletions(-)
> >
> > diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
> > index ec6c87a..9a46a0c 100644
> > --- a/example/ipsec/odp_ipsec.c
> > +++ b/example/ipsec/odp_ipsec.c
> > @@ -549,7 +549,8 @@ void initialize_intf(char *intf)
> >       char inq_name[ODP_QUEUE_NAME_LEN];
> >       odp_queue_param_t qparam;
> >       int ret;
> > -     uint8_t src_mac[ODPH_ETHADDR_LEN];
> > +     uint8_t src_mac[ODP_MAC_ADDR_MAX_LENGTH];
> > +     size_t mac_addr_size;
> >       char src_mac_str[MAX_STRING];
> >
> >       /*
> > @@ -587,8 +588,12 @@ void initialize_intf(char *intf)
> >       /* Read the source MAC address for this interface */
> >  #if USE_MAC_ADDR_HACK
> >       ret = query_mac_address(intf, src_mac);
> > +     (void)mac_addr_size;
> >  #else
> > -     ret = odp_pktio_get_mac_addr(pktio, src_mac);
> > +     ret = odp_pktio_get_mac_addr(pktio, src_mac, &mac_addr_size);
> > +     if (mac_addr_size != ODPH_ETHADDR_LEN) {
> > +             ODP_ABORT("Ethernet mac address length not supported");
> > +     }
> >  #endif
> >       if (ret) {
> >               ODP_ERR("Error: failed during MAC address get for %s\n",
> intf);
> > diff --git a/platform/linux-generic/include/api/odp_packet_io.h
> b/platform/linux-generic/include/api/odp_packet_io.h
> > index 29fd105..2086316 100644
> > --- a/platform/linux-generic/include/api/odp_packet_io.h
> > +++ b/platform/linux-generic/include/api/odp_packet_io.h
> > @@ -125,6 +125,23 @@ void odp_pktio_set_input(odp_packet_t pkt,
> odp_pktio_t id);
> >   */
> >  odp_pktio_t odp_pktio_get_input(odp_packet_t pkt);
> >
> > +/**
> > + * Defines the maximum length of mac address supported by this platform
> > + */
> > +#define ODP_MAC_ADDR_MAX_LENGTH      ETH_ALEN
> > +
> > +/**
> > + * Get mac address of the interface
> > + *
> > + * @param id         ODP packet IO handle
> > + * @param mac_addr   Storage for Mac address of the packet IO interface
> > + *                   Storage provided by the caller should be equal
> > + *                   to ODP_MAC_ADDR_MAX_LENGTH (filled by function)
> > + * @param addr_size  Size of the Mac address (filled by function)
> > + * @return  0 on success or -1 on error
> > +**/
> > +int odp_pktio_get_mac_addr(odp_pktio_t id, unsigned char *mac_addr,
> > +                        size_t *addr_size);
> >  #ifdef __cplusplus
> >  }
> >  #endif
> > diff --git a/platform/linux-generic/odp_packet_io.c
> b/platform/linux-generic/odp_packet_io.c
> > index 0c30f0f..c982ec8 100644
> > --- a/platform/linux-generic/odp_packet_io.c
> > +++ b/platform/linux-generic/odp_packet_io.c
> > @@ -476,3 +476,27 @@ int pktin_deq_multi(queue_entry_t *qentry,
> odp_buffer_hdr_t *buf_hdr[], int num)
> >
> >       return nbr;
> >  }
> > +int odp_pktio_get_mac_addr(odp_pktio_t id, unsigned char *mac_addr,
> > +                        size_t *addr_size)
> > +{
> > +     pktio_entry_t *pktio_entry = get_entry(id);
> > +     if (!pktio_entry) {
> > +             ODP_ERR("Invalid odp_pktio_t value\n");
> > +             return -1;
> > +     }
> > +     switch (pktio_entry->s.type) {
> > +     case ODP_PKTIO_TYPE_SOCKET_BASIC:
> > +     case ODP_PKTIO_TYPE_SOCKET_MMSG:
> > +             memcpy(mac_addr, pktio_entry->s.pkt_sock.if_mac, ETH_ALEN);
> > +             break;
> > +     case ODP_PKTIO_TYPE_SOCKET_MMAP:
> > +             memcpy(mac_addr, pktio_entry->s.pkt_sock_mmap.if_mac,
> ETH_ALEN);
> > +             break;
> > +     default:
> > +             ODP_ERR("Invalid pktio type: %02x\n",
> > +                     pktio_entry->s.type);
> > +             return ODP_PKTIO_INVALID;
> > +     }
> > +     *addr_size = ETH_ALEN;
> > +     return 0;
>
> In odp_packet_socket.h you say that we should return 0 on success and -1
> on error.
>
> However, I'm confused with the 3 return statements above in this
> function.
>
> I thought ODP_PKTIO_INVALID was an error (-1), however, I looked at it
> and it is defined to 0 and that looks wrong?
>
> Can we have defines for success or error in here?
>
> Return value of 0 and -1 is the syntax followed by all the existing APIs
in linux-generic.
So I have followed the same syntax here.
But you are correct I will have to remove ODP_PKTIO_INVALID and change it
as -1.

> > +}
> > diff --git a/platform/linux-generic/odp_packet_socket.c
> b/platform/linux-generic/odp_packet_socket.c
> > index 006d7bd..840987b 100644
> > --- a/platform/linux-generic/odp_packet_socket.c
> > +++ b/platform/linux-generic/odp_packet_socket.c
> > @@ -89,6 +89,8 @@ typedef struct {
> >
> >  static raw_socket_t raw_sockets[MAX_RAW_SOCKETS_NETDEVS];
> >  static odp_spinlock_t raw_sockets_lock;
> > +static int socket_store_hw_addr(int sockfd, unsigned char *if_mac,
> > +                           const char *netdev);
> >
> >  /** Eth buffer start offset from u32-aligned address to make sure the
> following
> >   * header (e.g. IP) starts at a 32-bit aligned address.
> > @@ -206,6 +208,10 @@ int setup_pkt_sock(pkt_sock_t *const pkt_sock,
> const char *netdev,
> >       sockfd = find_raw_fd(netdev);
> >       if (sockfd) {
> >               pkt_sock->sockfd = sockfd;
> > +             if (socket_store_hw_addr(sockfd, pkt_sock->if_mac,
> netdev)) {
> > +                     perror("setup_pkt_sock() -
> socket_store_hw_addr()");
>
> Use ODP_ERR instead of perror.
>
> Sure will change this.


> Cheers,
> Anders
>
> > +                     goto error;
> > +             }
> >               odp_spinlock_unlock(&raw_sockets_lock);
> >               return sockfd;
> >       }
> > @@ -778,7 +784,7 @@ static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock,
> const char *netdev)
> >       return 0;
> >  }
> >
> > -static int mmap_store_hw_addr(pkt_sock_mmap_t *const pkt_sock,
> > +static int socket_store_hw_addr(int sockfd, unsigned char *if_mac,
> >                             const char *netdev)
> >  {
> >       struct ifreq ethreq;
> > @@ -787,13 +793,13 @@ static int mmap_store_hw_addr(pkt_sock_mmap_t
> *const pkt_sock,
> >       /* get MAC address */
> >       memset(&ethreq, 0, sizeof(ethreq));
> >       strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
> > -     ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, &ethreq);
> > +     ret = ioctl(sockfd, SIOCGIFHWADDR, &ethreq);
> >       if (ret != 0) {
> >               perror("store_hw_addr() - ioctl(SIOCGIFHWADDR)");
> >               return -1;
> >       }
> >
> > -     ethaddr_copy(pkt_sock->if_mac,
> > +     ethaddr_copy(if_mac,
> >                    (unsigned char *)ethreq.ifr_ifru.ifru_hwaddr.sa_data);
> >
> >       return 0;
> > @@ -848,7 +854,7 @@ int setup_pkt_sock_mmap(pkt_sock_mmap_t *const
> pkt_sock, const char *netdev,
> >       if (ret != 0)
> >               return -1;
> >
> > -     ret = mmap_store_hw_addr(pkt_sock, netdev);
> > +     ret = socket_store_hw_addr(pkt_sock->sockfd, pkt_sock->if_mac,
> netdev);
> >       if (ret != 0)
> >               return -1;
> >
> > --
> > 2.0.1.472.g6f92e5f
> >
> >
> > _______________________________________________
> > lng-odp mailing list
> > lng-odp@lists.linaro.org
> > http://lists.linaro.org/mailman/listinfo/lng-odp
>
diff mbox

Patch

diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index ec6c87a..9a46a0c 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -549,7 +549,8 @@  void initialize_intf(char *intf)
 	char inq_name[ODP_QUEUE_NAME_LEN];
 	odp_queue_param_t qparam;
 	int ret;
-	uint8_t src_mac[ODPH_ETHADDR_LEN];
+	uint8_t src_mac[ODP_MAC_ADDR_MAX_LENGTH];
+	size_t mac_addr_size;
 	char src_mac_str[MAX_STRING];
 
 	/*
@@ -587,8 +588,12 @@  void initialize_intf(char *intf)
 	/* Read the source MAC address for this interface */
 #if USE_MAC_ADDR_HACK
 	ret = query_mac_address(intf, src_mac);
+	(void)mac_addr_size;
 #else
-	ret = odp_pktio_get_mac_addr(pktio, src_mac);
+	ret = odp_pktio_get_mac_addr(pktio, src_mac, &mac_addr_size);
+	if (mac_addr_size != ODPH_ETHADDR_LEN) {
+		ODP_ABORT("Ethernet mac address length not supported");
+	}
 #endif
 	if (ret) {
 		ODP_ERR("Error: failed during MAC address get for %s\n", intf);
diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h
index 29fd105..2086316 100644
--- a/platform/linux-generic/include/api/odp_packet_io.h
+++ b/platform/linux-generic/include/api/odp_packet_io.h
@@ -125,6 +125,23 @@  void odp_pktio_set_input(odp_packet_t pkt, odp_pktio_t id);
  */
 odp_pktio_t odp_pktio_get_input(odp_packet_t pkt);
 
+/**
+ * Defines the maximum length of mac address supported by this platform
+ */
+#define ODP_MAC_ADDR_MAX_LENGTH	ETH_ALEN
+
+/**
+ * Get mac address of the interface
+ *
+ * @param id		ODP packet IO handle
+ * @param mac_addr	Storage for Mac address of the packet IO interface
+ *			Storage provided by the caller should be equal
+ *			to ODP_MAC_ADDR_MAX_LENGTH (filled by function)
+ * @param addr_size	Size of the Mac address (filled by function)
+ * @return  0 on success or -1 on error
+**/
+int odp_pktio_get_mac_addr(odp_pktio_t id, unsigned char *mac_addr,
+			   size_t *addr_size);
 #ifdef __cplusplus
 }
 #endif
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index 0c30f0f..c982ec8 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -476,3 +476,27 @@  int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num)
 
 	return nbr;
 }
+int odp_pktio_get_mac_addr(odp_pktio_t id, unsigned char *mac_addr,
+			   size_t *addr_size)
+{
+	pktio_entry_t *pktio_entry = get_entry(id);
+	if (!pktio_entry) {
+		ODP_ERR("Invalid odp_pktio_t value\n");
+		return -1;
+	}
+	switch (pktio_entry->s.type) {
+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
+		memcpy(mac_addr, pktio_entry->s.pkt_sock.if_mac, ETH_ALEN);
+		break;
+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
+		memcpy(mac_addr, pktio_entry->s.pkt_sock_mmap.if_mac, ETH_ALEN);
+		break;
+	default:
+		ODP_ERR("Invalid pktio type: %02x\n",
+			pktio_entry->s.type);
+		return ODP_PKTIO_INVALID;
+	}
+	*addr_size = ETH_ALEN;
+	return 0;
+}
diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c
index 006d7bd..840987b 100644
--- a/platform/linux-generic/odp_packet_socket.c
+++ b/platform/linux-generic/odp_packet_socket.c
@@ -89,6 +89,8 @@  typedef struct {
 
 static raw_socket_t raw_sockets[MAX_RAW_SOCKETS_NETDEVS];
 static odp_spinlock_t raw_sockets_lock;
+static int socket_store_hw_addr(int sockfd, unsigned char *if_mac,
+			      const char *netdev);
 
 /** Eth buffer start offset from u32-aligned address to make sure the following
  * header (e.g. IP) starts at a 32-bit aligned address.
@@ -206,6 +208,10 @@  int setup_pkt_sock(pkt_sock_t *const pkt_sock, const char *netdev,
 	sockfd = find_raw_fd(netdev);
 	if (sockfd) {
 		pkt_sock->sockfd = sockfd;
+		if (socket_store_hw_addr(sockfd, pkt_sock->if_mac, netdev)) {
+			perror("setup_pkt_sock() - socket_store_hw_addr()");
+			goto error;
+		}
 		odp_spinlock_unlock(&raw_sockets_lock);
 		return sockfd;
 	}
@@ -778,7 +784,7 @@  static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, const char *netdev)
 	return 0;
 }
 
-static int mmap_store_hw_addr(pkt_sock_mmap_t *const pkt_sock,
+static int socket_store_hw_addr(int sockfd, unsigned char *if_mac,
 			      const char *netdev)
 {
 	struct ifreq ethreq;
@@ -787,13 +793,13 @@  static int mmap_store_hw_addr(pkt_sock_mmap_t *const pkt_sock,
 	/* get MAC address */
 	memset(&ethreq, 0, sizeof(ethreq));
 	strncpy(ethreq.ifr_name, netdev, IFNAMSIZ-1);
-	ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, &ethreq);
+	ret = ioctl(sockfd, SIOCGIFHWADDR, &ethreq);
 	if (ret != 0) {
 		perror("store_hw_addr() - ioctl(SIOCGIFHWADDR)");
 		return -1;
 	}
 
-	ethaddr_copy(pkt_sock->if_mac,
+	ethaddr_copy(if_mac,
 		     (unsigned char *)ethreq.ifr_ifru.ifru_hwaddr.sa_data);
 
 	return 0;
@@ -848,7 +854,7 @@  int setup_pkt_sock_mmap(pkt_sock_mmap_t *const pkt_sock, const char *netdev,
 	if (ret != 0)
 		return -1;
 
-	ret = mmap_store_hw_addr(pkt_sock, netdev);
+	ret = socket_store_hw_addr(pkt_sock->sockfd, pkt_sock->if_mac, netdev);
 	if (ret != 0)
 		return -1;