Re: Getting the private IP
Re: Getting the private IP
- Subject: Re: Getting the private IP
- From: Alastair Houghton <email@hidden>
- Date: Sat, 9 May 2009 00:32:36 +0100
On 8 May 2009, at 15:46, Mr. Gecko wrote:
Hello, I'm trying to find out how to get the private IP address.
This is my quick way of finding out.
- (NSString *)localIP {
NSString *IPAddress = @"";
struct ifaddrs *myaddrs, *ifa;
struct sockaddr_in *s4;
int status;
char buf[64];
status = getifaddrs(&myaddrs);
[snip]
is there a better way?
Depends what you are trying to achieve. It might be better if you
could explain what you are doing that needs this information, since
there are some alternatives that might be better in some cases.
Additionally, you need to be careful because:
- There may be more than one active interface with an IP address
- There may be more than one IP address for each active interface
- Your idea of the right interface to use might not match the user's
idea (or the system's idea)
Unless you're doing some very low-level networking code, you can
usually live without knowing "the" IP address of the system (to the
extent that such a thing actually exists).
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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