Thread (33 messages) flat view 33 messages, 7 authors, 2021-01-22

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

From: Daniel Borkmann <daniel@iogearbox.net>
Date: 2020-12-11 00:16:39
Also in: bpf

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;
+}
+
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help