On 10/24/06, Girish Venkatachalam <[EMAIL PROTECTED]> wrote:
How to programmatically determine the IP address of an interface?

Your question is unclear.  Do you _really_ want to look up the list of
IP addresses bound to a given interface, specified by name and/or
index?  That what your question asks for, but that information is
usually only needed for some UDP servers and routing programs.  Or do
you just want to know the local IP of a connected socket?  Note that
the IP choosen may depend on the IP that you're sending/connecting to.


getsockname(2) is supposed to work but it doesn't since it returns 0.0.0.0 for
INADDR_ANY.

Was that before or after you used connect(), sendto(), sendmsg(), or accept()?


Till now I have got away with a system("/sbin/ifconfig -a | grep.... hack.

If you *really* want to see how the interfaces are configured (I doubt
it), you should take a look at getifaddrs()

Btw, I strongly suggest you pick up a copy of "UNIX Network
Programming, volume 1" by Stevens.  You should ignore the XTI stuff in
the back, but the rest is Good Stuff.


Philip Guenther

Reply via email to