【问题标题】:pcap why always packets of 8 bytes... why?pcap 为什么总是 8 字节的数据包...为什么?
【发布时间】:2010-12-18 00:49:21
【问题描述】:

我正在使用 pcap 库,但我不知道为什么我总是得到这个输出:

新数据包大小:udata= 8 hdr=8 pkt=8

这是代码:

void handle_pcap(u_char *udata, const struct pcap_pkthdr *hdr, const u_char *pkt)
{
  DEBUG("DANY new packet with size: udata= %d hdr=%d pkt=%d", (int) sizeof(udata),(int) sizeof(hdr),(int) sizeof(pkt) );
...
stuff
}

在我使用的另一个文件中:

status = pcap_loop (pcap_obj,
    -1     /* How many packets it should sniff for before returning (a negative value
       means it should sniff until an error occurs  (loop forever) ) */,
    handle_pcap  /* Callback that will be called*/,
    NULL   /* Arguments to send to the callback (NULL is nothing) */);

输出正常吗?

我认为不是因为有时我的程序可以正常工作,有时却不行..

【问题讨论】:

  • 您需要将答案标记为正确。

标签: c pcap


【解决方案1】:

您正在打印指针的大小,而不是查看 pcap_pkthdr* hdr 来查看数据包的大小。

您可以通过查看hdr->caplenhdr->len找到捕获数据的大小和整个数据包的大小。

【讨论】:

    【解决方案2】:

    嗯。您正在获取(各种)指针的大小。

    例如sizeof(udata) 获得u_char * 的大小。这就是为什么这些数字看起来很可疑。

    如果要包的大小,在hdr->caplenhdr->len(前者为抓包长度,后者为包长度)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-20
      • 2023-03-28
      • 2021-12-28
      • 2017-01-03
      • 2011-12-12
      • 2013-12-08
      • 2010-10-17
      • 1970-01-01
      相关资源
      最近更新 更多