gpt4 book ai didi

c - WinPcap:丢弃的 WiFi 数据包

转载 作者:行者123 更新时间:2023-11-30 19:40:51 25 4
gpt4 key购买 nike

考虑 sending a single packet 的 WinPcap 教程。要开始运行它,相对简单:

  1. 将代码复制并粘贴到 C IDE 中(在我的例子中为 code::blocks)
  2. #define HAVE_REMOTE添加到第一行
  3. 设置构建选项(链接库和目录)
  4. 设置正确的 MAC 地址
  5. 用您要发送的数据填充数组
  6. 编译并执行(以管理员身份)

它工作得很好并且有很好的文档记录。如果您运行 capturing packets 的其他教程,您将看到数据包已正确传输。

但是,如果将第13个数组元素设置为0~5,则数据包将无法正常传输。例如,在发送数据包之前,添加以下代码行:

数据包[12]=5;

这样,之前正在传输的数据包将不再被传输(没有任何错误消息)。这没有任何意义。根据文档,该数组元素已经是有效负载的一部分(即:不再是 MAC 地址、长度或 header ),并且可以是 0 到 255 之间的任何整数。

问题
为什么第 13 个数组元素导致数据包不再传输?

最佳答案

packet[12]packet[13] 包含使用的 EtherType,例如 IP这是0x0800

参见herehere获取 EtherType 数字列表。

Which doesn't make any sense. According to the documentation, this array element is already part of the payload (ie: no longer mac address, length or header), and could be any integer from 0 to 255.

看起来不是这样的:

pcap_sendpacket() takes as arguments a buffer containing the data to send, the length of the buffer and the adapter that will send it. Notice that the buffer is sent to the net as is, without any manipulation. This means that the application has to create the correct protocol headers in order to send something meaningful.

因此您需要自己组装完整的数据包,包括 IP header 、TCP header 、校验和等。

关于c - WinPcap:丢弃的 WiFi 数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34658655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com