Currently, we assume that the last ID of interfaces is equal to the number of interfaces available. But the documentation on FreeBSD and Linux say that the table of interface can be sparse. This patch is a naive one which try any ID until we found what we want or we discover all interfaces available.
The patch fix an issue on Linux (EMFILE) and properly close the nl_socket in any situation (even if the function fails).
in sysctl_ifcounr return the highest index that is available (as done on FreeBSD) - but it seems there's no easy path to that (apart from iterating over the entire cache)
use a different C stub and call the rtnl_link_get_by_nane, and avoid the index dance (that seems to be not necessary on Linux anyways)
Currently, we assume that the last ID of interfaces is equal to the number of interfaces available. But the documentation on FreeBSD and Linux say that the table of interface can be sparse. This patch is a naive one which try any ID until we found what we want or we discover all interfaces available.
The patch fix an issue on Linux (EMFILE) and properly close the
nl_socket
in any situation (even if the function fails).