fork(4) download
  1. #include <stdio.h>
  2. #include <ifaddrs.h>
  3. #include <netpacket/packet.h>
  4.  
  5. int main (int argc, const char * argv[])
  6. {
  7. struct ifaddrs *ifaddr=NULL;
  8. struct ifaddrs *ifa = NULL;
  9. int i = 0;
  10.  
  11. if (getifaddrs(&ifaddr) == -1)
  12. {
  13. perror("getifaddrs");
  14. }
  15. else
  16. {
  17. for ( ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
  18. {
  19. if ( (ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET) )
  20. {
  21. struct sockaddr_ll *s = (struct sockaddr_ll*)ifa->ifa_addr;
  22. printf("%-8s ", ifa->ifa_name);
  23. for (i=0; i <s->sll_halen; i++)
  24. {
  25. printf("%02x%c", (s->sll_addr[i]), (i+1!=s->sll_halen)?':':'\n');
  26. }
  27. }
  28. }
  29. freeifaddrs(ifaddr);
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
lo       00:00:00:00:00:00