Correct way to determine machine's IP address in Cocoa
Correct way to determine machine's IP address in Cocoa
- Subject: Correct way to determine machine's IP address in Cocoa
- From: Jamie Curmi <email@hidden>
- Date: Sun, 21 Apr 2002 15:38:46 +1000
Hi All,
Does anyone know what the best/correct way to determine the IP address
of a given machine is?
I've tried a number of things with different amounts of success:
1) NSHost
Doing something like:
[[NSHost currentHost] address]
Seems to work sometimes, but sometimes it just returns 127.0.0.1
2) Using the BSD command:
/sbin/ifconfig -a
And calling out to it from C code, for example:
/sbin/ifconfig -a | grep broadcast | awk '/inet/{ print $2 }'
Also doesn't always work, and if the user didn't install the BSD
subsystem when they installed OSX it definitely doesn't work.
3) An Apple employee hinted at something to do with the
SystemConfiguration framework and using the DynamicStore API's. I've
tried to find out about this framework, but I can find much
documentation, and what little I did find was not really helpful for
doing what I want to do.
So I'm wondering, does anyone out there have some idea how to do this?
Any help would be appreciated.
Thanks.
Jamie
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.