> Subject: Re: [dpdk-dev] [PATCH v2 2/2] net/netvsc: support VF device hot > add/remove > > On Mon, 21 Dec 2020 13:33:22 -0800 > Long Li <lon...@linuxonhyperv.com> wrote: > > > /* trying to get mac address if this is a network device*/ > > + s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); > > + if (s == -1) { > > + PMD_DRV_LOG(ERR, "Failed to create socket > errno %d\n", > > + errno); > > + break; > > + } > > + strlcpy(req.ifr_name, dir->d_name, sizeof(req.ifr_name)); > > + ret = ioctl(s, SIOCGIFHWADDR, &req); > > + close(s); > > + if (ret == -1) { > > + PMD_DRV_LOG(ERR, "Failed to send > SIOCGIFHWADDR for " > > + "device %s\n", dir->d_name); > > + break; > > + } > > + if (req.ifr_hwaddr.sa_family != ARPHRD_ETHER) { > > + closedir(di); > > + return; > > + } > > You have sysfs directory open at this point, would it be easier to continue > with sysfs to find the mac address? > > snprintf(ifpath, sizeof(ifpath), "%s/address", dir->d_name); > fd = openat(dirfd(di), ifpath, O_RDONLY); > read(fd...)
I think sending SIOCGIFHWADDR through socket is safer. This is the same as vdev_netvsc does. If the network hardware is not ethernet, reading the address directly from sysfs may require some additional parsing.