2013-05-10 109 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