I need to obtain the IP address of the default gateway in an iPhone application. I cannot find the proper API. Anyone know if iPhone exposes this information?
If I'm not mistaken, the gateway IP is always whatever your device IP address is, with the last octet set to "1", isn't it? If that's what you're looking for, you should be able to find the hints you need from the localhostAddresses.m file which is part of the samples in CocoaHTTPServer sources. I use the project to add an internal webserver within my app and I get the devices IP from that source file's methods.
Dr. Touch talks about it at this link.
I was successful obtaining the address from SSDP protocol by sending a UDP packet out looking for service type "urn:schemas-upnp-org:device:InternetGatewayDevice:1" and noting the first device (if any) that replies (ignoring the payload, since I only want the IP address of the gateway).
This works for my application, but requires that the router implement SSDP, which is not perfect, although works in my case.
Since this is a special-purpose iPhone App (in-house, only), I am going to go with this. I won't mark this as "the answer" because it is not a general purpose solution. If I come back to this and look for a general purpose solution (such as using ICMP), or figuring out how to use the iPhone SDK configuration APIs to query for this information, I will post here.