Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding Subnet



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%20Reference%20Library/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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Finding Subnet (From: Chris Giddings <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.