Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include "ieee802154.h"
- #include <string.h>
- #include <linux/sockios.h>
- #include <net/if.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- #include <unistd.h>
- int socketfd = 0;
- struct ifreq ifr;
- static const char *wpandevs[] = {
- "wpan0"
- };
- int main(int argc, const char *argv[])
- {
- struct sockaddr_ieee802154 *sa;
- const char *socket_config_wpan;
- int ret;
- socket_config_wpan = wpandevs[0];
- socketfd = socket(PF_IEEE802154, SOCK_RAW, 0);
- strncpy(ifr.ifr_name, socket_config_wpan, IF_NAMESIZE);
- ret = ioctl(socketfd, SIOCGIFADDR, &ifr);
- if (ret < 0) {
- fprintf(stderr,"ioctl: SIOCGIFADDR error\n");
- return 1;
- }
- sa = (struct sockaddr_ieee802154 *)&ifr.ifr_addr;
- printf("pan_id 0x%x\n", sa->addr.pan_id);
- printf("short_addr 0x%x\n", sa->addr.short_addr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment