diff options
Diffstat (limited to 'dev.c')
-rw-r--r-- | dev.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -13,7 +13,7 @@ #include "link.h" #include "built_in.h" -int device_ifindex(const char *ifname) +int device_ifindex_get(const char *ifname) { int ret, sock, index; struct ifreq ifr; @@ -27,8 +27,8 @@ int device_ifindex(const char *ifname) strlcpy(ifr.ifr_name, ifname, IFNAMSIZ); ret = ioctl(sock, SIOCGIFINDEX, &ifr); - if (unlikely(ret)) - panic("Cannot get ifindex from device!\n"); + if (ret) + return -1; index = ifr.ifr_ifindex; close(sock); @@ -36,6 +36,15 @@ int device_ifindex(const char *ifname) return index; } +int device_ifindex(const char *ifname) +{ + int index = device_ifindex_get(ifname); + if (unlikely(index <= 0)) + panic("Cannot get ifindex from device!\n"); + + return index; +} + int device_type(const char *ifname) { int ret, sock, type; |