I'm trying to find the local ip address using gethostname/gethostbyname but I always get "Unable to Resolve" when doing it.
Why could it be failing? Are there other way to get the local ip address in the iphone?
Thx a lot
I'm trying to find the local ip address using gethostname/gethostbyname but I always get "Unable to Resolve" when doing it.
Why could it be failing? Are there other way to get the local ip address in the iphone?
Thx a lot
-(NSString*)getAddress {
char iphone_ip[255];
strcpy(iphone_ip,"127.0.0.1"); // if everything fails
NSHost* myhost =[NSHost currentHost];
if (myhost)
{
NSString *ad = [myhost address];
if (ad)
strcpy(iphone_ip,[ad cStringUsingEncoding: NSISOLatin1StringEncoding]);
}
return [NSString stringWithFormat:@"%s",iphone_ip];
}
I found a solution using gethostname/gethostbyname in the Erica Sadun book. The trick is to append the ".local" suffix to the hostname before calling gethostbyname.
In addition to the other answers here, I would suggest reviewing the Reachability sample code on the ADC site.
Can you please post the code on how to get the device ip address using gethostname or gethostbyname. It will be great if any one can help me with this i just got stuck with this. PLease help me out. Waiting fr the soonest response
It's worth noting that many carriers (especially outside the "first world") hand out RFC1918 (usually 10.0.0.0/8) addresses and so doing a HTTP request to one of the services could be better (except, of course, that many carriers, out of necessity use multiple public addresses for large NAT pools)
NSHost is not found in iPhone OS Library, it is present in Mac OS Core Library.
I am getting 2 warnings
"warning: no '+currentHost' method found" "warning: no '-address' method found"
Any way to remove these warnings ???
Check out this link.
http://zachwaugh.com/2009/03/programmatically-retrieving-ip-address-of-iphone/