gpt4 book ai didi

sockets - 嗅探所有网络接口(interface)

转载 作者:行者123 更新时间:2023-12-03 11:53:27 25 4
gpt4 key购买 nike

我编写了一个程序,它使用套接字来捕获网络接口(interface)上的数据包。首先,我使用 收集我机器的所有 IP。获取主机名 ,然后使用 将原始套接字绑定(bind)到每个 ip SOCK_RAW , IPPROTO_IP SIO_RCVALL 选项。为调用 的每个 IP 执行一个线程接收 在适当的套接字上(每个 ip 一个套接字)。该程序运行良好。

但是我发现了一个特殊的地址,名为 INADDR_ANY . MSDN 说 SIO_RCVALL 不能与 INADDR_ANY 一起使用,它是 here :

The socket also must be bound to an explicit local IPv4 or IPv6 interface, which means that you cannot bind to INADDR_ANY or in6addr_any.



是否可以使用一个套接字监视和捕获所有数据包(与本地计算机相关的数据包,而不是其他计算机的数据包)?

谢谢

最佳答案

INADDR_ANY表示“我不在乎哪个本地地址”,不是 “所有本地地址。”
来自 MSDN :

If an application does not care what local address is assigned, specify the constant value INADDR_ANY for an IPv4 local address or the constant value in6addr_any for an IPv6 local address in the sa_data member of the name parameter. This allows the underlying service provider to use any appropriate network address, potentially simplifying application programming in the presence of multihomed hosts (that is, hosts that have more than one network interface and address).

关于sockets - 嗅探所有网络接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5220879/

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