I need to collect all the interface names, even the ones that aren't up at the moment. Like ifconfig -a
.
getifaddrs()
is iterating through same interface name multiple times. How can I collect all the interface names just once using getifaddrs()
?
You can use the ifconfig command to list the network interfaces available in your system. Instead of typing ifconfig, type the command /sbin/ifconfig to list the network interfaces in your system.
Open the terminal application. Type ifconfig -a to check the network interface. Press Enter to run the command. The output will display information about all the network interfaces on the system.
ifconfig command – It is used to display or configure a network interface.
Here is what you need to do. First list all NIC ports, each line is a port. Now you can see the bus-info: 0000:08:00.0 matches 08:00.0 Ethernet controller: Solarflare Communications SFC9120 (rev 01) . Now you will be able to find out how many NIC ports you have, how many free ports on each card.
You could check which entries from getifaddrs belong to the AF_PACKET family. On my system that seems to list all interfaces:
struct ifaddrs *addrs,*tmp;
getifaddrs(&addrs);
tmp = addrs;
while (tmp)
{
if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET)
printf("%s\n", tmp->ifa_name);
tmp = tmp->ifa_next;
}
freeifaddrs(addrs);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With