Is it possible to get all network interfaces(whether up or down) name and available information in Linux using c++? I mean a program that only uses API to get interface's name. Does "ioctl" print down interfaces?
Asked
Active
Viewed 1.4k times
4
-
[This is the answer](http://stackoverflow.com/questions/8434918/find-available-network-interfaces-in-c-c), search first. – sad1e Aug 28 '13 at 18:36
-
@xingouy. I saw that before. I want to get all interfaces not only availables! – MSH Aug 29 '13 at 10:12
-
1@x5lcfd I did search, this was the result. – Katianie Oct 05 '17 at 18:49
1 Answers
4
Not specially for C++, but you can use the C API and the 'getifaddrs' function to do so: http://man7.org/linux/man-pages/man3/getifaddrs.3.html

PherricOxide
- 15,493
- 3
- 28
- 41
-
Can you explain the example of 'getifaddrs' in the page? why "for" statement runs 6 times while I have only 2 interfaces lo and eth0? – MSH Aug 31 '13 at 12:23
-
From the notes section, "The addresses returned on Linux will usually be the IPv4 and IPv6 addresses assigned to the interface, but also one AF_PACKET address per interface containing lower-level details about the interface and its physical layer." So you get the addresses for ipv4, ipv6, and ethernet address in different ifaddr structs. – PherricOxide Sep 02 '13 at 03:06