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.
This commit is contained in:
Rich Felker 2014-06-03 17:53:11 -04:00
parent d85d261ee6
commit 8041af5988
1 changed files with 1 additions and 1 deletions

View File

@ -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;
}