diff options
author | Rich Felker <dalias@aerifal.cx> | 2012-07-21 17:56:48 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2012-07-21 17:56:48 -0400 |
commit | 68c58223672465202958a5da16f19f64f32acf74 (patch) | |
tree | 4ea057a942cbedf1ef8dd9fcac3697cb5b9f8560 /src | |
parent | f07222739bc744fd7f5d5a06f2b39d07fde6ab3e (diff) | |
download | musl-68c58223672465202958a5da16f19f64f32acf74.tar.gz |
fix logic error for skipping failed interfaces in if_nameindex
Diffstat (limited to 'src')
-rw-r--r-- | src/network/if_nameindex.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/network/if_nameindex.c b/src/network/if_nameindex.c index 580acce0..cdb956cb 100644 --- a/src/network/if_nameindex.c +++ b/src/network/if_nameindex.c @@ -10,7 +10,7 @@ static void *do_nameindex(int s, size_t n) { - size_t i, len; + size_t i, len, k; struct ifconf conf; struct if_nameindex *idx; @@ -29,17 +29,16 @@ static void *do_nameindex(int s, size_t n) } n = conf.ifc_len / sizeof(struct ifreq); - for (i=0; i<n; i++) { + for (i=k=0; i<n; i++) { if (ioctl(s, SIOCGIFINDEX, &conf.ifc_req[i]) < 0) { - i--; - n--; + k++; continue; } - idx[i].if_index = conf.ifc_req[i].ifr_ifindex; - idx[i].if_name = conf.ifc_req[i].ifr_name; + idx[i-k].if_index = conf.ifc_req[i].ifr_ifindex; + idx[i-k].if_name = conf.ifc_req[i].ifr_name; } - idx[i].if_name = 0; - idx[i].if_index = 0; + idx[i-k].if_name = 0; + idx[i-k].if_index = 0; return idx; } |