示例#1
0
static int hostap_init_sockets(struct hostap_driver_data *drv)
{
    struct ifreq ifr;
    struct sockaddr_ll addr;

    drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
    if (drv->sock < 0) {
        perror("socket[PF_PACKET,SOCK_RAW]");
        return -1;
    }

    if (eloop_register_read_sock(drv->sock, handle_read, drv->hapd, NULL))
    {
        printf("Could not register read socket\n");
        return -1;
    }

    memset(&ifr, 0, sizeof(ifr));
    snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
    if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
        perror("ioctl(SIOCGIFINDEX)");
        return -1;
    }

    if (hostap_set_iface_flags(drv, 1)) {
        return -1;
    }

    memset(&addr, 0, sizeof(addr));
    addr.sll_family = AF_PACKET;
    addr.sll_ifindex = ifr.ifr_ifindex;
    wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
               addr.sll_ifindex);

    if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
        perror("bind");
        return -1;
    }

    memset(&ifr, 0, sizeof(ifr));
    os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
    if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
        perror("ioctl(SIOCGIFHWADDR)");
        return -1;
    }

    if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
        printf("Invalid HW-addr family 0x%04x\n",
               ifr.ifr_hwaddr.sa_family);
        return -1;
    }
    memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);

    return 0;
}
示例#2
0
static void hostap_driver_deinit(void *priv)
{
    struct hostap_driver_data *drv = priv;

    (void) hostap_set_iface_flags(drv, 0);
    (void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 0);
    (void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD_STA, 0);

    if (drv->ioctl_sock >= 0)
        close(drv->ioctl_sock);

    if (drv->sock >= 0)
        close(drv->sock);

    os_free(drv->generic_ie);

    free(drv);
}
示例#3
0
static int hostap_init_sockets(struct hostap_driver_data *drv, u8 *own_addr)
{
	struct ifreq ifr;
	struct sockaddr_ll addr;

	drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
	if (drv->sock < 0) {
		wpa_printf(MSG_ERROR, "socket[PF_PACKET,SOCK_RAW]: %s",
			   strerror(errno));
		return -1;
	}

	if (eloop_register_read_sock(drv->sock, handle_read, drv, NULL)) {
		wpa_printf(MSG_ERROR, "Could not register read socket");
		return -1;
	}

        memset(&ifr, 0, sizeof(ifr));
        snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
        if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
		wpa_printf(MSG_ERROR, "ioctl(SIOCGIFINDEX): %s",
			   strerror(errno));
		return -1;
        }

	if (hostap_set_iface_flags(drv, 1)) {
		return -1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sll_family = AF_PACKET;
	addr.sll_ifindex = ifr.ifr_ifindex;
	wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
		   addr.sll_ifindex);

	if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
		wpa_printf(MSG_ERROR, "bind: %s", strerror(errno));
		return -1;
	}

	return linux_get_ifhwaddr(drv->sock, drv->iface, own_addr);
}