创建 PING 程序时限制 ICMP 回显答复
我正在编写一个多线程 ping 程序。我在每个线程(针对每个 IP)上创建了原始套接字,并使用 sendto() 向每个线程发送了 ICMP Echo 请求,然后在每个线程中执行了 receivevfrom() 。我正在从各种套接字中的 IP 获取消息(例如,如果我使用套接字 S1 来发送 IP1,我会收到从 IP1 到 S1、S2 等的回显回复)。我需要进行绑定吗?
另一个问题是,即使我只发送 1 个 ICMP 请求,我也会从目标收到许多回显回复。有什么办法可以限制这个吗?这导致我错过了一些其他 ICMP 数据包。有没有办法让我的程序要求目标停止发送 ICMP 回显?
谢谢,
I was writing a multithreaded ping program. I created rawsockets on each thread (for each IP) and sent ICMP Echo Request to each using sendto() and then I did recvfrom() in each thread. I am getting messages from IPs in various sockets(like if I had used socket S1 for sendto for IP1, I get echo-replies from IP1 to S1, S2 etc). Do I need to do a bind?
Also another problem is that even though I send only 1 ICMP request I get back many echo replies from target. Is there any way I can limit this? This is causing me to miss some of the other ICMP packets. Is there a way for my program to ask the target to stop sending ICMP echo's?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原始套接字接收所有传入数据包;您将需要进行自己的过滤,或者 - 更好 - 只打开一个原始套接字,并在单个线程上检测所有传入的回显回复。
您的重复数据包可能是由于多个原始套接字造成的 - 您将在每个套接字上获得每个传入数据包的一份副本。另请注意,在某些情况下,互联网数据包可能会重复(但这种情况很少见)。
Raw sockets pick up all incoming packets; you will need to do your own filtering, or - better yet - only open one raw socket, and detect all of the incoming echo replies on a single thread.
Your duplicate packets may be because of the multiple raw sockets - you'll get one copy of each incoming packet per socket. Also note that in some cases internet packets can be duplicated (this is rare, however).