Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <net/if.h>
- #include <sys/ioctl.h>
- #define PUB_TOPIC "adbiot/changestatus/deviceupdate/matteo/notebook/12345678901234567890123456789012"
- char *deviceupdate = PUB_TOPIC;
- int main(int argc, char** argv)
- {
- int s = socket(PF_INET, SOCK_DGRAM, 0);
- struct ifreq ifr = { .ifr_name = "eth0" };
- ioctl(s, SIOCGIFHWADDR, &ifr);
- sprintf(strrchr(deviceupdate, '/') + 1, "%02x%02x%02x%02x%02x%02x",
- (unsigned char)ifr.ifr_hwaddr.sa_data[0] & 0xff,
- (unsigned char)ifr.ifr_hwaddr.sa_data[1] & 0xff,
- (unsigned char)ifr.ifr_hwaddr.sa_data[2] & 0xff,
- (unsigned char)ifr.ifr_hwaddr.sa_data[3] & 0xff,
- (unsigned char)ifr.ifr_hwaddr.sa_data[4] & 0xff,
- (unsigned char)ifr.ifr_hwaddr.sa_data[5] & 0xff
- );
- printf("topic: %s\n", deviceupdate);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement