[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] Network interfaces
On Sat, Jan 15, 2011 at 11:00 PM, Jo Even Skarstein <joska@online.no> 
wrote:
Is it possible to enumerate the network interfaces automatically?
Straight copy of function from freemint/tools/ifconfig.c function:
static void
list_all_if (short all)
{
	struct ifconf ifc;
	struct ifreq ifr[50];
	int i, n;
	ifc.ifc_len = sizeof (ifr);
	ifc.ifc_req = ifr;
	if (ioctl (sock, SIOCGIFCONF, &ifc) < 0)
	{
		perror ("cannot get interface list");
		exit (1);
	}
	n = ifc.ifc_len / sizeof (struct ifreq);
	for (i = 0; i < n; ++i)
	{
		if (ifr[i].ifr_addr.sa_family != AF_INET)
			continue;
		if (all || (get_flags (ifr[i].ifr_name) & IFF_UP))
			print_if (ifr[i].ifr_name);
	}
}
Greets,
m