Re: [PATCHv4 bpf-next] samples/bpf: add xdp program on egress for xdp_redirect_map

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/8/20 1:01 PM, Hangbin Liu wrote:
[...]
+static int get_mac_addr(unsigned int ifindex_out, void *mac_addr)
+{
+	struct ifreq ifr;
+	char ifname[IF_NAMESIZE];
+	int fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+	if (fd < 0)
+		return -1;
+
+	if (!if_indextoname(ifindex_out, ifname))
+		return -1;
+
+	strcpy(ifr.ifr_name, ifname);
+
+	if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0)
+		return -1;
+
+	memcpy(mac_addr, ifr.ifr_hwaddr.sa_data, 6 * sizeof(char));
+	close(fd);

Given we do bother to close the socket fd here, we should also close it in above
error cases..

+	return 0;
+}
+



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux