On Tue, Oct 24, 2006 at 10:43:57AM +0200, Otto Moerbeek wrote:
>
> On Tue, 24 Oct 2006, Girish Venkatachalam wrote:
>
> > Dear friends,
> >
> > I know this question sounds basic but it is not.
> >
> > How to programmatically determine the IP address of an interface?
> >
> > (Programmatically means using C of course :-)
> >
> > getsockname(2) is supposed to work but it doesn't since it returns 0.0.0.0
> > for INADDR_ANY. getpeername(2) works, so am I supposed to send a packet, do
> > a getpeername(2) at the other side and get back the result in the payload?
> >
> > Till now I have got away with a system("/sbin/ifconfig -a | grep.... hack.
> >
> > Am I missing something? I surely am since the very notion of IP address of
> > an interface is silly since it could be bridged,carped, trunked etc.
> >
> > But say, I have obtained 192.168.1.2 thro' DHCP and this is what I want to
> > figure out. That is the only IP that interface has. How to achieve that?
>
> You are looking for getifaddrs(3)
Thanks, but it just slipped my mind. I knew this but couldn't figure out what
on earth the man page was trying to say.
Is there a way to portably make this work across linux,FreeBSD,NetBSD and
OpenBSD?
Thanks to everyone who responded.
This mailing list rocks! :-)
As usual. :-)
regards,
Girish
--
Having nothing nothing can he lose