Date: Fri, 4 Aug 2006 13:43:56 +0100 (BST) From: Robert Watson <rwatson@FreeBSD.org> To: Mario Lobo <mario.lobo@ipad.com.br> Cc: freebsd-hackers@freebsd.org Subject: Re: getting interface MAC addr from C Message-ID: <20060804134258.R56045@fledge.watson.org> In-Reply-To: <200608040759.49390.mario.lobo@ipad.com.br> References: <200608040759.49390.mario.lobo@ipad.com.br>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 4 Aug 2006, Mario Lobo wrote: > Would anyone have a tip on how to get the MAC from a C program? > > I tried: > > struct ifreq ifreq; > unsigned char *hw; > > strcpy(ifreq.ifr_name, "rl0"); > ioctl(fd, SIOCGIFMAC, &ifreq); > hw = ifreq.ifr_ifru.ifru_data; ???? > > but i don't know if this is right or, if it is, where to get the MAC from > the structure. I doesn't issue any error compiling or running though. Usually the general purpose interface recommended for inspecting interface information is getifaddrs(), which will build a userspace list of interfaces and their various addresses, including link-layer addresses. Something like the above will work, but may not be preferred. Robert N M Watson Computer Laboratory University of Cambridge > > In linux i used: > > struct ifreq ifreq; > unsigned char *hw; > > strcpy(ifreq.ifr_name, "rl0"); > ioctl(fd, SIOCGIFHWADDR, &ifreq); > hw = ifreq.ifr_hwaddr.sa_data; > > Thanks, > > Mario > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060804134258.R56045>