View | Details | Raw Unified | Return to bug 144109
Collapse All | Expand All

(-)usr.sbin/wpa/l2_packet.c (-26 / +14 lines)
Lines 29-34 Link Here
29
#include <net/route.h>
29
#include <net/route.h>
30
#include <netinet/in.h>
30
#include <netinet/in.h>
31
#include <arpa/inet.h>
31
#include <arpa/inet.h>
32
#include "net80211/ieee80211_ioctl.h"
32
33
33
#include <stdlib.h>
34
#include <stdlib.h>
34
#include <stdio.h>
35
#include <stdio.h>
Lines 221-258 Link Here
221
static int
222
static int
222
eth_get(const char *device, u8 ea[ETH_ALEN])
223
eth_get(const char *device, u8 ea[ETH_ALEN])
223
{
224
{
224
	struct if_msghdr *ifm;
225
	struct ieee80211req ireq;
225
	struct sockaddr_dl *sdl;
226
	int s;
226
	u_char *p, *buf;
227
	size_t len;
228
	int mib[] = { CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0 };
229
227
230
	if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
228
	s = socket(PF_ROUTE, SOCK_RAW, 0);
231
		return -1;
229
	if (s < 0) {
232
	if ((buf = malloc(len)) == NULL)
233
		return -1;
234
	if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
235
		free(buf);
236
		return -1;
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) {
233
	memset(&ireq, 0, sizeof(ireq));
253
		errno = ESRCH;
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
		return -1;
240
		return -1;
255
	}
241
	}
242
243
	close(s);
256
	return 0;
244
	return 0;
257
}
245
}
258
246

Return to bug 144109