--- usr.sbin/wpa/l2_packet.c.old 2010-12-01 19:15:46.000000000 -0700 +++ usr.sbin/wpa/l2_packet.c 2010-12-01 19:21:26.000000000 -0700 @@ -29,6 +29,7 @@ #include #include #include +#include "net80211/ieee80211_ioctl.h" #include #include @@ -221,38 +222,25 @@ static int eth_get(const char *device, u8 ea[ETH_ALEN]) { - struct if_msghdr *ifm; - struct sockaddr_dl *sdl; - u_char *p, *buf; - size_t len; - int mib[] = { CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0 }; + struct ieee80211req ireq; + int s; - if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) - return -1; - if ((buf = malloc(len)) == NULL) - return -1; - if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { - free(buf); + s = socket(PF_ROUTE, SOCK_RAW, 0); + if (s < 0) { return -1; } - for (p = buf; p < buf + len; p += ifm->ifm_msglen) { - ifm = (struct if_msghdr *)p; - sdl = (struct sockaddr_dl *)(ifm + 1); - if (ifm->ifm_type != RTM_IFINFO || - (ifm->ifm_addrs & RTA_IFP) == 0) - continue; - if (sdl->sdl_family != AF_LINK || sdl->sdl_nlen == 0 || - memcmp(sdl->sdl_data, device, sdl->sdl_nlen) != 0) - continue; - memcpy(ea, LLADDR(sdl), sdl->sdl_alen); - break; - } - free(buf); - if (p >= buf + len) { - errno = ESRCH; + memset(&ireq, 0, sizeof(ireq)); + strncpy(ireq.i_name, device, sizeof(ireq.i_name)); + ireq.i_type = IEEE80211_IOC_BSSID; + ireq.i_data = (void *) ea; + ireq.i_len = ETH_ALEN; + if (ioctl(s, SIOCG80211, &ireq) < 0) { + close(s); return -1; } + + close(s); return 0; }