getting interface MAC addr from C
Hi; 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. 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 [EMAIL PROTECTED]
Re: getting interface MAC addr from C
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 [EMAIL PROTECTED] ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: getting interface MAC addr from C
Mario Lobo wrote: Hi; 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; This is probably very far from what you want. MAC stands here for MAC(4) - e.g. security related stuff as opposed to something network (did you read MAC as Media Access Control?). I don't know it that is the easiest/right way to get this information but you can use getifaddrs(3). Attached find a simple program which prints out the interfaces and their MAC addresses using getifaddrs(). The code for getting the printable address is taken from function fmt_sockaddr() from src/usr.bin/netstat/route.c. You can also probably use SIOCGIFADDR with the right socket passed in as fd or with sysctl(3) (int mib[] = { CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0}). 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. 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 HTH Michal ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]