Alan
Alan

Reputation: 21

C++ code to get the name of all network interface available on the systems

Does any one know any C++ code to get the name of all network interface available on the computer with there types that is wired or wireless. It will be also equally good if only all interfaces name are available.I want to this with the help of ioctl library e.g.,

ioctl(sd, SIOCGIFNAME, &ifr);
strncpy(ifname,ifr.ifr_name,IFNAMSIZ);
printf("Interface name :%s\n",ifname);

actully the above way is not working.

Thanks

Upvotes: 2

Views: 1086

Answers (2)

Alan
Alan

Reputation: 21

Thanks. But I have found another way i.e. to read the /proc/net/dev file to get the list of all interfaces on the system.

Upvotes: 0

e.dan
e.dan

Reputation: 7475

Try: man getifaddrs - get interface addresses

Upvotes: 1

Related Questions