[oclug] [OT] C: get local ip?
David F. Skoll
dfs at roaringpenguin.com
Tue Mar 19 15:48:15 EST 2002
On Tue, 19 Mar 2002, Matt Rose wrote:
> I don't think that'll do what you think it'll do.
There is no easy way to do what you want in C. Basically, you
have to go through the routing table to find out which interface
is used for the default route, and then use ioctl's to get its IP
address. There are some complications:
- There may be no default route. There may be two or more default routes.
- If you are using policy routing, there may be more than one routing table.
- If the default route goes via a PPP interface, it may not even have an
IP address (there are "unnumbered links").
So it's a mess.
--
David.
More information about the OCLUG
mailing list