Subject: SIOCGIFCONF wierdness
To: None <tech-net@netbsd.org>
From: Alex Barclay <alex@tfo-consulting.com>
List: tech-net
Date: 05/08/2001 14:59:44
Hi all
I'm having trouble accessing the list of interfaces on the machine which
is a NetBSD-current/i386 (Kernel is a 1.5U)
I create a socket of type PF_INET, SOCK_DGRAM
try to use either SIOCGIFCONF or OSIOCGIFCONF and get very strange
results. Using SIOCGIFCONF I get a few of the interface names but by no
means all of them. Using OSIOCGIFCONF I get the interface names but no
address information.
Where did I go wrong??
Thanks
A.
int main()
{
ifconf ifc;
ifc.ifc_len = sizeof(ifreq)*100;
ifc.ifc_ifcu.ifcu_buf = (caddr_t)malloc(sizeof(ifreq)*100);
int sock = socket(PF_INET, SOCK_DGRAM, 0);
int ret;
ret = ioctl(sock, OSIOCGIFCONF, &ifc);
if (ret != 0) {
cerr << "ioctl - ret = " << ret << endl;
exit(1);
}
cout << ifc.ifc_len/sizeof(ifreq) << endl;
ifreq* ifr = ifc.ifc_ifcu.ifcu_req;
for(int i = 0; i < ifc.ifc_len/sizeof(ifreq); ++i) {
cout << ifr[i].ifr_name << endl;
}
return 0;
}