From 8041af59881219c32267c3491bee43591d3c3fe6 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 3 Jun 2014 17:53:11 -0400 Subject: [PATCH] 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. --- src/network/if_nametoindex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/if_nametoindex.c b/src/network/if_nametoindex.c index fb4a1474..cb6ec054 100644 --- a/src/network/if_nametoindex.c +++ b/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; } -- 2.25.1