Преглед изворни кода

fix if_nametoindex return value when interface does not exist

the return value is unsigned, so negative results for "errors" do not
make sense; 0 is the value reserved for when the interface name does
not exist.

(cherry picked from commit 8041af59881219c32267c3491bee43591d3c3fe6)
Rich Felker пре 11 година
родитељ
комит
f8b5cc8a7e
1 измењених фајлова са 1 додато и 1 уклоњено
  1. 1 1
      src/network/if_nametoindex.c

+ 1 - 1
src/network/if_nametoindex.c

@@ -14,5 +14,5 @@ unsigned if_nametoindex(const char *name)
 	strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
 	r = ioctl(fd, SIOCGIFINDEX, &ifr);
 	__syscall(SYS_close, fd);
-	return r < 0 ? r : ifr.ifr_ifindex;
+	return r < 0 ? 0 : ifr.ifr_ifindex;
 }