On 10/25/06, Mark Thomas wrote:
> Does any know how you would get your Gateway/Router IP address. As getting
>this previously using Open Transport was pretty easy as you would use.
The way I do it in Mac OS X is to use the System Configuration
Framework. This is basically a structured set of property lists
defining network services and configuration parameters. You need to
find the "primary" network service as previously described (on this
list), and then request the list of "routers" for that service. Notice
the primary network can change as the system is moved and you can
request to be notified when keys in the System Configuration Framework
It takes a little while to understand how it all fits together, but its
actually an elegant way of consolidating a lot of diverse information.
If you are using Cocoa, the CFDictionarys, CFArrays, and CFStrings, that
form the bulk of the System Configuration Framework are toll free
bridged to NSDictionarys, NSArrays, and NSStrings making the code
relatively straight forward. The basic pattern is to take some keys
that define where to find the information of interest (such as
"routers", "addresses", service ID, BSD name of interface, hardware
address, device type, etc...), and walk through the dictionaries to find
what you want.
In my case, I've written a Cocoa object that enumerates interface names
and identifiers, and will return information given a requested key and
interface ID. Network information is organized as a collection of
services with a defined service order that corresponds to the settings
in the Network Preferences Panel.
P.S. How to correlate various interface attributes is a problem not
fully addressed by Mac OS X. Given a BSD device name like "ppp2",
there's no programatic way to correlate that with something the user
recognizes. Is it a dialup modem, PPPoE, some VPN?, a tunnel, does it
have a user name? There's no easy way to tell, it can vary from one
system to another, or even change from one moment to the next.
I'm including some previous verbiage on this below.
What Is An IP Interface?
The concept of a network interface can be confusing to people new to
networking terminology so it may help to clarify exactly what we mean by this.
From outside the computer, a network interface may appear to be the
Ethernet jack or internal modem, but these are more accurately described
as network ports or devices. Within the computer, an IP interface is a
data structure specifying various interface attributes like its IP
address and mask and some code for handling messages associated with
that structure. Thus a single port can have more than one IP interface.
What's significant is that an interface defines a protocol, a set of
messages that we're interested in, and some code for processing them. In
practical systems, parts of the data structure that defines an IP
interface may be implemented in more than one place. Some in the IP
layer of the BSD stack, some in the Network Preferences Panel (System
Configuration Framework), and some in Extensions that provide other
services such as IP filtering, Network Address Translation, PPP (Point-
to-Point Prococol), or secure communcation using PPTP or IPSec.
Within Mac OS X, the part of the IP interface data structure defined in
the IP layer of the BSD stack is identified by a device name (such as
"en0" or "ppp0") while the part defined in the System Configuration
framework is identified by a Service ID (a so called UUID or Universal
Unique Identifier such as: "FF414B0D-87ED-11D8-B1D9-000A95EEE352").
Since these UUIDs are machine specific and rather long, IPNetRouterX
adopts a notation used by other UNIX systems of identifying additional
IP interfaces on the same physical port by appending an index as in
"en0:1" to to form a unique Interface ID. In this example "en0:1"
indicates the second IP interface on en0 with the first interface being
"en0:0" (which is abbreviated as just "en0"). Internally IPNetRouterX
uses the corresponding device name or UUID as needed for communicating
with other system components. The purpose of these "Interface IDs" is
simply to correllate the separate pieces of the IP interface data
structure wherever they appear.
The Network Preferences Panel also provides a "User Name" for each
network service, but at the time of this writing, these User Names are
not available to 3rd party applications like IPNetRouterX. IPNetRouterX
displays the Interface Name as the Port Name followed by the Device Name
in parentheses (both of which you can edit) and a unique Interface ID as
described above. By convention, "en0" (Ethernet 0) is used for Ethernet
Built-in, while "en1" is used for AirPort or the first PCI Ethernet card
if there is one. "ppp0" is used for the first PPP device which could be
associated with a modem or PPPoE. "lo0" refers to the loopback interface
used for interprocess communication.
Since Apple is free to enhance the IP interface data structure as
defined in the Network Preferences Panel (System Configuration
Framework), the Interface panel in IPNetRouterX does not try to emulate
or replace the Network Preferences Panel, but rather works along side it
to provide additional interface attributes.
If you change locations in the Network Preferences Panel, IPNetRouterX
may interpret new interfaces as ones being added to the previous
configuration and assign them new InterfaceIDs. To have IPNetRouterX
rescan the entire list of available interfaces, press the "Refresh List"
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