Re: Is there a clean way to get my default IP address.
Re: Is there a clean way to get my default IP address.
- Subject: Re: Is there a clean way to get my default IP address.
- From: Frederick Cheung <email@hidden>
- Date: Tue, 6 Dec 2005 22:20:28 +0000
On 6 Dec 2005, at 22:10, John Draper wrote:
Justin C. Walker wrote:
From the Mac OS X perspective, you have a default interface, not
a default IP address. That interface is the one that carries
(i.e., provides, either by manual entry or something like DHCP)
the default route, the DNS servers, etc.
Is that like the "en0" and "en1" you see in the "ifconfig" output?
Is that what you mean by "Interface".
Yup, that's an interface
Since a system like a Mac can have several active interfaces,
these are ordered (by the user, e.g., using the network control
panel) to provide priority: the highest priority interface at any
given time is that one that is both active and highest in the
priority order.
Yes - It would be nice for me to figure out how to find them under
program control. But I'm going to
have to spend at least 3 months to learn them. I don't even know
where to start. The URL references
you gave me, is something I'm going to have to read over and over
to comprehend it.
To each interface there can be assigned multiple IP addresses.
Multiple ones? WOW!!! yet MORE confusion... Gackkkk!
These can come and go, and there is no good way to choose a
default among them. That's why I say there is no default address
on Mac OS X (and therefore, no way to talk about, or retrieve,
"my" or "the" IP address).
Hmmm - So how does "ifconfig" get this information? If I do an
"ifconfig -a" I get a list of
all the devices, and some are "active" and others are not. What
code or API gets this information?
Is it calls to "gethostbyname" and looking at the hostent it
returns? Or is there some other
lower level device level means it uses to get me the "inet" value
of a device (en0, or en1).
getifaddrs will get you most of that info I believe.
SystemConfiguration can also give you this info, there's a command
line tool scutil that will show you how SystemConfiguration
structures this kind of thing.
I know from experience, I can have BOTH a wired connection and a
WIFI connection if I turn
on my airport. Then, as I do the "ifconfig" I see both active,
but they have different IP
addresses. But only the "active" ones do. I presume only ONE is
designated as the one to
use for outgoing connections? My what criteria is that one
selected? From the Network
Control panel? You say I can access this info under program
control? Where can I find
some example code to do this.... does it exist? I looked at the
URL's you gave me earlier,
but in looking at the code, and the function API names that were
used, I could not make
an association to one that would return my IP address (the high
priority one).
That's the job of the routing table, which in a nutshell tells you
what to do when you want to send some data to a given host. The man
pages for route and routed have more info. netstat -r will display
the routing table for you.
So what API's are appropriate to use if I want to access internal
data used by the "ifconfig".
or better yet, use the data they display in the Mac's Network
control panal?
The reason you aren't seeing any clear way to get the default IP
address is that the concept is not present in anything that Mac OS
X provides.
Yes - I see that...
I gather you are trying to port an app, is that correct?
Yes - from the WinBlows to the Mac... and when one has an airport
connected as well as an
ethernet connection, I'm afraid my code will break.
It could be that the problem you are having is that the view
taken by Mac OS X doesn't match that of the system where this
code originally ran.
The "view" is standard UNIX socket code. Isn't the Carbon SFSocket
calls built on top of the
UNIX socket code?
CFSocket is a thin layer on top of BSD sockets, it's purpose is to
integrate sockets into a CFRunLoop.
Fred
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden