1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00
openmptcprouter-feeds/netifd/patches/085-get-ifindex-in-file-if-ioctl-fail.patch
2022-04-06 20:55:49 +08:00

46 lines
1,000 B
Diff

diff -Nur a/system-linux.c netifd-2015-12-16/system-linux.c
--- a/system-linux.c 2018-11-08 15:30:16.422606326 -0800
+++ netifd-2015-12-16/system-linux.c 2018-11-08 15:30:24.522606530 -0800
@@ -593,6 +593,33 @@
return path + 1;
}
+static int system_get_ifindex(const char *name)
+{
+ char path[64], buf[24];
+ int len;
+ FILE *f;
+ struct stat st;
+
+ snprintf(path, sizeof(path), "/sys/class/net/%s/ifindex", name);
+
+ if (stat(path, &st) < 0)
+ return 0;
+
+ f = fopen(path, "r");
+ if (!f) {
+ return 0;
+ }
+
+ len = fread(buf, 1, 23, f);
+ fclose(f);
+
+ if (len <= 0)
+ return 0;
+
+ buf[len] = 0;
+ return strtoul(buf, NULL, 0);
+}
+
static struct device *system_get_bonding(const char *name, char *buf, int buflen)
{
char path[64], *devname;
@@ -706,7 +733,7 @@
if (!ioctl(sock_ioctl, SIOCGIFINDEX, &ifr))
return ifr.ifr_ifindex;
else
- return 0;
+ return system_get_ifindex(dev->ifname);
}
static int system_if_flags(const char *ifname, unsigned add, unsigned rem)