network_interface_list.cpp 707 B

123456789101112131415161718192021222324252627282930
  1. #include "simple/io/address.h"
  2. #include <iostream>
  3. int main() try
  4. {
  5. auto list = get<0>(simple::io::make_network_interface_list());
  6. std::cout << '\n';
  7. std::cout << "IPv4 network interfaces with broadcast support:" << '\n';
  8. for(auto&& interface : simple::io::get_range(list))
  9. {
  10. if(interface.up && interface.ip && interface.broadcast_ip)
  11. {
  12. std::cout << interface.name;
  13. std::cout << " - " <<
  14. int(interface.broadcast_ip->address[0]) << '.' <<
  15. int(interface.broadcast_ip->address[1]) << '.' <<
  16. int(interface.broadcast_ip->address[2]) << '.' <<
  17. int(interface.broadcast_ip->address[3]) << '\n';
  18. }
  19. }
  20. std::cout << '\n';
  21. return 0;
  22. }
  23. catch(...)
  24. {
  25. perror("omaaaagooot");
  26. throw;
  27. }