hostapd提供了控制命令hostapd_cli,使用方法可以查看usage。
源码中的main函数:
int main(int argc, char *argv[])
{
int warning_displayed = 0;
int c;
int daemonize = 0;
if (os_program_init())//不同操作体统平台下执行不同的环境初始化
return -1;
for (;;) { //执行getopt的选择,h则显示usage
c = getopt(argc, argv, "a:BhG:i:p:P:s:v");
if (c < 0)
break;
switch (c) {
case 'a':
action_file = optarg;
break;
case 'B': //后台执行
daemonize = 1;
break;
case 'G':
ping_interval = atoi(optarg);
break;
case 'h':
usage();
return 0;
case 'v':
printf("%s\n", hostapd_cli_version);
return 0;
case 'i': //选择控制的网络接口
os_free(ctrl_ifname);
ctrl_ifname = os_strdup(optarg);
break;
case 'p':
ctrl_iface_dir = optarg;
break;
case 'P':
pid_file = optarg;
break;
case 's':
client_socket_dir = optarg;
break;
default:
usage();
return -1;
}
}
interactive = (argc == optind) && (action_file == NULL);
if (interactive) {
printf("%s\n\n%s\n\n", hostapd_cli_version, cli_license);
}
if (eloop_init())//创建和初始化epoll
return -1;
for (;;) {
if (ctrl_ifname == NULL) {
struct dirent *dent;
DIR *dir = opendir(ctrl_iface_dir);
if (dir) {
while ((dent = readdir(dir))) {
if (os_strcmp(dent->d_name, ".") == 0
||
os_strcmp(dent->d_name, "..") == 0)
continue;