提交 3cdbfb99 编写于 作者: R Ron Yorston 提交者: Rich Felker

fix if_nametoindex return value when socket open fails

The return value of if_nametoindex is unsigned; it should return 0
on error.
上级 2f853dd6
......@@ -10,7 +10,7 @@ unsigned if_nametoindex(const char *name)
struct ifreq ifr;
int fd, r;
if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return -1;
if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
r = ioctl(fd, SIOCGIFINDEX, &ifr);
__syscall(SYS_close, fd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册