RE: How to get the gateway's IP address of a NIC
RE: How to get the gateway's IP address of a NIC
- Subject: RE: How to get the gateway's IP address of a NIC
- From: Jerry Chang <email@hidden>
- Date: Fri, 21 Mar 2008 01:52:48 -0400
- Importance: Normal
Thanks for the information. I will give it a try. :)
Jerry
> From: email@hidden > To: email@hidden; email@hidden > Subject: Re: How to get the gateway's IP address of a NIC > Date: Wed, 19 Mar 2008 16:45:19 -0400 > > On Wed, Mar 19, 2008, Jerry <email@hidden> wrote: > > >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 > > Hi Jerry, > > the typical ways are to fetch the routing table either with sysctl or by > using a PF_ROUTE raw socket. Stevens' book "Unix Network Programming" > would be a good place to start. > > Cheers.....Peter > > p.s. remember that an interface does not have to have a gateway. Most do > but it's not required >
Windows Live Hotmail is giving away Zunes. Enter for your chance to win.
|
_______________________________________________
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