I have written a program in C which communicates through udp with an Arduino.
My question is, how can I “ping” an ip address and only get a 1 or 0 (available or not) in C (unix).
The system("ping xxx.xxx.xxx.xxx"); call doesn’t work because it outputs a list…?
Should do the trick.
-c 1sends only a single packet. We pipe to/dev/nullas we don’t care about the output to stdout (is that the list you refer to?). If you also want to discard stderr, add a2>&1to the end. You might also want to limit the response time using-W.The call will return an integer representing the success or failure. 0 indicates success, while a non-zero integer represents failure. Here’s some sample code: http://ideone.com/cf0eR
Be aware that a failed ping does not guarantee that the device is offline. Although in your controlled environment, it’s probably a reasonable thing to expect it to work.