man -s3 getifaddrs ?

-- Pawel.

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?

Thanks.

regards,
Girish

Reply via email to