Hi

On Thu, Sep 29, 2022 at 11:54 AM Alexander Ivanov <
alexander.iva...@virtuozzo.com> wrote:

> Replace a dumb function in commands-bsd.c by the code of HW address
> getting.
>
> Signed-off-by: Alexander Ivanov <alexander.iva...@virtuozzo.com>
>

lgtm
Reviewed-by: Marc-André Lureau <marcandre.lur...@redhat.com>



> ---
>  qga/commands-bsd.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c
> index ca81114171..f9997ee1ec 100644
> --- a/qga/commands-bsd.c
> +++ b/qga/commands-bsd.c
> @@ -20,6 +20,8 @@
>  #include <sys/param.h>
>  #include <sys/ucred.h>
>  #include <sys/mount.h>
> +#include <net/if_dl.h>
> +#include <net/ethernet.h>
>  #include <paths.h>
>
>  #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)
> @@ -178,10 +180,15 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error
> **errp)
>   */
>  int guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, Error
> **errp)
>  {
> -    /*
> -     * We can't get the hw addr of this interface,
> -     * but that's not a fatal error.
> -     */
> -    return 0;
> +    struct sockaddr_dl *sdp;
> +
> +    if (ifa->ifa_addr->sa_family != AF_LINK) {
> +        /* We can get HW address only for AF_LINK family */
> +        g_debug("failed to get MAC address of %s", ifa->ifa_name);
> +        return 0;
> +    }
> +    sdp = (struct sockaddr_dl *)ifa->ifa_addr;
> +    memcpy(buf, sdp->sdl_data + sdp->sdl_nlen, ETHER_ADDR_LEN);
> +    return 1;
>  }
>  #endif /* HAVE_GETIFADDRS */
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

Reply via email to