2013-05-10 38 views
0

我已經得到了使用功能ieee80211_radiotap_iterator_init()radiotap-parser.cieee80211_radiotap_iterator_next()一些代碼,libpcap的Radiotap頭提取

我不知道我在做什麼錯誤,也許有人能教我嗎?我使用的示例代碼the documentation或多或少不加修飾,它非常適合於什麼,我想實現:

/* where packet is `const u_char *packet' */ 
struct ieee80211_radiotap_iterator rti; 
struct ieee80211_radiotap_header *rth = (struct ieee80211_radiotap_header *) packet; 

/* 802.11 frame starts here */ 
struct wi_frame *fr= (struct wi_frame *) (packet + rth->it_len); 

/* Set up the iteration */ 
int ret = ieee80211_radiotap_iterator_init(&rti, rth, rth->it_len); 

/* Loop until we've consumed all the fields */ 
while(!ret) { 
    printf("Itteration: %d\n", count++); 
    ret = ieee80211_radiotap_iterator_next(&rti); 
    if(ret) { 
    /* 
    * The problem is here, I'm dropping into this clause with 
    * a value of `1` consistently, that doesn't match my platform's 
    * definition of EINVAL or ENOENT. 
    */ 
    continue; 
    } 
    switch(rti.this_arg_index) { 
    default: 
    printf("Constant: %d\n", *rti.this_arg); 
    break; 
    } 
} 

有有限的範圍內對代碼有擰東西了,我想,我被1ieee80211_radiotap_iterator_next()返回,根據實現似乎並不像the implementation中的錯誤條件。

我正在篩選類型爲"(type mgt) and (not type mgt subtype beacon)"的數據包,我甚至不確定在數據鏈接設置爲DLT_IEEE802_11_RADIO時,libpcap是否會包含這些屬性?

回答

1

第一:

我過濾類型的數據包「(類型MGT)和(未鍵入MGT亞型信標)」,我甚至不能肯定是否libpcap的將包括這些屬性的時數據鏈接設置爲DLT_IEEE802_11_RADIO?

它會的。爲DLT_IEEE802_11_RADIO生成的過濾器代碼獲取radiotap標頭長度並跳過radiotap標頭,因此它將跳過radiotap標頭並檢查後面的802.11標頭。

二:

您鏈接到的ieee80211_radiotap_iterator_next() 2個不同實現實施 - the one at radiotap-parser.c,其中ieee80211_radiotap_iterator_next()返回 「下一個本ARG指數」 上的成功,the one from the Linux kernel,其中ieee80211_radiotap_iterator_next()成功返回0。如果您使用的radiotap迭代器代碼是radiotap-parser.c中的代碼,請不要注意來自Linux內核的那個代碼,因爲它不像您使用的代碼那樣運行。

+0

謝謝Guy,我不確定如何使用'ieee80211_radiotap_iterator_next()'的用戶執行的結果。但我會繼續挖掘。我甚至沒有考慮過這兩個函數會有兩個並行的實現! – 2013-05-12 08:56:08