gpt4 book ai didi

c - pcap_inject 在断开连接的接口(interface)上

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:49:45 24 4
gpt4 key购买 nike

我正在尝试使用 libpcap 实现重播存储在 .pcap 文件中的数据包。过程非常简单:我将使用“pcap_open_offline”打开 pcap 文件,然后将数据包传递到使用 pcap_open_live 打开的设备,然后使用 pcap_inject 通过接口(interface)发送它们。

现在 NIC 没有连接以太网电缆。我知道 pcap_open_live 不会判断打开的设备是否支持发送,所以我从 pcap_inject (errno 100) 得到错误。这是可以预料的吗?如果我只是从 cmd 行使用 tcpreplay,它会完成并且不会出现错误,无论是否插入以太网电缆。

有人知道 tcpreplay/tcpedit 如何处理“死”接口(interface)吗? tcpreplay 是否会在我尝试发送原始数据包时重写数据包 header ?感谢您的帮助!

我在 Ubuntu 14.04 上,界面是无地址的,处于混杂模式:

auto eth1
iface eth1 inet manual
up ifconfig eth1 promisc up
down ifconfig eth1 promisc down

最佳答案

Now the NIC doesn't have an ethernet cable connected to it.

那么您希望通过在该 NIC 上发送数据包获得什么有用的结果?

I know that pcap_open_live won't tell whether the device opened supports sending

设备是否启动会随着时间的推移而改变,因此当您实际尝试发送数据包时,您从 pcap_open_live() 获得的任何答案都可能不正确。

so I get errors from pcap_inject (errno 100)

在 Linux errno.h 中搜索 100 显示:

#define ENETDOWN    100 /* Network is down */

我猜 Linux 网络不喜欢人们尝试通过 send() 系统调用在已关闭的接口(interface)上发送数据包,而 libpcap 就是这样做的。

Is this to be expected?

是的。

If I simply use tcpreplay from the cmd line, it finishes and presents no error

tcpreplay 有一大堆用于发送数据包的不同机制。参见tcpreplay源码中sendpacket.c源文件中的sendpacket()。例如,它们中的一些可能会静静地丢弃在死接口(interface)上发送的数据包,而不是报告错误,并且它可能正在使用其中一种机制。

关于c - pcap_inject 在断开连接的接口(interface)上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32996721/

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