Limiting ICMP echo replies when creating a PING program

时光怂恿深爱的人放手 提交于 2019-12-05 05:53:57

问题


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,


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



来源:https://stackoverflow.com/questions/6904135/limiting-icmp-echo-replies-when-creating-a-ping-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!