diff options
author | Steven Barth <steven@midlink.org> | 2011-10-07 20:01:11 +0200 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2011-10-07 20:01:11 +0200 |
commit | 8b6073c6500d4e655e7020c6a50b6e847037a00c (patch) | |
tree | cbaee1522e6e7ec9077520bbfb51631c74868546 /system-linux.c | |
parent | 2152229c45f470a14dee33507b331ac38055e062 (diff) |
system-linux: resolve interface index at device_up
Diffstat (limited to 'system-linux.c')
-rw-r--r-- | system-linux.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/system-linux.c b/system-linux.c index f6e1058..f1acc19 100644 --- a/system-linux.c +++ b/system-linux.c @@ -165,8 +165,19 @@ static int system_if_flags(struct device *dev, unsigned add, unsigned rem) return ioctl(sock_ioctl, SIOCSIFFLAGS, &ifr); } +static int system_if_resolve(struct device *dev) +{ + struct ifreq ifr; + strncpy(ifr.ifr_name, dev->ifname, sizeof(ifr.ifr_name)); + if (!ioctl(sock_ioctl, SIOCGIFINDEX, &ifr)) + return ifr.ifr_ifindex; + else + return 0; +} + int system_if_up(struct device *dev) { + dev->ifindex = system_if_resolve(dev); return system_if_flags(dev, IFF_UP, 0); } @@ -177,16 +188,7 @@ int system_if_down(struct device *dev) int system_if_check(struct device *dev) { - struct ifreq ifr; - strncpy(ifr.ifr_name, dev->ifname, sizeof(ifr.ifr_name)); - if (ioctl(sock_ioctl, SIOCGIFINDEX, &ifr)) - return -1; - - dev->ifindex = ifr.ifr_ifindex; - - /* if (!strcmp(dev->ifname, "eth0")) - device_set_present(dev, true); */ - return 0; + return -!(system_if_resolve(dev)); } static int system_addr(struct device *dev, struct device_addr *addr, int cmd) |