地址在这里。
获取一个iface是否up:
int linux_iface_up(int sock, const char *ifname)
{
wpa_printf(MSG_ERROR, "linux_iface_up: %s",
ifname);
struct ifreq ifr;
int ret;
if (sock < 0)
return -1;
os_memset(&ifr, 0, sizeof(ifr));
os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) {
ret = errno ? -errno : -999;
wpa_printf(MSG_ERROR, "Could not read interface %s flags: %s",
ifname, strerror(errno));
return ret;
}
int a =!!(ifr.ifr_flags & IFF_UP) ;
wpa_printf(MSG_ERROR, "linux_iface_up: %s,%d",
ifname,a);
return a;
}
获取硬件mac地址:
int linux_get_ifhwaddr(int sock, const char *ifname, u8 *addr)
{
wpa_printf(MSG_ERROR, "linux_get_ifhwaddr: %s",
ifname);
struct ifreq ifr;
os_memset(&ifr, 0, sizeof(ifr));
os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
if (ioctl(sock, SIOCGIFHWADDR, &ifr)) {
wpa_printf(MSG_ERROR, "Could not get interface %s hwaddr: %s",
ifname, strerror(errno));
return -1;
}
if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
wpa_printf(MSG_ERROR, "%s: Invalid HW-addr family 0x%04x",
ifname, ifr.ifr_hwaddr.sa_family);
return -1;
}
os_memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
return 0;
}