Robert Lunnon wrote:
Looking about in the code WsControl grubs about in the /proc filesystem to get the names of, and count the number of network interfaces. Since /Proc only hosts processes on Solaris this constitutes a linux dependancy we don't need. Studying the ifconfig source gives another possibility instead which look like it may be more portable using ioctl SIOCGIFCONF on an arbitrary IP socket
The return from this call is a structure containing the length of the reply buffer, which seems to contains an array of ifreq structures (one for each interface) which contains among other things the name of the interface. By dividing the size of the buffer by the size of the returned objects we know how many interfaces there are...
Questions Anyone know if this is Is this workable ? Is this workable on linux, (I ask because I don't have linux and don't know linux ioctl implementation details)?
SIOCGIFCONF isn't in the Single Unix Spec, V2, but it does appear to be in Linux. It also appears to be in Irix. Looks like a widely used ioctl.
But note:
http://mail-index.netbsd.org/tech-net/2001/05/09/0001.html http://www.geocrawler.com/archives/3/154/2000/2/0/3362774/ http://www.geocrawler.com/archives/3/495/2000/10/0/4586144/ SIOCGIFCONF is supported by netbsd, but is hard to use gotchas because size of reply larger than expected
http://mail.gnu.org/pipermail/bug-inetutils/2001-January/000055.html glibc supports SIOCGIFCONF, but not for down or virtual interfaces
http://www.cygwin.com/ml/cygwin/2001-03/msg00518.html cygwin supports it (so we can run wine on cygwin on windows :-)
- Dan