mac osx prism header pcap

时间:2012-10-19 09:38:44

标签: macos pcap rssi

我正试图在我的mac上以监控模式捕获数据包以解决研究问题。从这些数据包中我需要一些特殊信息,例如rssi。不幸的是,linktype表示DLT_IEEE802_11_RADIO,但实际上我期望DLT_PRISM_HEADER,因为应该打开监控模式。这是一个问题,因为radiotap标头不提供任何RSSI值或我需要的其他东西。

这是我的代码(我省略了回调方法等等):

int main(int argc, char *argv[])
{
pcap_t *handle; /* Session handle */
char *dev;  /* The device to sniff on */
char errbuf[PCAP_ERRBUF_SIZE];  /* Error string */
struct pcap_pkthdr header;  /* The header that pcap gives us */
const u_char *packet;   /* The actual packet */
struct ether_header *ether;  /* net/ethernet.h */

/* Define the device */
dev = pcap_lookupdev(errbuf);
if(dev == NULL) {
    printf("Couldn't find default device: %s\n", errbuf);
    exit(EXIT_FAILURE);
}
printf("Device: %s\n", dev);

//handle = pcap_open_live(dev, 1562, 1, 500, errbuf);
handle = pcap_create(dev, errbuf);
if(handle == NULL) {
    printf("pcap_create failed: %s\n", errbuf);
    exit(EXIT_FAILURE);
}

/* set monitor mode on */
if(pcap_set_rfmon(handle, 1) != 0) {
    printf("monitor mode not available\n");
    exit(EXIT_FAILURE);
}
pcap_set_snaplen(handle, 2048);  // Set the snapshot length to 2048
pcap_set_promisc(handle, 1); // Turn promiscuous mode on
pcap_set_timeout(handle, 512); // Set the timeout to 512 milliseconds

int status = pcap_activate(handle);
if(status != 0) {
    printf("activation failed: %d\n", status);
}

printf("link-type: %s\n", pcap_datalink_val_to_name(pcap_datalink(handle)));

int loop = pcap_loop(handle, 1, process_packet, NULL);
if(loop != 0) {
    printf("loop terminated before exhaustion: %d\n", loop);
}

/* And close the session */
pcap_close(handle);

return(0);
}

所以有人知道,为什么我接受radiotap而不是棱镜以及我应该怎么做呢? 我再次在OSX下编码。

1 个答案:

答案 0 :(得分:0)

  

从这些数据包中我需要一些特殊信息,例如rssi。

然后,除非驱动程序允许您请求PPI标头而不是radiotap标头 - 在调用pcap_list_datalinks()后在监控模式下使用pcap_activate() ,如果包含DLT_PPI,则设置链接层标题类型为DLT_PPI pcap_set_datalink() - 你运气不好。如果您可以请求PPI标头,那么您可以从该标头获取RSSI值;见the PPI specification

  

不幸的是,linktype表示DLT_IEEE802_11_RADIO,但我实际上期望DLT_PRISM_HEADER,因为应该打开监控模式。

在具有任意Wi-Fi设备和驱动程序的任意操作系统上,没有任何理由期望您在监视模式下获得Prism标头。如果您获得无线电信息,您将获得驱动程序编写者提供的任何标题。这些天,驱动程序倾向于使用radiotap - Linux mac80211驱动程序,大多数* BSD驱动程序和OS X驱动程序。

相关问题