Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[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



+ (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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

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>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.