我有一个功能,可以使用libpCap在MacOS上为WiFi设备启用监控模式.这是可行的,但目前将WiFi设备设置回托管模式的唯一方法是退出该进程.我希望将WiFi设备设置为托管模式,同时允许该过程继续.据我所知,这不能用libpcap.我如何将WiFi设备设置回托管模式(可能使用Objective-C中的CoreWLAN API?)?
pcap_t *enable_monitor(char *dev) {
wifi_disassociate();
char error_buffer[PCAP_ERRBUF_SIZE];
pcap_t *handle;
int result;
handle = pcap_create(dev, error_buffer);
if (handle == NULL) {
printf("failed to create a handle: %s\n",
error_buffer);
return NULL;
}
result = pcap_set_rfmon(handle, 1);
if (result != 0) {
printf("failed to set pcap rfmon: %s (%s)\n",
pcap_statustostr(result),
pcap_geterr(handle));
return NULL;
}
result = pcap_activate(handle);
if (result != 0) {
printf("failed to activate handle: %s (%s)\n",
pcap_statustostr(result),
pcap_geterr(handle));
return NULL;
}
//pcap_close(handle);
return handle;
}
编辑:
将第二个参数设置为cap_set_rfmon
到0似乎并没有将设备设置为托管模式,只是没有将其设置为监视模式.
int disable_monitor(pcap_t *handle) {
int result;
result = pcap_set_rfmon(handle, 0);
if (result != 0) {
printf("failed to set pcap rfmon: %s (%s)\n",
pcap_statustostr(result),
pcap_geterr(handle));
return 1;
}
pcap_close(handle);
return 0;
}
int main() {
char *dev = find_wifi_device();
pcap_t *handle = enable_monitor(dev);
sleep(5);
int status = disable_monitor(handle);
printf("Status: %d\n", status);
for (;;)
sleep(100);
}
这将导致:
failed to set pcap rfmon: The setting can't be changed after the pcap_t is activated (can't perform operation on activated capture)
Status: 1