Guest User

Untitled

a guest
May 11th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include "ieee802154.h"
  3. #include <string.h>
  4.  
  5. #include <linux/sockios.h>
  6. #include <net/if.h>
  7. #include <sys/ioctl.h>
  8. #include <sys/socket.h>
  9. #include <stdio.h>
  10. #include <stdint.h>
  11. #include <string.h>
  12. #include <unistd.h>
  13.  
  14. int socketfd = 0;
  15. struct ifreq ifr;
  16. static const char *wpandevs[] = {
  17. "wpan0"
  18. };
  19.  
  20. int main(int argc, const char *argv[])
  21. {
  22. struct sockaddr_ieee802154 *sa;
  23. const char *socket_config_wpan;
  24. int ret;
  25.  
  26. socket_config_wpan = wpandevs[0];
  27. socketfd = socket(PF_IEEE802154, SOCK_RAW, 0);
  28.  
  29. strncpy(ifr.ifr_name, socket_config_wpan, IF_NAMESIZE);
  30. ret = ioctl(socketfd, SIOCGIFADDR, &ifr);
  31. if (ret < 0) {
  32. fprintf(stderr,"ioctl: SIOCGIFADDR error\n");
  33. return 1;
  34. }
  35.  
  36. sa = (struct sockaddr_ieee802154 *)&ifr.ifr_addr;
  37.  
  38. printf("pan_id 0x%x\n", sa->addr.pan_id);
  39. printf("short_addr 0x%x\n", sa->addr.short_addr);
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment