Re: Correct way to determine machine LAN ip
Re: Correct way to determine machine LAN ip
- Subject: Re: Correct way to determine machine LAN ip
- From: Justin Walker <email@hidden>
- Date: Sat, 29 Mar 2003 13:48:58 -0800
On Saturday, Mar 29, 2003, at 10:07 US/Pacific, Arthur VIGAN wrote:
I am designing a very simple application on Mac OS X, and I would like
to determine the machine LAN ip...
I'm not sure what you mean by "the machine LAN ip". I'll guess that
you mean IP address. Today's networked systems can have multiple IP
addresses assigned, so "the" IP address is a fuzzy concept at best. A
powerbook, for example, could have a minimum of 4 addresses active: one
for the built-in ethernet; one for AirPort; one for one of the previous
two interfaces, specifically for ZeroConf activity; and one for the
loopback interface.
So I'd say you are doomed from the start if you want "the" IP address.
There is some hope, though; but you have to be prepared for some gnarly
concepts and a bit of work. Darwin (and Mac OS X) use the
SystemConfiguration framework/API to handle (currently, mostly
networking) configuration. It keeps a persistent database,
/var/db/SystemConfiguration/preferences.xml which stores all the known
configuration information it tracks.
This database is used to get things going when the system starts up;
after boot, the information about system configuration is kept in a
live, ephemeral, in-core database by configd and its plugins.
If you go to the network preferences panel and look at the "network
port configurations" (select in the "Show:" pop-up), you note one or
more ports specified in a checkable list. This list can be ordered
(click/drag) to select a "primary" interface. This interface is the
one that is used for "default routes", DNS info, and so on. If the
current "primary" goes away (someone trips over your ethernet cord; or,
more to the point, your ISP hangs up the phone on your PPP link), the
next in the list becomes the new "primary".
It is from the "primary" interface that you will get an IP address that
is the closest thing you will find to "the" IP address. Select the
first one listed for the primary.
To see examples of the use of this framework in action, you can go to
the Darwin (or opendarwin) websites and check out the configd and
configd-plugin projects; and from the scutil and scselect commands. In
addition, there is a utility called 'ncutil' by Jeffrey Frey
(
http://deaddog.duch.udel.edu/~frey/darwin) that does much of what the
network prefs panel does, but from the command line.
In addition, there is some documentation in the
/Developer/Documentation tree (search for SysConfig and
SystemConfiguration).
Hope that helps.
Regards,
Justin
--
Justin C. Walker, Curmudgeon-At-Large *
Institute for General Semantics | It's not whether you win or
lose...
| It's whether *I* win or lose.
*--------------------------------------*-------------------------------*
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.