views:

374

answers:

2

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  A: 

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.

Greg Miller
Agreed. No need to reinvent the wheel.
Byron Whitlock
Well, that sounds like it's the only way I will be able to do what I want for right now, unless I can think of something else. What I am basically doing is taking several iPod touch devices and creating a distributed computing setup. The idea is for one iPod to be able to ping for servers (setup on the other iPod touches) and if they're available (in range), then send them a task to do. I'm using C sockets (don't even mention CFNetwork, I've had enough trouble out of that stupid framework lol) to setup the connections. Any ideas on how to ping without iterating through the IP's on my subnet?
Josh Bradley
Rather than having the iPod ping each device, why not have each device broadcast out a packet stating it's available?
Greg Miller
A: 

Why not just look at the ping source ;)

Byron Whitlock