C Sockets Ping Command?

2019-08-02 11:59发布

Can someone point me to some tutorial on how to set up a ping method using C sockets? Using beej's guide, I've been able to set up a connection between two devices, but now I want to setup a method that pings for all available devices before starting an actual connection. I've never done this before, so would you do something like set up a multicast socket to broadcast an empty data packet and then have the receiver of that empty packet fill it with their IP address and return that now full data packet so that you have the address to start the connection? Any guide's/ help would be appreciated!

2条回答
We Are One
2楼-- · 2019-08-02 12:23

Why not just look at the ping source ;)

查看更多
劫难
3楼-- · 2019-08-02 12:42

Most current IP stacks will not respond to a ping request to a broadcast address. The feature was abused for denial of service attacks.

Implementing a real ping implementation won't be easy, I'd suggest you use an existing lib: http://www.kernelthread.com/projects/hanoi/html/icmp.html

But you will have to manually iterate through all of the IP addrs on your subnet to get them to respond.

查看更多
登录 后发表回答