• 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: [iPhone] get iPhone's IP address...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [iPhone] get iPhone's IP address...


  • Subject: Re: [iPhone] get iPhone's IP address...
  • From: Jim Puls <email@hidden>
  • Date: Sun, 19 Jul 2009 23:58:40 -0700

On Jul 19, 2009, at 10:50 PM, James Lin wrote:

- (NSString*) getNetAddr {
char iphone_ip[255];
strcpy(iphone_ip,"127.0.0.1"); // if everything fails
NSHost *myhost =[NSHost currentHost];
//NSHost *myhost = [[NSHost alloc] init];
if (myhost)
{
NSLog(@"myhost exits");
NSString *ad = [myhost address];
if (ad)
strcpy(iphone_ip, [ad cStringUsingEncoding: NSISOLatin1StringEncoding]);
}

return [NSString stringWithFormat:@"%s", iphone_ip];
}

And just to pile on, there's no reason why you should be converting an NSString to a char* and back. That's just a waste of effort.


-> jp
_______________________________________________

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: 
 >[iPhone] get iPhone's IP address... (From: James Lin <email@hidden>)

  • Prev by Date: Re: [iPhone] get iPhone's IP address...
  • Next by Date: [iPhone] UITableView cell display bugs ?
  • Previous by thread: Re: [iPhone] get iPhone's IP address...
  • Next by thread: Re: [iPhone] get iPhone's IP address...
  • Index(es):
    • Date
    • Thread