创建一个PING程序时限制ICMP回显应答 [英] Limiting ICMP echo replies when creating a PING program

查看:332
本文介绍了创建一个PING程序时限制ICMP回显应答的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个多线程ping程序。我创建低级插口每个线程(每个IP)上,并发送ICMP回显请求给每个使用的sendto(),然后我做了recvfrom的()的每个线程。我从各种插座的IP获取的信息(例如,如果我用插座S1为SENDTO为IP1,我得到回音答复从IP1到S1,S2等)。我需要做一个绑定?

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?

此外,另一个问题是,即使我只送1 ICMP请求我从后面的目标回波许多回复。有没有什么办法可以限制呢?这是害我错过了一些其他的ICMP数据包。有没有办法为我的程序要求目标停止发送ICMP回送的?

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?

谢谢,

推荐答案

原始套接字拿起所有传入的数据包;你需要做自己的过滤,或者 - 更好 - 只有开立一个原始套接字,并检测所有传入回应回复在单个线程

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).

这篇关于创建一个PING程序时限制ICMP回显应答的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆