• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: I need an example of getting the iPhone's current IP address using CFHost
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I need an example of getting the iPhone's current IP address using CFHost


  • Subject: Re: I need an example of getting the iPhone's current IP address using CFHost
  • From: Alex Kac <email@hidden>
  • Date: Fri, 6 Nov 2009 22:33:32 -0600

+ (void)list
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

NSMutableDictionary* result = [NSMutableDictionary dictionary];
struct ifaddrs* addrs;
BOOL success = (getifaddrs(&addrs) == 0);
if (success)
{
const struct ifaddrs* cursor = addrs;
while (cursor != NULL)
{
NSMutableString* ip;
if (cursor->ifa_addr->sa_family == AF_INET)
{
const struct sockaddr_in* dlAddr = (const struct sockaddr_in*) cursor->ifa_addr;
const uint8_t* base = (const uint8_t*)&dlAddr->sin_addr;
ip = [[NSMutableString new] autorelease];
for (int i = 0; i < 4; i++)
{
if (i != 0)
[ip appendFormat:@"."];
[ip appendFormat:@"%d", base[i]];
}
[result setObject:(NSString*)ip forKey:[NSString stringWithFormat:@"%s", cursor->ifa_name]];
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
// NSURL *netIPURL = [NSURL URLWithString:@"http://whatismyip.org";];
// NSString *netIP = [NSString stringWithContentsOfURL:netIPURL encoding:NSUTF8StringEncoding error:nil];
// if (netIP)
// [result setObject:netIP forKey:@"www"];
// NSLog(@"IP addresses: %@", result);
[[NSNotificationCenter defaultCenter] postNotificationName:@"LocalhostAdressesResolved" object:result];

[pool release];
}



On Nov 6, 2009, at 8:19 PM, Scott Andrew wrote:

I need to get the iPhone's current IP address. I know that CFHost is the way to go, since we don't have NSHost. Does anyone have an example of how to turn the iPods name to a iPodsName.local? I can't seem to find the rules, or the sample code that is mentioned all over the web.

Scott_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

Alex Kac - President and Founder Web Information Solutions, Inc.

"It is useless for sheep to pass a resolution in favor of vegetarianism while wolves remain of a different opinion."
-- William Randolph Inge






_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >I need an example of getting the iPhone's current IP address using CFHost (From: Scott Andrew <email@hidden>)

  • Prev by Date: popup menu entries
  • Next by Date: Re: popup menu entries
  • Previous by thread: I need an example of getting the iPhone's current IP address using CFHost
  • Next by thread: popup menu entries
  • Index(es):
    • Date
    • Thread