4

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?

MSH
  • 429
  • 3
  • 7
  • 20

1 Answers1

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