c - libpcap Radiotap header 提取

标签 c linux libpcap tcpdump wifi

我有一些代码使用来自 radiotap-parser.c 的函数 ieee80211_radiotap_iterator_init()ieee80211_radiotap_iterator_next() ,

我不确定我做错了什么,也许有人可以教育我?我正在使用 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;
  }
}

我认为,在该代码中搞砸的范围有限,我对从 ieee80211_radiotap_iterator_next() 返回的 1 感到困惑,根据实现在 the implementation 中似乎不是错误条件.

我正在过滤 "(type mgt) and (not type mgt subtype beacon)" 类型的数据包,我什至不确定 libpcap 是否会在数据链接时包含这些属性设置为 DLT_IEEE802_11_RADIO

最佳答案

首先:

I'm filtering for packets of type "(type mgt) and (not type mgt subtype beacon)", and I'm not even certain if libpcap will include these attributes when the data link is set to DLT_IEEE802_11_RADIO?

会的。为 DLT_IEEE802_11_RADIO 生成的过滤器代码获取 radiotap header 长度并跳过 radiotap header ,因此它只会跳过 radiotap header 并检查其后的 802.11 header 。

第二个:

the implementation

您链接到 ieee80211_radiotap_iterator_next() 的两个不同实现 - the one at radiotap-parser.c ,其中 ieee80211_radiotap_iterator_next() 成功返回“下一个当前参数索引”,the one from the Linux kernel ,其中 ieee80211_radiotap_iterator_next() 成功返回 0。如果您使用的 radiotap 迭代器代码是 radiotap-parser.c 中的代码,请不要注意 Linux 内核中的代码,因为它的行为与您使用的代码不同。

关于c - libpcap Radiotap header 提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16483010/

相关文章:

php - UTF-8贯穿始终

mysql - 在 Linux 机器上远程连接到 mysql 时出现问题

C中的字符问题

c - 分配内存并在c中保存字符串

C型铸件: bitwise or arithmetic

c - pthread_join 如何填充 thread_result 的变量

python - 使用python通过文件设置环境变量

c++ - 我怎么会空,没有抓包?

c++ - 写入图像

c - 802.11数据包的大小