Parcourir la source

sockpbf: ioctl might fail

David Marec il y a 8 mois
Parent
commit
ddb9a723f9
1 fichiers modifiés avec 6 ajouts et 1 suppressions
  1. 6 1
      sockraw/sockbpf.c

+ 6 - 1
sockraw/sockbpf.c

@@ -116,6 +116,7 @@ static void sender(const struct ifreq *ifr, size_t nb)
 static int get_hwaddr(const char * restrict iface, struct ifreq * restrict dest_ifr)
 {
 	int shw;
+	int rc;
 
 	strncpy(dest_ifr->ifr_name, iface, sizeof dest_ifr->ifr_name);
 	dest_ifr->ifr_addr.sa_family = AF_LINK;
@@ -124,8 +125,12 @@ static int get_hwaddr(const char * restrict iface, struct ifreq * restrict dest_
 		return -1;
 	}
 
-	ioctl(shw, SIOCGHWADDR, dest_ifr);
+	rc = ioctl(shw, SIOCGHWADDR, dest_ifr);
 	close(shw);
+
+	if (rc)
+		return -1;
+
 	VPRINTF("Destination %s,  HW address: %s.\n",  iface, ether_ntoa((const struct ether_addr *)dest_ifr->ifr_addr.sa_data));
 
 	return 0;