diff options
author | Felix Fietkau <nbd@nbd.name> | 2021-06-28 15:30:28 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2021-06-28 15:39:22 +0200 |
commit | c9b1672f5a83c8dcb14fdbaee651f775a7defe52 (patch) | |
tree | dd9c837cdc3ea1d6e8125824e48743f8cc11a1f2 | |
parent | c0414642fead263a4a6a686ad3cb7e965ec8a23a (diff) | |
download | iwinfo-c9b1672f5a83c8dcb14fdbaee651f775a7defe52.tar.gz |
nl80211: fix path compatibility issue
The previous shell script implementation accepted shorter path values
that omitted initial parts before the pcie bus node by only checking if
the configured path is included in the determined path
Add support for doing the same thing here
Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r-- | iwinfo_nl80211.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index ef0dffa..c4b0ee2 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -298,12 +298,18 @@ static int nl80211_phy_idx_from_path(const char *path) char buf[128]; struct dirent *e; const char *cur_path; + int cur_path_len; + int path_len; int idx = -1; DIR *d; if (!path) return -1; + path_len = strlen(path); + if (!path_len) + return -1; + d = opendir("/sys/class/ieee80211"); if (!d) return -1; @@ -313,7 +319,11 @@ static int nl80211_phy_idx_from_path(const char *path) if (!cur_path) continue; - if (strcmp(cur_path, path) != 0) + cur_path_len = strlen(cur_path); + if (cur_path_len < path_len) + continue; + + if (strcmp(cur_path + cur_path_len - path_len, path) != 0) continue; snprintf(buf, sizeof(buf), "/sys/class/ieee80211/%s/index", e->d_name); |