29 |
29 |
#include <net/route.h>
|
30 |
30 |
#include <netinet/in.h>
|
31 |
31 |
#include <arpa/inet.h>
|
|
32 |
#include "net80211/ieee80211_ioctl.h"
|
32 |
33 |
|
33 |
34 |
#include <stdlib.h>
|
34 |
35 |
#include <stdio.h>
|
... | ... | |
221 |
222 |
static int
|
222 |
223 |
eth_get(const char *device, u8 ea[ETH_ALEN])
|
223 |
224 |
{
|
224 |
|
struct if_msghdr *ifm;
|
225 |
|
struct sockaddr_dl *sdl;
|
226 |
|
u_char *p, *buf;
|
227 |
|
size_t len;
|
228 |
|
int mib[] = { CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0 };
|
|
225 |
struct ieee80211req ireq;
|
|
226 |
int s;
|
229 |
227 |
|
230 |
|
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
|
231 |
|
return -1;
|
232 |
|
if ((buf = malloc(len)) == NULL)
|
233 |
|
return -1;
|
234 |
|
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
|
235 |
|
free(buf);
|
|
228 |
s = socket(PF_ROUTE, SOCK_RAW, 0);
|
|
229 |
if (s < 0) {
|
236 |
230 |
return -1;
|
237 |
231 |
}
|
238 |
|
for (p = buf; p < buf + len; p += ifm->ifm_msglen) {
|
239 |
|
ifm = (struct if_msghdr *)p;
|
240 |
|
sdl = (struct sockaddr_dl *)(ifm + 1);
|
241 |
|
if (ifm->ifm_type != RTM_IFINFO ||
|
242 |
|
(ifm->ifm_addrs & RTA_IFP) == 0)
|
243 |
|
continue;
|
244 |
|
if (sdl->sdl_family != AF_LINK || sdl->sdl_nlen == 0 ||
|
245 |
|
memcmp(sdl->sdl_data, device, sdl->sdl_nlen) != 0)
|
246 |
|
continue;
|
247 |
|
memcpy(ea, LLADDR(sdl), sdl->sdl_alen);
|
248 |
|
break;
|
249 |
|
}
|
250 |
|
free(buf);
|
251 |
232 |
|
252 |
|
if (p >= buf + len) {
|
253 |
|
errno = ESRCH;
|
|
233 |
memset(&ireq, 0, sizeof(ireq));
|
|
234 |
strncpy(ireq.i_name, device, sizeof(ireq.i_name));
|
|
235 |
ireq.i_type = IEEE80211_IOC_BSSID;
|
|
236 |
ireq.i_data = (void *) ea;
|
|
237 |
ireq.i_len = ETH_ALEN;
|
|
238 |
if (ioctl(s, SIOCG80211, &ireq) < 0) {
|
|
239 |
close(s);
|
254 |
240 |
return -1;
|
255 |
241 |
}
|
|
242 |
|
|
243 |
close(s);
|
256 |
244 |
return 0;
|
257 |
245 |
}
|
258 |
246 |
|