summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heider <a.heider@gmail.com>2022-12-24 11:53:36 +0100
committerChristian Marangi <ansuelsmth@gmail.com>2023-01-20 17:26:58 +0100
commit6194aaf05244241d2f51c471a43584f8d80b64ce (patch)
treef56faaca64f66c2b76380b8da892e9870466080e
parentacbf4fe47d8f6dca340ff05c84779bf4fa16b5dd (diff)
downloadiwinfo-6194aaf05244241d2f51c471a43584f8d80b64ce.tar.gz
nl80211: simplify iterating over phy's devices
There's no need to iterate over all devices in /sys/class/net and check if the phy index matches, sysfs already provides per phy devices. Signed-off-by: Andre Heider <a.heider@gmail.com>
-rw-r--r--iwinfo_nl80211.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c
index 6b2a87a..d7e7d90 100644
--- a/iwinfo_nl80211.c
+++ b/iwinfo_nl80211.c
@@ -826,24 +826,21 @@ static char * nl80211_phy2ifname(const char *ifname)
memset(nif, 0, sizeof(nif));
- if ((d = opendir("/sys/class/net")) != NULL)
+ snprintf(buffer, sizeof(buffer),
+ "/sys/class/ieee80211/phy%d/device/net", phyidx);
+
+ if ((d = opendir(buffer)) != NULL)
{
while ((e = readdir(d)) != NULL)
{
snprintf(buffer, sizeof(buffer),
- "/sys/class/net/%s/phy80211/index", e->d_name);
+ "/sys/class/net/%s/ifindex", e->d_name);
- if (nl80211_readint(buffer) == phyidx)
+ if ((cifidx = nl80211_readint(buffer)) >= 0 &&
+ ((ifidx < 0) || (cifidx < ifidx)))
{
- snprintf(buffer, sizeof(buffer),
- "/sys/class/net/%s/ifindex", e->d_name);
-
- if ((cifidx = nl80211_readint(buffer)) >= 0 &&
- ((ifidx < 0) || (cifidx < ifidx)))
- {
- ifidx = cifidx;
- strncpy(nif, e->d_name, sizeof(nif) - 1);
- }
+ ifidx = cifidx;
+ strncpy(nif, e->d_name, sizeof(nif) - 1);
}
}