How to get the gateway's IP address of a NIC
How to get the gateway's IP address of a NIC
- Subject: How to get the gateway's IP address of a NIC
- From: "Jerry" <email@hidden>
- Date: Wed, 19 Mar 2008 11:02:39 -0700
Hi
there,
I was using the
system configuration to retrieve the gateway's IP address, and it works fine
until I use manually assigned static IP address.
The key in
system configuration is "State:/Network/Service/(a service ID for en0, en1,
..)/IPv4/Router". So I got the gateway IP from using "kSCPropNetIPv4Addresses"
key programmatically.
When using the
static IP(no DHCP), I found out that the Router field is disappeared.
However, the "NetworkSignature" key contains a string that has the router's IP
address. This key's value is in this format:
"IPv4.Router=xxx.xxx.xxx.xxx;RouterHardwareAddress=xx:xx:xx:xx:xx"
I could get the
gateway IP from parsing the string but I do not think this is a good solution
because they key name may change or the format of the value may change as
well in the future.
Is there another way
or better way to retrieve the gateway's IP address? Such as an network API
or BSD function.
Thanks,
Jerry
_______________________________________________
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