Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ICMP and the iPhone SDK

I'm looking to implement a Ping class in Cocoa-Touch. From the googling I have done and old c code I have looked at, it seems using the ICMP protocol is the best way to go.

I guess my question is, is ICMP supported in the iPhone SDK, and if not, is there anything in the CoreFoundation Network classes I could use instead? I have had a look at CFHost and CFHostStartInfoResolution(host, kCFHostReachability, &error) but that is more to check if a host exists rather than get the time to respond etc.

like image 529
JamesSugrue Avatar asked Nov 14 '22 16:11

JamesSugrue


1 Answers

Yep, you can theoretically do this. However, the last time I checked you needed to be running as root to get access to the 'raw' BSD socket required for sending ICMP traces. This is true on the Mac, at least, so I'd assume it's the same on the iPhone.

You might want to take a look at the SystemConfiguration framework and the SCReachability APIs as an alternative. These are all asynchronous, so you can potentially keep track of the time that takes to get an idea of the network latency.

like image 57
Jim Dovey Avatar answered Dec 15 '22 00:12

Jim Dovey