gpt4 book ai didi

linux - 通过本地接口(interface)使用数据链路原始套接字发送和接收 ICMP

转载 作者:太空宇宙 更新时间:2023-11-04 04:08:40 24 4
gpt4 key购买 nike

我正在 Linux 上学习数据链路原始套接字编程,我发现这些很有帮助 examples 。我编译了icmp4_ll.c,并用它向同一局域网中的另一台计算机发送ICMP数据包。我可以收到目标计算机的回复。但是,当我使用它向本地计算机发送ICMP数据包时,即我将源和目标以太网MAC和IP地址设置为eth0的MAC和IP地址时,我在eth0或lo接口(interface)上都无法收到ICMP回复(在Wireshark中,我只注意到通过eth0发送的ICMP请求,但在任何接口(interface)上都没有收到ICMP回复。)我认为 ICMP 请求消息的组成正确(否则远程目标将不会回复)。但我不知道为什么操作系统不回复请求。任何帮助或提示表示赞赏。

最佳答案

RFC 792 定义了 ICMP 消息的特殊条件:

  • No ICMP error messages are sent in response to ICMP error messages to avoid infinite repetition.

  • For fragmented IP datagrams, ICMP messages are only sent for errors on fragmented zero (the first fragment).

  • ICMP error messages are never sent in response to a datagram that is destined to a broadcast or a multicast address.

  • ICMP error messages are never sent in response to a datagram sent as a link layer broadcast.

  • ICMP error messages are never sent in response to a datagram whose source address does not represents a unique host (the source address cannot be zero, a loopback address, a broadcast address or a multicast address).

  • ICMP error messages are never sent in response to an IGMP message of any kind. When an ICMP message of unknown type is received, it must be silently discarded.

路由器几乎总是会生成 ICMP 消息,但当涉及目标主机时,生成的 ICMP 消息数量取决于实现。

关于linux - 通过本地接口(interface)使用数据链路原始套接字发送和接收 ICMP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20155764/

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