Guest User

Untitled

a guest
Jan 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. # headers elided
  2.  
  3.  
  4. int main()
  5. {
  6. char buf[1024];
  7. struct ifconf ifc;
  8. struct ifreq *ifr;
  9. int sck;
  10. int count;
  11. int i;
  12.  
  13. sck = socket(2, 2, 0);
  14. if (sck < 0)
  15. {
  16. perror("socket");
  17. return 1;
  18. }
  19.  
  20. ifc.ifc_len = sizeof(buf);
  21. ifc.ifc_ifcu.ifcu_buf = buf;
  22. if (ioctl(sck, (0x80000000|(((long)sizeof(struct ifconf)&0x7f)<<16)|('s'<<8)|100), &ifc) < 0)
  23. {
  24. perror("ioerror");
  25. return 1;
  26. }
  27.  
  28. ifr = ifc.ifc_ifcu.ifcu_req;
  29. count = ifc.ifc_len / sizeof(struct ifreq);
  30.  
  31. for (i = 0; i < count; i++)
  32. {
  33. struct ifreq *item = &ifr[i];
  34. fprintf(((__getreent())->_stdout), "name: %s\n", item->ifr_ifrn.ifrn_name);
  35. fprintf(((__getreent())->_stdout), "hwaddr: %02x:%02x:%02x:%02x:%02x:%02x\n",
  36. (unsigned char)item->ifr_ifru.ifru_hwaddr.sa_data[0],
  37. (unsigned char)item->ifr_ifru.ifru_hwaddr.sa_data[1],
  38. (unsigned char)item->ifr_ifru.ifru_hwaddr.sa_data[2],
  39. (unsigned char)item->ifr_ifru.ifru_hwaddr.sa_data[3],
  40. (unsigned char)item->ifr_ifru.ifru_hwaddr.sa_data[4],
  41. (unsigned char)item->ifr_ifru.ifru_hwaddr.sa_data[5]);
  42. }
  43. }
Add Comment
Please, Sign In to add comment