2012-10-19 36 views
1

我正試圖在監視模式下捕獲我的MAC上的數據包,用於研究問題。從這些包我需要一些特殊的信息,例如rssi。不幸的是,鏈接類型說DLT_IEEE802_11_RADIO,但我實際上期望DLT_PRISM_HEADER,因爲應該打開監視器模式。這是一個問題,因爲radiotap標題不提供任何RSSI值或我需要的其他東西。mac osx prism header pcap

這裏是我的代碼(我離開了回調方法等):

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下編碼。

回答

0

從這些數據包中我需要一些特殊的信息,例如, rssi。

然後,除非駕駛員將讓你請求PPI頭而不是radiotap頭 - 使用在監控模式pcap_list_datalinks()主叫pcap_activate()後,如果其包括DLT_PPI,設置鏈路層報頭類型與pcap_set_datalink()到DLT_PPI - 你運氣不好。如果您可以請求PPI標頭,那麼您可以從該標頭獲取RSSI值;請參閱the PPI specification

不幸的是,鏈接類型表示DLT_IEEE802_11_RADIO,但我實際上期望DLT_PRISM_HEADER,因爲應該打開監視器模式。

在任意一個帶有任意Wi-Fi設備和驅動程序的操作系統上,沒有任何理由期望您能夠在監視模式下獲得Prism頭文件。如果你收到廣播信息,你可以得到驅動程序編寫者提供的任何頭文件。現在,驅動程序傾向於使用radiotap - Linux mac80211驅動程序,大多數* BSD驅動程序和OS X驅動程序。

+0

謝謝,使用PPI幀格式有所幫助。 – Cravid