diff --git a/lib/libnet/libnet.c b/lib/libnet/libnet.c index 70c6f2f2e..439c0cd47 100644 --- a/lib/libnet/libnet.c +++ b/lib/libnet/libnet.c @@ -265,3 +265,23 @@ void netGetNameserver( char *ip ) } fclose(fp); } + +void netGetMacAddr(char * ifname, unsigned char * mac) +{ + int fd; + struct ifreq ifr; + + + memset(mac, 0, 6); + fd = socket(AF_INET, SOCK_DGRAM, 0); + if(fd < 0) + return; + + ifr.ifr_addr.sa_family = AF_INET; + strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1); + + if(ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) + return; + + memmove(mac, ifr.ifr_hwaddr.sa_data, 6); +} diff --git a/lib/libnet/libnet.h b/lib/libnet/libnet.h index a1ddad998..2f1d7fe97 100644 --- a/lib/libnet/libnet.h +++ b/lib/libnet/libnet.h @@ -17,6 +17,7 @@ extern char *netGetHostname( void ); extern void netSetHostname( char *host ); extern void netSetNameserver(const char *ip); extern void netGetNameserver( char *ip ); +extern void netGetMacAddr(char * ifname, unsigned char * mac); #ifdef __cplusplus