hostapd的分析

Hostapd的功能就是作为AP的认证服务器,负责控制管理stations(通常可以认为带无线网卡的PC)的接入和认证。
通过Hostapd可以将无线网卡切换为AP/Master模式,通过修改配置文件,可以建立一个开放式的(不加密)的,WEP,WPA或WPA2的无线网络。并且通过修改配置文件可以设置无线网卡的各种参数,包括频率,信号,beacon包时间间隔,是否发送beacon包,如果响应探针请求等等。还可以设置mac地址过滤条件等。
这里写图片描述
hostapd的main函数

int main(int argc, char *argv[])
{
    struct hapd_interfaces interfaces;
    int ret = 1;
    size_t i, j;
    int c, debug = 0, daemonize = 0;
    char *pid_file = NULL;
    const char *log_file = NULL;
    const char *entropy_file = NULL;
    char **bss_config = NULL, **tmp_bss;
    size_t num_bss_configs = 0;
#ifdef CONFIG_DEBUG_LINUX_TRACING
    int enable_trace_dbg = 0;
#endif /* CONFIG_DEBUG_LINUX_TRACING */
    int start_ifaces_in_sync = 0;
    char **if_names = NULL;
    size_t if_names_size = 0;

    if (os_program_init())
        return -1;

    os_memset(&interfaces, 0, sizeof(interfaces));
    interfaces.reload_config = hostapd_reload_config;
    interfaces.config_read_cb = hostapd_config_read;
    interfaces.for_each_interface = hostapd_for_each_interface;
    interfaces.ctrl_iface_init = hostapd_ctrl_iface_init;
    interfaces.ctrl_iface_deinit = hostapd_ctrl_iface_deinit;
    interfaces.driver_init = hostapd_driver_init;
    interfaces.global_iface_path = NULL;
    interfaces.global_iface_name = NULL;
    interfaces.global_ctrl_sock = -1;
    dl_list_init(&interfaces.global_ctrl_dst);

    for (;;) {
        c = getopt(argc, argv, "b:Bde:f:hi:KP:STtu:vg:G:");
        if (c < 0)
            break;
        switch (c) {
        case 'h':
            usage();
            break;
        case 'd':
            debug++;
            if (wpa_debug_level > 0)
                wpa_debug_level--;
            break;
        case 'B':
            daemonize++;
            break;
        case 'e':
            entropy_file = optarg;
            break;
        case 'f':
            log_file = optarg;
            break;
        case 'K':
            wpa_debug_show_keys++;
            break;
        case 'P':
            os_free(pid_file);
            pid_file = os_rel2abs_path(optarg);
            break;
        case 't':
            wpa_debug_timestamp++;
            break;
#ifdef CONFIG_DEBUG_LINUX_TRACING
        case 'T':
            enable_trace_dbg = 1;
            break;
#endif /* CONFIG_DEBUG_LINUX_TRACING */
        case 'v':
            show_version();
            exit(1);
            break;
        case 'g':
            if (hostapd_get_global_ctrl_iface(&interfaces, optarg))
                return -1;
            break;
        case 'G':
            if (hostapd_get_ctrl_iface_group(&interfaces, optarg))
                return -1;
            break;
        case 'b':
            tmp_bss = os_realloc_array(bss_config,
                           num_bss_configs + 1,
                           sizeof(char *));
            if (tmp_bss == NULL)
                goto out;
            bss_config = tmp_bss;
            bss_config[num_bss_configs++] = optarg;
            break;
        case 'S':
            start_ifaces_in_sync = 1;
            break;
#ifdef CONFIG_WPS
        case 'u':
            return gen_uuid(optarg);
#endif /* CONFIG_WPS */
        case 'i':
            if (hostapd_get_interface_names(&if_names,
                            &if_names_size, optarg))
                goto out;
            break;
        default:
            usage();
            break;
        }
    }

    if (optind == argc && interfaces.global_iface_path == NULL &&
        num_bss_configs == 0)
        usage();

    wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb);

    if (log_file)
        wpa_debug_open_file(log_file);
    else
        wpa_debug_setup_stdout();
#ifdef CONFIG_DEBUG_LINUX_TRACING
    if (enable_trace_dbg) {
        int tret = wpa_debug_open_linux_tracing();
        if (tret) {
            wpa_printf(MSG_ERROR, "Failed to enable trace logging");
            return -1;
        }
    }
#endif /* CONFIG_DEBUG_LINUX_TRACING */

    interfaces.count = argc - optind;
    if (interfaces.count || num_bss_configs) {
        interfaces.iface = os_calloc(interfaces.count + num_bss_configs,
                         sizeof(struct hostapd_iface *));
        if (interfaces.iface == NULL) {
            wpa_printf(MSG_ERROR, "malloc failed");
            return -1;
        }
    }

    if (hostapd_global_init(&interfaces, entropy_file)) {
        wpa_printf(MSG_ERROR, "Failed to initialize global context");
        return -
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值