Re: Finding Subnet
Re: Finding Subnet
- Subject: Re: Finding Subnet
- From: John Labovitz <email@hidden>
- Date: Mon, 31 Jan 2005 22:40:33 -0800
On Jan 31, 2005, at 9:52 PM, Chris Giddings wrote:
Does anyone here have suggestions or sample code on how to get the sub
net of the current system and output and output it to say a text
field?
It's a little more complicated than "the subnet of the current system."
A system can have more than one interface configured (eg, Ethernet and
Airport), and each interface can potentially be configured with more
than one address and related subnet. You could, however, want the
subnet of the *primary* interface.
I am not very familiar with the IOKit which seems to be the main focus
for this kind of information.
I dunno whether you can get it from IOKit. Perhaps you could. I think
Apple's preferred method is to use the System Configuration framework.
Here's the link to it on my local system; it should work for you if
you've installed the developer tools & docs:
file:///Developer/ADC Reference Library/documentation/Networking/
Reference/SysConfig/sysconfig_fw.html
There's a command-line tool called "scutil" (located at
/usr/sbin/scutil) that will browse the System Configuration database.
It's not as easy as it sounds; you have to understand the SC schema for
it to be useful.
For an easier way, see Malte Tancred's SysconfViewer at:
http://www.oops.se/~malte/software.html
Personally, I've used the BSD calls to get information about
interfaces. Look at getifaddrs() in particular ("man getifaddrs" at
your shell prompt). Using that function, you can interate through all
the network interfaces, and each address on each interface, and find
any defined subnets. You'll have to deal with sockaddr structures,
which are C structures, not Objective-C objects.
Or you could do it the Unix way, and pipe the output of "ifconfig"
through a Perl script, and find the subnets that way. ;)
Good luck!
--
John Labovitz
Macintosh support, research, and software development
John Labovitz Consulting, LLC
email@hidden | +1 503.949.3492 |
www.johnlabovitz.com/consulting
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden