Created
April 30, 2014 17:05
-
-
Save citrin/c3d79302c647ac56792e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <net/if_dl.h> /* LLADDR */ | |
#include <ifaddrs.h> | |
#include <err.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
int | |
main(int argc, char *argv[]) | |
{ | |
struct ifaddrs *ifaphead, *ifap; | |
if (getifaddrs(&ifaphead) != 0) | |
err(1, "getifaddrs()"); | |
for (ifap = ifaphead; ifap; ifap = ifap->ifa_next) { | |
struct sockaddr_dl *sdl = | |
(struct sockaddr_dl *)ifap->ifa_addr; | |
if (!sdl || sdl->sdl_family != AF_LINK) | |
continue; | |
uint8_t *mac; | |
mac = (uint8_t *)LLADDR(sdl); | |
printf("Interface: %s MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", | |
ifap->ifa_name, | |
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); | |
} | |
freeifaddrs(ifaphead); | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment