I thank you all for your responses and mail. The solution that works,
i.e. the one which yields the local IP address without looking in the
hosts file or yp is as follows:
struct sockaddr_in address;
get_myaddress(&address);
return address.sin_addr;