diff options
author | Jonathan McCrohan <jmccrohan@gmail.com> | 2011-10-24 01:30:23 +0100 |
---|---|---|
committer | Jonathan McCrohan <jmccrohan@gmail.com> | 2011-10-24 01:30:23 +0100 |
commit | 8adfff8b2419a0f79e85ba6884e507e787a313da (patch) | |
tree | 3e360dd9b0c2d238520b16718218045df4872bf6 /gethwaddr.c | |
parent | 2643a5dc67dc6945ce8e0a3962818b16a240f0b5 (diff) | |
download | verteco-8adfff8b2419a0f79e85ba6884e507e787a313da.tar.gz |
Timer working. MAC address in string variable.
Diffstat (limited to '')
-rw-r--r-- | gethwaddr.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gethwaddr.c b/gethwaddr.c new file mode 100644 index 0000000..2ca2fbb --- /dev/null +++ b/gethwaddr.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <net/if.h> +#include <string.h> + +int main( int argc, char *argv[] ) +{ + int s; + struct ifreq ifr; + + s = socket(PF_INET, SOCK_DGRAM, 0); + memset(&ifr, 0x00, sizeof(ifr)); + strcpy(ifr.ifr_name, "eth0"); + ioctl(s, SIOCGIFHWADDR, &ifr); + close(s); + + unsigned char mac_address[6]; + sprintf(mac_address,"%.2X%.2X%.2X%.2X%.2X%.2X", (unsigned char) ifr.ifr_hwaddr.sa_data[0], (unsigned char) ifr.ifr_hwaddr.sa_data[1], (unsigned char) ifr.ifr_hwaddr.sa_data[2], (unsigned char) ifr.ifr_hwaddr.sa_data[3], (unsigned char) ifr.ifr_hwaddr.sa_data[4], (unsigned char) ifr.ifr_hwaddr.sa_data[5]); + printf("%s", mac_address); + +} |