Re: How to get the current IP address using CF api from C?
Re: How to get the current IP address using CF api from C?
- Subject: Re: How to get the current IP address using CF api from C?
- From: "Justin C. Walker" <email@hidden>
- Date: Mon, 20 Mar 2006 11:54:25 -0800
On Mar 20, 2006, at 11:40 , Mathias Kolehmainen wrote:
I'm porting some linux code to OSX, and I'm trying to figure out
how to get the current IP address. I'm using C with no gui, and so
I'm using the CoreFoundation API.
There is no one "current IP address".
Looks like I am supposed to use the configuration system. What I
can't figure out from the docs is how to get a handle to the
configuration system.
There are a couple of available programs whose source you can peruse:
Apple's 'scselect' and 'scutil' are available at Apple's Darwin site
(<http://developer.apple.com/darwin>; see their man pages), and
Jeffrey Frey's 'ncutil', which provides a command-line version of the
Network Preferences panel (google is your friend).
My first attempt used SCNetoworkInterfaceCopyAll. That seems to
return proper SCNetworkInterfaceRef objects, but when I try to run
SCNetworkInterfaceGetConfiguration on them it always returns a NULL
dictionary.
So, what is the proper way to get into the system configuration
database? And if somebody knows how to navigate to the current-ip-
address property, that would be useful too.
Each network interface that supports IP may have several of these, so
"the current" one is not really meaningful. You will need to think a
bit about what your goal is to make this work correctly in all
circumstances. For example, a given interface may sport one or more
"globally routable" addresses, in addition to RFC 1918 addresses and
a Bonjour (link-local) address, all present at the same time. Your
goal will dictate which of these you want to "find".
Check out 'scutil' to see what SystemConfiguration can give you.
(Am I supposed to use the IOKit? I notice the GetMACAddressSample
sample code uses the IOKit...)
No! The MAC address is not what you want.
In addition to SystemConfiguration, you may want to consider using
'getifaddrs()' (cf. the man page).
Regards,
Justin
--
Justin C. Walker, Curmudgeon-At-Large
Institute for the Absorption of Federal Funds
--------
Men are from Earth.
Women are from Earth.
Deal with it.
--------
_______________________________________________
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